-
Notifications
You must be signed in to change notification settings - Fork 1
hotfix: 7일 이내 복구 정책을 위해 회원탈퇴 시 Apple 토큰 revoke 코드 제거 #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+158
−10
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21474c7
fix: 7일 복구 정책 위해 Apple 토큰 즉시 revoke 제거
dh2906 74d1d85
chore: 7일 경과 Apple 탈퇴 유저 조회 쿼리 추가
dh2906 d0b290a
feat: 탈퇴 7일 후 Apple 토큰 revoke 스케줄러 추가
dh2906 55f7d18
chore: 코드 포맷팅
dh2906 22dd8fe
fix: revoke된 토큰 null 처리
dh2906 8ae7d2c
refactor: Apple revoke 배치 트랜잭션 경계 분리
dh2906 355342c
fix: 스케줄러 작동 시간을 서버 시간대에 의존
dh2906 ffe4d1c
refactor: 변경감지 활용
dh2906 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/gg/agit/konect/domain/user/scheduler/UserScheduler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package gg.agit.konect.domain.user.scheduler; | ||
|
|
||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import gg.agit.konect.domain.user.service.UserSchedulerService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class UserScheduler { | ||
|
|
||
| private final UserSchedulerService userSchedulerService; | ||
|
|
||
| /** | ||
| * 매일 자정(서버 기본 시간대 기준 00:00)에 실행되어 7일 경과한 Apple 사용자 토큰을 revoke합니다. | ||
| * cron 표현식: 초 분 시 일 월 요일 | ||
| * 0 0 0 * * *: 매일 00:00:00 실행 | ||
| */ | ||
| @Scheduled(cron = "0 0 0 * * *") | ||
| public void revokeAppleTokensAfterRestoreWindow() { | ||
| try { | ||
| log.info("Starting Apple token revocation task for users withdrawn more than 7 days ago"); | ||
dh2906 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| userSchedulerService.revokeAppleTokensAfterRestoreWindow(); | ||
| log.info("Successfully completed Apple token revocation task"); | ||
| } catch (Exception e) { | ||
| log.error("Failed to revoke Apple tokens for withdrawn users", e); | ||
| } | ||
dh2906 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
src/main/java/gg/agit/konect/domain/user/service/UserSchedulerService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package gg.agit.konect.domain.user.service; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import gg.agit.konect.domain.user.model.User; | ||
| import gg.agit.konect.infrastructure.oauth.AppleTokenRevocationService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserSchedulerService { | ||
|
|
||
| private static final int REVOKE_AFTER_DAYS = 7; | ||
|
|
||
| private final UserSchedulerTxService userSchedulerTxService; | ||
| private final AppleTokenRevocationService appleTokenRevocationService; | ||
|
|
||
| /** | ||
| * 7일 이상 경과한 Apple 사용자의 토큰을 revoke합니다. | ||
| * - 7일 복구 정책: 탈퇴 후 7일 이내 복구 가능하므로 즉시 revoke하지 않음 | ||
| * - 7일 경과 후: 복구 불가 시점이므로 Apple 토큰 영구 폐기 | ||
| */ | ||
| public void revokeAppleTokensAfterRestoreWindow() { | ||
| LocalDateTime threshold = LocalDateTime.now().minusDays(REVOKE_AFTER_DAYS); | ||
| List<User> usersToRevoke = userSchedulerTxService.findUsersToRevoke(threshold); | ||
dh2906 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (usersToRevoke.isEmpty()) { | ||
| log.info("No Apple users to revoke (threshold={})", threshold); | ||
| return; | ||
| } | ||
|
|
||
| int successCount = 0; | ||
| int failureCount = 0; | ||
|
|
||
| for (User user : usersToRevoke) { | ||
| try { | ||
| String refreshToken = user.getAppleRefreshToken(); | ||
| if (refreshToken == null) { | ||
| continue; | ||
| } | ||
|
|
||
| appleTokenRevocationService.revoke(refreshToken); | ||
| userSchedulerTxService.clearAppleRefreshTokenIfMatches(user.getId(), refreshToken); | ||
| successCount++; | ||
| } catch (Exception e) { | ||
| failureCount++; | ||
| log.error("Failed to revoke Apple token for userId={}", user.getId(), e); | ||
| } | ||
| } | ||
dh2906 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| log.info( | ||
| "Apple token revoke task finished: total={}, success={}, failure={}" | ||
| , usersToRevoke.size(), successCount, failureCount | ||
| ); | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
src/main/java/gg/agit/konect/domain/user/service/UserSchedulerTxService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package gg.agit.konect.domain.user.service; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import gg.agit.konect.domain.user.enums.Provider; | ||
| import gg.agit.konect.domain.user.model.User; | ||
| import gg.agit.konect.domain.user.repository.UserRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserSchedulerTxService { | ||
|
|
||
| private final UserRepository userRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<User> findUsersToRevoke(LocalDateTime threshold) { | ||
| return userRepository.findByProviderAndDeletedAtBefore(Provider.APPLE, threshold); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void clearAppleRefreshTokenIfMatches(Integer userId, String expectedRefreshToken) { | ||
| userRepository.findByIdIncludingDeleted(userId) | ||
| .filter(user -> expectedRefreshToken.equals(user.getAppleRefreshToken())) | ||
| .ifPresent(User::clearAppleRefreshToken); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.