From 74c8174699370bf61fc187edb5906250b374827b Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Sat, 5 Aug 2023 11:38:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20JWT=20=ED=95=84=ED=84=B0=20Access=20Tok?= =?UTF-8?q?en=20=EA=B2=80=EC=A6=9D=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JwtAuthenticationProcessingFilter.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 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 9d8bae8..d1c087b 100644 --- a/src/main/java/com/project/mapdagu/jwt/filter/JwtAuthenticationProcessingFilter.java +++ b/src/main/java/com/project/mapdagu/jwt/filter/JwtAuthenticationProcessingFilter.java @@ -46,29 +46,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse return; } - // 사용자 요청 헤더에서 RefreshToken 추출-> RefreshToken이 없거나 유효하지 않다면 null - String refreshToken = jwtService.extractRefreshToken(request) - .filter(jwtService::isTokenValid) - .orElse(null); - - // 리프레시 토큰이 요청 헤더에 존재하고 유효하다면, AccessToken이 만료된 것 -> AccessToken 재발급 - 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; - } + log.info("JwtAuthenticationProcessingFilter 호출"); + String accessToken = jwtService.extractAccessToken(request).orElse(null); - // AccessToken을 검사하고 인증 처리 - // AccessToken이 없거나 유효하지 않다면, 인증 객체가 담기지 않은 상태로 다음 필터로 넘어가기 때문에 403 에러 발생 - // AccessToken이 유효하다면, 인증 객체가 담긴 상태로 다음 필터로 넘어가기 때문에 인증 성공 - else { - checkAccessTokenAndAuthentication(request, response, filterChain); + if (jwtService.isTokenValid(accessToken)) { + jwtService.extractEmail(accessToken) + .ifPresent(email -> memberRepository.findByEmail(email) + .ifPresent(this::saveAuthentication)); } + filterChain.doFilter(request, response); } public boolean isRefreshTokenMatch(String email, String refreshToken) {