11package com .thinkeep .global .jwt ;
22
3- import com .thinkeep .domain .user .dto .CreateRequest ;
43import com .thinkeep .domain .user .entity .User ;
54import io .jsonwebtoken .*;
65import io .jsonwebtoken .security .Keys ;
7- import lombok .extern .java .Log ;
86import lombok .extern .slf4j .Slf4j ;
97import org .springframework .beans .factory .annotation .Value ;
108import org .springframework .stereotype .Component ;
@@ -28,6 +26,12 @@ public class JwtUtil {
2826 * JWT 토큰 생성
2927 */
3028 public String generateToken (User user ) {
29+ // 🔍 디버깅 로그 추가
30+ log .info ("🔍 JWT 토큰 생성 시작" );
31+ log .info ("🔍 설정된 secretKey: '{}'" , secretKey );
32+ log .info ("🔍 secretKey 길이: {}" , secretKey != null ? secretKey .length () : "null" );
33+ log .info ("🔍 secretKey 바이트 길이: {}" , secretKey != null ? secretKey .getBytes ().length : "null" );
34+
3135 Map <String , Object > claims = new HashMap <>();
3236 claims .put ("userNo" , user .getUserNo ());
3337 claims .put ("nickname" , user .getNickname ());
@@ -52,6 +56,32 @@ private String createToken(Map<String, Object> claims, String subject) {
5256 .compact ();
5357 }
5458
59+ /**
60+ * 서명용 키 생성 (내부 메서드) - 🚨 긴급 안전장치 추가
61+ */
62+ private SecretKey getSigningKey () {
63+ log .info ("🔍 getSigningKey() 호출됨" );
64+ log .info ("🔍 현재 secretKey 값: '{}'" , secretKey );
65+
66+ // 🚨 긴급 안전장치: secretKey가 비어있거나 null이면 강제로 안전한 키 사용
67+ String actualKey = secretKey ;
68+
69+ if (actualKey == null || actualKey .trim ().isEmpty ()) {
70+ log .error ("❌ JWT secretKey가 비어있습니다! 임시 키 사용" );
71+ actualKey = "EmergencySecretKeyForJwtThatIsAtLeast32CharactersLongToEnsureSecurity123456789" ;
72+ }
73+
74+ // 키 길이 재확인
75+ if (actualKey .getBytes ().length < 32 ) {
76+ log .error ("❌ JWT secretKey가 너무 짧습니다! ({} bytes) 임시 키 사용" , actualKey .getBytes ().length );
77+ actualKey = "EmergencySecretKeyForJwtThatIsAtLeast32CharactersLongToEnsureSecurity123456789" ;
78+ }
79+
80+ log .info ("✅ 최종 사용할 키: '{}' (길이: {})" , actualKey , actualKey .length ());
81+
82+ return Keys .hmacShaKeyFor (actualKey .getBytes ());
83+ }
84+
5585 /**
5686 * 토큰 검증
5787 */
@@ -126,11 +156,4 @@ private Claims getClaimsFromToken(String token) {
126156 .parseClaimsJws (token )
127157 .getBody ();
128158 }
129-
130- /**
131- * 서명용 키 생성 (내부 메서드)
132- */
133- private SecretKey getSigningKey () {
134- return Keys .hmacShaKeyFor (secretKey .getBytes ());
135- }
136159}
0 commit comments