diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java b/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java index 2f2ccdef..904d42bd 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java @@ -1,10 +1,7 @@ package com.postgraduate.domain.auth.application.dto.res; import com.postgraduate.domain.user.domain.entity.constant.Role; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Builder @Getter @@ -12,6 +9,8 @@ @AllArgsConstructor public class JwtTokenResponse { private String accessToken; + private int accessExpiration; private String refreshToken; + private int refreshExpiration; private Role role; } diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java index 34bb9771..b9d117ba 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java @@ -7,6 +7,7 @@ import com.postgraduate.global.jwt.JwtProvider; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -14,6 +15,10 @@ public class JwtUseCase { private final JwtProvider jwtProvider; private final SecurityUtils securityUtils; + @Value("${jwt.refreshExpiration}") + private int refreshExpiration; + @Value("${jwt.accessExpiration}") + private int accessExpiration; public JwtTokenResponse signIn(User user) { return generateToken(user); @@ -28,6 +33,6 @@ public JwtTokenResponse regenerateToken(AuthDetails authDetails, HttpServletRequ private JwtTokenResponse generateToken(User user) { String accessToken = jwtProvider.generateAccessToken(user.getUserId(), user.getRole()); String refreshToken = jwtProvider.generateRefreshToken(user.getUserId(), user.getRole()); - return new JwtTokenResponse(accessToken, refreshToken, user.getRole()); + return new JwtTokenResponse(accessToken, accessExpiration, refreshToken, refreshExpiration, user.getRole()); } } diff --git a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java index e4310f2c..caa92edf 100644 --- a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java @@ -8,5 +8,4 @@ @RestControllerAdvice @RequiredArgsConstructor public class GlobalExceptionHandler { - } diff --git a/src/main/java/com/postgraduate/global/jwt/JwtProvider.java b/src/main/java/com/postgraduate/global/jwt/JwtProvider.java index 5c00de1c..4631cc29 100644 --- a/src/main/java/com/postgraduate/global/jwt/JwtProvider.java +++ b/src/main/java/com/postgraduate/global/jwt/JwtProvider.java @@ -29,11 +29,15 @@ public class JwtProvider { private final RedisRepository redisRepository; @Value("${jwt.secret-key}") private String secret; + @Value("${jwt.refreshExpiration}") + private int refreshExpiration; + @Value("${jwt.accessExpiration}") + private int accessExpiration; private final String REFRESH = "refresh"; private final String AUTHORIZATION = "Authorization"; public String generateAccessToken(Long id, Role role) { - Instant accessDate = LocalDateTime.now().plusHours(6).atZone(ZoneId.systemDefault()).toInstant(); + Instant accessDate = LocalDateTime.now().plusSeconds(accessExpiration).atZone(ZoneId.systemDefault()).toInstant(); return Jwts.builder() .claim("role", role) .setSubject(String.valueOf(id)) @@ -43,7 +47,7 @@ public String generateAccessToken(Long id, Role role) { } public String generateRefreshToken(Long id, Role role) { - Instant refreshDate = LocalDateTime.now().plusDays(30).atZone(ZoneId.systemDefault()).toInstant(); + Instant refreshDate = LocalDateTime.now().plusSeconds(refreshExpiration).atZone(ZoneId.systemDefault()).toInstant(); String refreshToken = Jwts.builder() .claim("role", role) .setSubject(String.valueOf(id))