diff --git a/src/main/java/com/beat/global/auth/jwt/provider/JwtTokenProvider.java b/src/main/java/com/beat/global/auth/jwt/provider/JwtTokenProvider.java index 749bfe2e..1aac0d78 100644 --- a/src/main/java/com/beat/global/auth/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/beat/global/auth/jwt/provider/JwtTokenProvider.java @@ -27,12 +27,10 @@ public class JwtTokenProvider { private long REFRESH_TOKEN_EXPIRE_TIME; private static final String MEMBER_ID = "memberId"; - private SecretKey secretKey; @PostConstruct protected void init() { - byte[] keyBytes = Base64.getEncoder().encode(JWT_SECRET.getBytes(StandardCharsets.UTF_8)); - this.secretKey = Keys.hmacShaKeyFor(keyBytes); + JWT_SECRET = Base64.getEncoder().encodeToString(JWT_SECRET.getBytes(StandardCharsets.UTF_8)); } public String issueAccessToken(final Authentication authentication) { @@ -54,10 +52,15 @@ private String issueToken(final Authentication authentication, final long expire return Jwts.builder() .setHeaderParam(Header.TYPE, Header.JWT_TYPE) .setClaims(claims) - .signWith(secretKey) + .signWith(getSigningKey()) .compact(); } + private SecretKey getSigningKey() { + String encodedKey = Base64.getEncoder().encodeToString(JWT_SECRET.getBytes()); //SecretKey 통해 서명 생성 + return Keys.hmacShaKeyFor(encodedKey.getBytes()); //일반적으로 HMAC (Hash-based Message Authentication Code) 알고리즘 사용 + } + public JwtValidationType validateToken(String token) { try { Claims claims = getBody(token); @@ -76,7 +79,7 @@ public JwtValidationType validateToken(String token) { private Claims getBody(final String token) { return Jwts.parserBuilder() - .setSigningKey(secretKey) + .setSigningKey(getSigningKey()) .build() .parseClaimsJws(token) .getBody(); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index cd963466..95949472 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -14,7 +14,7 @@ spring: jpa: hibernate: - ddl-auto: create + ddl-auto: update show-sql: true properties: hibernate: @@ -23,7 +23,7 @@ spring: data: redis: - host: localhost + host: ${DEV_REDIS_HOST} port: 6379 security: diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index ee4fb9e4..3b21c334 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -13,8 +13,8 @@ spring: password: ${PROD_DB_PASSWORD} jpa: hibernate: - ddl-auto: create - show-sql: false + ddl-auto: update + show-sql: true properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect @@ -22,7 +22,7 @@ spring: data: redis: - host: localhost + host: ${PROD_REDIS_HOST} port: 6379 security: