diff --git a/BE/exceed/src/main/java/com/gaebaljip/exceed/application/service/auth/AuthService.java b/BE/exceed/src/main/java/com/gaebaljip/exceed/application/service/auth/AuthService.java index 7899290db..ab12e54ed 100644 --- a/BE/exceed/src/main/java/com/gaebaljip/exceed/application/service/auth/AuthService.java +++ b/BE/exceed/src/main/java/com/gaebaljip/exceed/application/service/auth/AuthService.java @@ -1,5 +1,7 @@ package com.gaebaljip.exceed.application.service.auth; +import com.gaebaljip.exceed.adapter.out.redis.RedisAdapter; +import com.gaebaljip.exceed.common.dto.ReissueTokenDTO; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,6 +16,8 @@ import lombok.RequiredArgsConstructor; +import javax.servlet.http.HttpServletRequest; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -29,9 +33,11 @@ public LoginResponseDTO execute(LoginRequest request) { if (!bCryptPasswordEncoder.matches(request.password(), member.getPassword())) { throw PasswordMismatchException.EXECPTION; } - return LoginResponseDTO.builder() + LoginResponseDTO loginResponseDTO = LoginResponseDTO.builder() .accessToken(jwtManager.generateAccessToken(member.getId())) .refreshToken(jwtManager.generateRefreshToken(member.getId())) .build(); + jwtManager.saveRefreshToken(request.email(), loginResponseDTO.refreshToken()); + return loginResponseDTO; } } diff --git a/BE/exceed/src/main/java/com/gaebaljip/exceed/common/security/domain/JwtManager.java b/BE/exceed/src/main/java/com/gaebaljip/exceed/common/security/domain/JwtManager.java index 49395d7d9..d4c04d2ac 100644 --- a/BE/exceed/src/main/java/com/gaebaljip/exceed/common/security/domain/JwtManager.java +++ b/BE/exceed/src/main/java/com/gaebaljip/exceed/common/security/domain/JwtManager.java @@ -6,6 +6,8 @@ import javax.servlet.http.HttpServletRequest; +import com.gaebaljip.exceed.adapter.out.redis.RedisAdapter; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.AuthenticationException; import org.springframework.stereotype.Component; @@ -25,10 +27,12 @@ public class JwtManager { private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 3; // 3일 private static final long REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 7; // 7일 private final Key key; + private RedisAdapter redisAdapter; - public JwtManager(@Value("${jwt.secret}") String secretKey) { + public JwtManager(@Value("${jwt.secret}") String secretKey, RedisAdapter redisAdapter) { byte[] keyBytes = Decoders.BASE64.decode(secretKey); this.key = Keys.hmacShaKeyFor(keyBytes); + this.redisAdapter = redisAdapter; } public String generateAccessToken(Long memberId) { @@ -152,4 +156,8 @@ public boolean validateRefreshToken(String refreshToken, HttpServletRequest requ } return false; } + + public void saveRefreshToken(String email, String refreshToken) { + redisAdapter.saveWithExpiration(email, refreshToken, REFRESH_TOKEN_EXPIRE_TIME); + } }