Refactor: JWT 키 생성 및 검증 로직을 이전 방식으로 롤백#288
Merged
jsoonworld merged 3 commits intodevelopfrom Jul 15, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR rolls back the JWT key generation and verification logic to the previous single-key approach with Base64-encoded secrets for full backward compatibility. Main changes:
- Restore Base64 encoding of
secretKeyinValueConfig - Simplify
JwtProviderto use a singlesecretKeyand centralize exception handling - Clean up and unify JWT error codes, and update exception usage in
UserandAuthService
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ValueConfig.java | Added @PostConstruct to Base64-encode the loaded secretKey |
| JwtProvider.java | Removed dual-key logic, centralized parseClaims exception mapping |
| JwtErrorCode.java | Removed unused codes, renamed and standardized error messages |
| User.java | Switched thrown error from INVALID_JWT_TOKEN to INVALID_TOKEN |
| AuthService.java | Updated orElseThrow to use INVALID_TOKEN for missing user |
Comments suppressed due to low confidence (4)
src/main/java/org/terning/terningserver/common/config/ValueConfig.java:32
- Consider adding integration tests to verify that tokens generated before and after this Base64 encoding change remain valid, ensuring backward compatibility.
secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes(StandardCharsets.UTF_8));
src/main/java/org/terning/terningserver/auth/jwt/exception/JwtErrorCode.java:24
- [nitpick] You've removed the '[JWT ERROR]' prefix and changed field 'rawMessage' to 'message'. Ensure downstream code that logs or returns error messages still includes necessary context or reintroduce a standard prefix if required for consistency.
private final String message;
src/main/java/org/terning/terningserver/auth/application/AuthService.java:114
- [nitpick] Throwing INVALID_TOKEN for a missing user record may obscure the real issue; consider a distinct error code like USER_NOT_FOUND or INVALID_USER_ID for clarity.
.orElseThrow(() -> new JwtException(JwtErrorCode.INVALID_TOKEN));
src/main/java/org/terning/terningserver/auth/jwt/JwtProvider.java:92
- The ExpiredJwtException type is referenced but not imported; add an import for io.jsonwebtoken.ExpiredJwtException (and similarly for MalformedJwtException and UnsupportedJwtException) to avoid compile errors.
if (e instanceof ExpiredJwtException) {
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.
📄 Work Description
표준적인 JWT 키 생성 방식 도입을 시도했으나, 이로 인해 기존 사용자들의 토큰이 만료되지 않았음에도 재로그인을 해야 하는 불편함이 발생할 수 있음을 확인했습니다.
사용자 경험을 최우선으로 고려하여, 더 나은 방식(듀얼 키 등)의 도입은 추후 과제로 남겨두고, 우선 안정성이 검증된 과거의 단일 키 방식으로 롤백하는 것을 결정했습니다.
특히, 과거 시스템이
secret-key를 Base64 인코딩하여 사용했던 고유한 로직을 그대로 복원하여 완전한 하위 호환성을 보장하는 데 중점을 두었습니다.1. feat: JWT 시크릿 키 Base64 인코딩 방식 복원
ValueConfig.java:@PostConstruct를 사용하여application.yml에서 읽어온secret-key를 Base64로 인코딩하는 과거 로직을 복원했습니다. 이를 통해 모든 토큰이 일관된 방식으로 서명될 수 있는 기반을 마련했습니다.2. refactor: JwtProvider를 단일 키 처리 방식으로 단순화
JwtProvider.java: New/Old 듀얼 키 관리 로직을 모두 제거하고,ValueConfig에서 처리된 최종 키를 받아 사용하는 단일secretKey필드만 남겼습니다. 토큰 생성(generateToken) 및 검증(parseClaims) 로직이 모두 이 단일 키를 사용하도록 수정하여 코드를 단순화하고 오류 발생 가능성을 줄였습니다.3. refactor: JWT 관련 에러 코드 및 예외 처리 통일
JwtErrorCode.java: 듀얼 키 마이그레이션 시도 과정에서 추가되었으나 현재 사용되지 않는 에러 코드들을 제거하고, 메시지를 명확하게 정리했습니다.AuthService.java,User.java: 정리된JwtErrorCode에 맞춰 예외 처리 부분을INVALID_TOKEN으로 통일하여 일관성을 확보했습니다.💬 To Reviewers
ValueConfig에서 인코딩)과 현재JwtProvider의 초기화 로직이 어떻게 연계되는지 중점적으로 봐주시면 감사하겠습니다.⚙️ ISSUE