From 69e1d5171acb9e298c54e32a722cd2de1564ed1b Mon Sep 17 00:00:00 2001 From: onpyeong Date: Thu, 19 Oct 2023 17:43:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20refresh=20token=20=EC=9D=BC=EC=B9=98?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=84=20=EC=8B=9C=20SophyJwtE?= =?UTF-8?q?xception=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sophy/sophy/exception/ErrorStatus.java | 1 + .../java/org/sophy/sophy/service/common/AuthService.java | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sophy/sophy/exception/ErrorStatus.java b/src/main/java/org/sophy/sophy/exception/ErrorStatus.java index d849e652..52fbcad7 100644 --- a/src/main/java/org/sophy/sophy/exception/ErrorStatus.java +++ b/src/main/java/org/sophy/sophy/exception/ErrorStatus.java @@ -25,6 +25,7 @@ public enum ErrorStatus { INVALID_ACCESS_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, "유효하지 않은 액세스 토큰입니다."), REFRESH_TOKEN_TIME_EXPIRED_EXCEPTION(HttpStatus.UNAUTHORIZED, "만료된 리프레시 토큰입니다."), LOGOUT_REFRESH_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, "로그아웃 하여 리프레시 토큰이 존재하지 않는 상태입니다."), + INVALID_REFRESH_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, "리프레시 토큰의 정보가 일치하지 않습니다."), /** * 403 FORBIDDEN diff --git a/src/main/java/org/sophy/sophy/service/common/AuthService.java b/src/main/java/org/sophy/sophy/service/common/AuthService.java index 35e770ca..afe9fa61 100644 --- a/src/main/java/org/sophy/sophy/service/common/AuthService.java +++ b/src/main/java/org/sophy/sophy/service/common/AuthService.java @@ -1,5 +1,6 @@ package org.sophy.sophy.service.common; +import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.sophy.sophy.controller.dto.request.DuplCheckDto; @@ -12,9 +13,11 @@ import org.sophy.sophy.exception.model.ExistEmailException; import org.sophy.sophy.exception.model.LogoutRefreshtokenException; import org.sophy.sophy.exception.model.SophyException; +import org.sophy.sophy.exception.model.SophyJwtException; import org.sophy.sophy.infrastructure.MemberRepository; import org.sophy.sophy.jwt.TokenProvider; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.core.Authentication; @@ -23,8 +26,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; -import java.util.concurrent.TimeUnit; - @Service @RequiredArgsConstructor @Slf4j @@ -136,7 +137,8 @@ public TokenDto reissue(String accessToken, String refreshToken) { // 4. Refresh Token 일치하는지 검사 if (!existRefreshToken.equals(refreshToken)) { - throw new RuntimeException("Refresh Token의 정보가 일치하지 않습니다."); + throw new SophyJwtException(HttpStatus.UNAUTHORIZED, + ErrorStatus.INVALID_REFRESH_TOKEN_EXCEPTION.getMessage()); } // 5. 새로운 토큰 생성