Open
Conversation
spring-kang
reviewed
Oct 29, 2025
| @Value("${jwt.refresh-token-expiration-minutes}") | ||
| private int refreshTokenExpirationMinutes; | ||
|
|
||
| public String generateAccessToken(Map<String, Object> claims, String subject) { |
Collaborator
There was a problem hiding this comment.
이런식으로 claim 정보나 subject 정보 자체를 넘기느 방식은 조금 위험할수있습니다.
spring-kang
reviewed
Oct 29, 2025
|
|
||
| @Override | ||
| public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, | ||
| Authentication authentication) throws IOException, ServletException { |
Collaborator
There was a problem hiding this comment.
내부에서 401 에러나 500에러도 핸들링 되도록 구현해보시면 좋을것 같아요!
spring-kang
reviewed
Oct 29, 2025
| filterChain.doFilter(request, response); | ||
| } | ||
|
|
||
| private Map<String, Object> verifyJws(HttpServletRequest request) { |
Collaborator
There was a problem hiding this comment.
이렇게 검증하는 로직이 JwtTokenProvider 에서 구현되면 좀더 책임분리가 잘된 코드가 됩니다.
spring-kang
reviewed
Oct 29, 2025
| import org.springframework.util.StringUtils; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
|
|
||
| public class JwtAuthenticationFilter extends OncePerRequestFilter { |
Collaborator
There was a problem hiding this comment.
필터를 주입하는 부분이 보이지 않는것 같아요! 확인해주세요.
spring-kang
approved these changes
Oct 29, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
요구사항
기본
JWT 컴포넌트 구현
리팩토링 - 로그인
미션 9와 마찬가지로 Spring Security의 formLogin + 미션 9의 인증 흐름은 그대로 유지하면서 필요한 부분만 대체합니다.
AuthenticationSuccessHandler 컴포넌트를 대체하세요.
기존 구현체는 LoginSuccessHandler입니다.
JwtLoginSuccessHandler를 정의하고 대체하세요.
JWT 인증 필터 구현
요청 당 한번만 실행되도록 OncePerRequestFilter를 상속하세요.
요청 헤더(Authorization)에 Bearer 토큰이 포함된 경우에만 인증을 시도하세요.
JwtProvider를 통해 엑세스 토큰의 유효성을 검사하세요.
유효한 토큰인 경우 UsernamePasswordAuthenticationToken 객체를 활용해 인증 완료 처리하세요.
리프레시 토큰을 활용한 엑세스 토큰 재발급
리프레시 토큰을 활용해 엑세스 토큰을 재발급하는 API를 구현하세요.
API 스펙
permitAll 설정에 포함하세요.
토큰 재발급 API로 대체할 수 있는 컴포넌트를 모두 삭제하세요.
Me API (GET /auth/me)
RememberMe
리팩토링 - 로그아웃
심화
리팩토링 - 토큰 상태 관리
토큰 기반 인증 방식은 세션 기반 인증 방식과 달리 무상태(stateless)이기 때문에 사용자의 로그인 상태를 제어하기 어렵습니다.
따라서 SessionRegistry를 통해 세션의 상태를 관리했던 것처럼, JWT의 상태를 관리할 수 있는 컴포넌트를 추가해야합니다.
메모리에 JwtInformation을 저장하는 JwtRegistry 구현체입니다.
동시성 처리를 위해 다음과 같이 구성하세요. 동시성에 대해서는 다음 미션에서 학습합니다.
JwtRegistry를 활용해 동시 로그인 제한 기능을 리팩토링하세요.
동일한 계정으로 로그인 시 기존 로그인 세션을 무효화합니다.
주기적으로 만료된 토큰 정보를 레지스트리에서 삭제하세요.
@EnableScheduling를 추가하세요.
주요 변경사항
스크린샷
멘토에게