From bf9a637a49d42517dfe0110894222a8e50b0489f Mon Sep 17 00:00:00 2001 From: mybloom Date: Sun, 12 Jun 2022 00:58:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=95=84=ED=84=B0=EC=97=90=20TokenExpi?= =?UTF-8?q?redException=20=EC=9D=B5=EC=85=89=EC=85=98=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=9E=91=EC=84=B1=20(ios-h/airbn?= =?UTF-8?q?b#35)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/team4/airbnb/filter/AuthCheckFilter.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/BE/src/main/java/org/team4/airbnb/filter/AuthCheckFilter.java b/BE/src/main/java/org/team4/airbnb/filter/AuthCheckFilter.java index 315901c0e..d9ed75c3b 100644 --- a/BE/src/main/java/org/team4/airbnb/filter/AuthCheckFilter.java +++ b/BE/src/main/java/org/team4/airbnb/filter/AuthCheckFilter.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import io.jsonwebtoken.Claims; import java.io.IOException; import java.nio.charset.StandardCharsets; import javax.servlet.FilterChain; @@ -16,6 +17,7 @@ import org.springframework.web.filter.OncePerRequestFilter; import org.team4.airbnb.auth.JwtTokenProvider; import org.team4.airbnb.exception.ErrorResponse; +import org.team4.airbnb.exception.TokenExpiredException; import org.team4.airbnb.exception.TokenInValidateException; @Slf4j @@ -34,12 +36,17 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse validateHeader(header); String accessToken = header.substring("Bearer ".length()); - jwtTokenProvider.validateJwtToken(accessToken); -// Claims claims = jwtTokenProvider.parseJwtToken(accessToken); + Claims claims = jwtTokenProvider.validateJwtToken(accessToken); filterChain.doFilter(request, response); - } catch (TokenInValidateException e) { - ErrorResponse errorResponse = new ErrorResponse(new String("invalid token".getBytes(),StandardCharsets.UTF_8)); + } catch (TokenInValidateException inValidateException) { + ErrorResponse errorResponse = new ErrorResponse( + new String("invalid token".getBytes(), StandardCharsets.UTF_8)); + response.setStatus(HttpStatus.UNAUTHORIZED.value()); + response.getWriter().write(convertObjectToJson(errorResponse)); + } catch (TokenExpiredException expiredException) { + ErrorResponse errorResponse = new ErrorResponse( + new String("authentication is expired".getBytes(), StandardCharsets.UTF_8)); response.setStatus(HttpStatus.UNAUTHORIZED.value()); response.getWriter().write(convertObjectToJson(errorResponse)); }