Skip to content

Commit

Permalink
fix: token validate 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
23Yong committed Oct 6, 2023
1 parent d44943d commit 20b33ff
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package kr.codesquad.secondhand.presentation.filter;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import kr.codesquad.secondhand.exception.ErrorCode;
import kr.codesquad.secondhand.exception.UnAuthorizedException;
import kr.codesquad.secondhand.infrastructure.jwt.JwtExtractor;
Expand All @@ -18,6 +10,15 @@
import org.springframework.web.cors.CorsUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class JwtFilter extends OncePerRequestFilter {

private final AntPathMatcher pathMatcher = new AntPathMatcher();
Expand All @@ -39,7 +40,10 @@ protected boolean shouldNotFilter(HttpServletRequest request) {
HttpMethod method = HttpMethod.resolve(request.getMethod());
if (method == HttpMethod.GET && isExcludeGetUrl(request.getRequestURI())) {
extractToken(request).ifPresentOrElse(
token -> authenticationContext.setMemberId(jwtProvider.extractClaims(token)),
token -> {
jwtProvider.validateToken(token);
authenticationContext.setMemberId(jwtProvider.extractClaims(token));
},
() -> authenticationContext.setMemberId(Map.of("memberId", -1L)));
return true;
}
Expand Down

0 comments on commit 20b33ff

Please sign in to comment.