-
Notifications
You must be signed in to change notification settings - Fork 2
feat: reissue 로직 변경 및 server duration time 측정 #249 #250
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,17 +98,17 @@ public TokenDto login(final SocialType socialType, final String authorizationCod | |
| public TokenDto reissue(final String refreshToken) { | ||
| try { | ||
| final long userId = jwtProvider.extractUserIdFromToken(refreshToken); | ||
| checkIsSameRefreshToken(userId, refreshToken); | ||
| final UserRole userRole = UserRole.valueOf(jwtProvider.extractUserRoleFromToken(refreshToken)); | ||
| checkIsSameRefreshToken(userId, refreshToken); | ||
|
|
||
| final User user = userRetriever.findUserById(userId); | ||
| final Token newToken = getLoginOrReissueJwtToken(user.getUserId(), user.getUserRole()); | ||
| final Token newToken = getLoginOrReissueJwtToken(userId, userRole); | ||
|
|
||
| saveRefreshTokenInRedis(user.getUserId(), newToken.getRefreshToken()); | ||
| saveRefreshTokenInRedis(userId, newToken.getRefreshToken()); | ||
|
Comment on lines
100
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 재발급 시 role을 토큰 claim만 신뢰하면 권한/계정 상태 변경 반영이 늦어질 수 있습니다. Line 101~Line 104에서 사용자 현재 상태를 서버 측 소스로 재확인하지 않고 RT의 role claim으로 바로 재발급합니다. 이 경로는 역할 강등/계정 비활성화(또는 삭제) 이후에도 기존 RT가 유효한 동안 이전 권한으로 AT 재발급이 가능해질 수 있습니다. 재발급 시점에 사용자 상태(존재/활성/권한)를 다시 검증하는 경로를 유지하는 것이 안전합니다. 🤖 Prompt for AI Agents |
||
|
|
||
| return TokenDto.of(newToken.getAccessToken(), newToken.getRefreshToken()); | ||
| } catch (AuthWrongJwtException | AuthRTNotFoundException e) { | ||
| } catch (AuthWrongJwtException e) { | ||
| throw new AuthUnAuthorizedException(ErrorCode.UNAUTHORIZED_WRONG_RT); | ||
| } catch (AuthExpiredJwtException e) { | ||
| } catch (AuthExpiredJwtException |AuthRTNotFoundException e) { | ||
| throw new AuthUnAuthorizedException(ErrorCode.UNAUTHORIZED_RT_EXPIRED); | ||
| } catch (AuthRTException e) { | ||
| throw new AuthUnAuthorizedException(ErrorCode.INTERNAL_RT_REDIS_ERROR); | ||
|
|
@@ -125,7 +125,6 @@ public void logout(final long userId, final String refreshTokenFromCookie) { | |
| } catch (DataAccessException e) { | ||
| throw new AuthRedisException(ErrorCode.INTERNAL_RT_REDIS_ERROR); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private void checkIsSameRefreshToken(final long userId, final String refreshToken) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,11 @@ public long extractUserIdFromToken(final String token) { | |
|
|
||
| public String extractUserRoleFromToken(final String token) { | ||
| final Jws<Claims> claims = parseToken(token); | ||
| return claims.getBody().get(Constants.USER_ROLE, String.class); | ||
| final String role = claims.getBody().get(Constants.USER_ROLE, String.class); | ||
| if(role == null) { | ||
| throw new AuthWrongJwtException(); | ||
| } | ||
| return role; | ||
|
Comment on lines
+51
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
현재는 제안 수정안- public String extractUserRoleFromToken(final String token) {
+ public UserRole extractUserRoleFromToken(final String token) {
final Jws<Claims> claims = parseToken(token);
final String role = claims.getBody().get(Constants.USER_ROLE, String.class);
- if(role == null) {
+ if (role == null) {
throw new AuthWrongJwtException();
}
- return role;
+ try {
+ return UserRole.valueOf(role);
+ } catch (IllegalArgumentException e) {
+ throw new AuthWrongJwtException();
+ }
}🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| //토큰 파싱 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: PERMIT-SEOUL/permit-server
Length of output: 1403
🏁 Script executed:
Repository: PERMIT-SEOUL/permit-server
Length of output: 1753
🏁 Script executed:
Repository: PERMIT-SEOUL/permit-server
Length of output: 2511
🏁 Script executed:
Repository: PERMIT-SEOUL/permit-server
Length of output: 11749
🏁 Script executed:
Repository: PERMIT-SEOUL/permit-server
Length of output: 569
UserRole.valueOf(...)호출 시 발생 가능한 예외가 인증 오류로 매핑되지 않습니다.Line 101에서
extractUserRoleFromToken()이 반환하는 문자열이 null이거나 enum과 일치하지 않으면IllegalArgumentException또는NullPointerException이 발생합니다. 현재 catch 블록에서 이를 명시적으로 처리하지 않아 예외가 그대로 전파됩니다. 다음과 같이 처리해주세요:🔧 제안 수정안
🤖 Prompt for AI Agents