From f2b8dc4c4949b4bab0c670e393c14413dc9333d1 Mon Sep 17 00:00:00 2001 From: koungq Date: Tue, 20 Aug 2024 19:26:20 +0900 Subject: [PATCH] =?UTF-8?q?Hotfix:=20JWT=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JwtAuthenticationProcessingFilter.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java b/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java index 38e687d6..948bc2eb 100644 --- a/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java +++ b/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java @@ -52,23 +52,20 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse public void checkAccessTokenAndRefreshToken(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain, String refreshToken) throws ServletException, IOException { log.info("checkAccessTokenAndRefreshToken() 호출"); - jwtService.extractAccessToken(request) + + String accessToken = jwtService.extractAccessToken(request) .filter(jwtService::isTokenValid) - .ifPresentOrElse( - accessToken -> jwtService.extractEmail(accessToken) - .ifPresent(email -> userRepository.findByEmail(email) - .ifPresent(user -> { - saveAuthentication(user); - try { - filterChain.doFilter(request, response); - } catch (IOException | ServletException e) { - throw new RuntimeException(e); - } - })), - () -> checkRefreshTokenAndReIssueAccessToken(response, refreshToken) - ); + .orElse(null); - filterChain.doFilter(request, response); + if (accessToken == null) { + checkRefreshTokenAndReIssueAccessToken(response, refreshToken); + } else { + jwtService.extractEmail(accessToken) + .ifPresent(email -> userRepository.findByEmail(email) + .ifPresent(this::saveAuthentication)); + + filterChain.doFilter(request, response); + } } public void checkRefreshTokenAndReIssueAccessToken(HttpServletResponse response, String refreshToken) {