Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ protected boolean shouldNotFilter(HttpServletRequest request) {
* 다만 내가 픽했는지 여부등을 파악하기 위해 선택적으로 제공
* <p>
* 수정 : 2024-11-10
*
* TODO: 현재 하드코딩된 경로 관리 방식을 애노테이션 기반으로 개선 필요
* TODO: @AccessPolicy 또는 @OptionalAuth 애노테이션을 활용하여 컨트롤러에서 선언적으로 관리
* TODO: 경로 추가 시마다 두 곳(SecurityConfig + 여기)을 수정해야 하는 문제 해결 필요
*/
private boolean skipFilter(String method, String url) {
final String targetPath = method + ":" + url;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app.bottlenote.global.security.jwt;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Configuration;

@Setter
@Getter
@Configuration
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ConfigurationProperties(prefix = "security.jwt")
@ConfigurationPropertiesScan

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] You’ve placed @ConfigurationPropertiesScan on this class. It's typically applied to a configuration entry point (e.g., the main application class) instead of the properties bean itself—consider relocating the scan annotation.

Suggested change
@ConfigurationPropertiesScan

Copilot uses AI. Check for mistakes.
public class JwtProperties {
private String secretKey;
private long accessTokenExpiration;
private long refreshTokenExpiration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@Component
public class JwtTokenProvider {

public static final int ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24; // 24시간
public static final int REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 14; // 14일
public static final int ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 2;
public static final int REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 14;
Comment on lines +22 to +23

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class still uses static constants for expiration. Consider injecting JwtProperties and using its values here so the provider honors the externalized configuration.

Suggested change
public static final int ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 2;
public static final int REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 14;
@Value("${security.jwt.access-token-expire-time}")
private int accessTokenExpireTime;
@Value("${security.jwt.refresh-token-expire-time}")
private int refreshTokenExpireTime;

Copilot uses AI. Check for mistakes.
public static final String KEY_ROLES = "roles";
private final Key secretKey;

Expand All @@ -30,7 +30,7 @@ public class JwtTokenProvider {
* @param secret 토큰 생성용 시크릿 키
*/
public JwtTokenProvider(
@Value("${security.jwt.secret-key}") String secret
@Value("${security.jwt.secret-key}") String secret
) {
byte[] keyBytes = Decoders.BASE64.decode(secret);
this.secretKey = Keys.hmacShaKeyFor(keyBytes);
Expand All @@ -48,9 +48,9 @@ public TokenItem generateToken(String userEmail, UserType role, Long userId) {
String accessToken = createAccessToken(userEmail, role, userId);
String refreshToken = createRefreshToken(userEmail, role, userId);
return TokenItem.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
}

/**
Expand All @@ -65,11 +65,11 @@ public String createAccessToken(String userEmail, UserType role, Long userId) {
Claims claims = createClaims(userEmail, role, userId);
Date now = new Date();
return Jwts.builder()
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + ACCESS_TOKEN_EXPIRE_TIME))
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + ACCESS_TOKEN_EXPIRE_TIME))
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();
}

public String createGuestToken(Long userId, int expireTime) {
Expand All @@ -78,12 +78,12 @@ public String createGuestToken(Long userId, int expireTime) {
claims.put(KEY_ROLES, UserType.ROLE_GUEST.name());
Date now = new Date();
return Jwts.builder()
.setClaims(claims)
.setSubject("guest")
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + expireTime))
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();
.setClaims(claims)
.setSubject("guest")
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + expireTime))
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();
}

/**
Expand All @@ -98,11 +98,11 @@ public String createRefreshToken(String userEmail, UserType role, Long userId) {
Claims claims = createClaims(userEmail, role, userId);
Date now = new Date();
return Jwts.builder()
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + REFRESH_TOKEN_EXPIRE_TIME))
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + REFRESH_TOKEN_EXPIRE_TIME))
.signWith(secretKey, SignatureAlgorithm.HS512)
.compact();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ spring:
security:
jwt:
secret-key: ${JWT_SECRET_KEY:c2VjdXJlU2VjcmV0S2V5MTIzNDU2Nzg5MGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6QWJDRGVGR2hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlrSg==}
access-token-expiration: 86400 # 하루 (24시간)
refresh-token-expiration: 2592000 # 한 달 (30일)


# Actuator 설정
management:
Expand Down
Loading