-
Notifications
You must be signed in to change notification settings - Fork 1
[refactor/#650] JWT 토큰 무효화 체계 및 RT 재사용 탐지 도입 #651
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef8fe76
feat: tokenVersion 인프라 구축
kanghana1 2811ed8
refactor: 인증 필터 tokenVersion 검증 전환 및 DB 조회 제거
kanghana1 82834b7
feat: 재사용 탐지 로직 추가
kanghana1 f753e33
chore: 충돌해결
kanghana1 5e0679e
fix: JWT claim에 type 추가
kanghana1 d6ffa96
fix: redis를 캐시로 사용하도록 수정
kanghana1 a1d2851
fix: AT 무효화 검증 제거
kanghana1 f703a1b
refactor: lua 스크립트를 이용해 동시성 이슈 방지
kanghana1 7535106
test: 테스트 보강
kanghana1 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
46 changes: 46 additions & 0 deletions
46
src/main/java/umc/cockple/demo/global/auth/TokenVersionRepository.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,46 @@ | ||
| package umc.cockple.demo.global.auth; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.StringRedisTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import umc.cockple.demo.domain.member.repository.MemberRepository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class TokenVersionRepository { | ||
|
|
||
| private static final String KEY_PREFIX = "member:tokenVersion:"; | ||
|
|
||
| private final StringRedisTemplate stringRedisTemplate; | ||
| private final MemberRepository memberRepository; | ||
|
|
||
| /** | ||
| * 현재 토큰 버전을 반환한다. | ||
| * 캐시 hit 시 Redis, miss 시 DB에서 읽어 재적재 | ||
| */ | ||
| public long getVersion(Long memberId) { | ||
| String cached = stringRedisTemplate.opsForValue().get(KEY_PREFIX + memberId); | ||
| if (cached != null) { | ||
| return Long.parseLong(cached); | ||
| } | ||
| long version = memberRepository.findTokenVersionById(memberId).orElse(0L); | ||
| cache(memberId, version); | ||
| return version; | ||
| } | ||
|
|
||
| /** | ||
| * 토큰 버전을 1 증가시키고 새 값을 반환 | ||
| */ | ||
| @Transactional | ||
| public long increment(Long memberId) { | ||
| memberRepository.incrementTokenVersion(memberId); | ||
| long newVersion = memberRepository.findTokenVersionById(memberId).orElse(0L); | ||
| cache(memberId, newVersion); | ||
| return newVersion; | ||
| } | ||
|
|
||
| private void cache(Long memberId, long version) { | ||
| stringRedisTemplate.opsForValue().set(KEY_PREFIX + memberId, String.valueOf(version)); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.