From c709dc47ecab9db0626f9825db64338fd0a5c98e Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Thu, 3 Aug 2023 16:33:10 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Jwt=20=ED=95=84=ED=84=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=8B=9C=20?= =?UTF-8?q?TokenException=20=EB=B0=9C=EC=83=9D=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/JwtAuthenticationProcessingFilter.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/project/mapdagu/jwt/filter/JwtAuthenticationProcessingFilter.java b/src/main/java/com/project/mapdagu/jwt/filter/JwtAuthenticationProcessingFilter.java index c612366..9d8bae8 100644 --- a/src/main/java/com/project/mapdagu/jwt/filter/JwtAuthenticationProcessingFilter.java +++ b/src/main/java/com/project/mapdagu/jwt/filter/JwtAuthenticationProcessingFilter.java @@ -50,14 +50,16 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse String refreshToken = jwtService.extractRefreshToken(request) .filter(jwtService::isTokenValid) .orElse(null); - String email = jwtService.extractEmail(refreshToken).orElseThrow(() -> new TokenException(ErrorCode.INVALID_TOKEN)); // 리프레시 토큰이 요청 헤더에 존재하고 유효하다면, AccessToken이 만료된 것 -> AccessToken 재발급 - if (refreshToken != null && isRefreshTokenMatch(email, refreshToken)) { - String newAccessToken = jwtService.createAccessToken(email); - String newRefreshToken = jwtService.createRefreshToken(email); - jwtService.updateRefreshToken(email, newRefreshToken); - jwtService.sendAccessAndRefreshToken(response, newAccessToken, refreshToken); + if (refreshToken != null) { + String email = jwtService.extractEmail(refreshToken).orElseThrow(() -> new TokenException(ErrorCode.INVALID_TOKEN)); + if (isRefreshTokenMatch(email, refreshToken)) { + String newAccessToken = jwtService.createAccessToken(email); + String newRefreshToken = jwtService.createRefreshToken(email); + jwtService.updateRefreshToken(email, newRefreshToken); + jwtService.sendAccessAndRefreshToken(response, newAccessToken, refreshToken); + } return; } @@ -97,6 +99,7 @@ public void checkAccessTokenAndAuthentication(HttpServletRequest request, HttpSe * 파라미터의 유저 : 우리가 만든 회원 객체 / 빌더의 유저 : UserDetails의 User 객체 */ public void saveAuthentication(Member member) { + log.info("saveAuthentication() 호출"); String password = member.getPassword(); if (password == null) { // 소셜 로그인 유저의 비밀번호 임의로 설정 하여 소셜 로그인 유저도 인증 되도록 설정 password = PasswordUtil.generateRandomPassword();