|
10 | 10 | import jakarta.servlet.http.HttpServletRequest;
|
11 | 11 | import jakarta.servlet.http.HttpServletResponse;
|
12 | 12 | import java.io.IOException;
|
| 13 | +import java.util.List; |
13 | 14 | import lombok.RequiredArgsConstructor;
|
14 | 15 | import lombok.extern.slf4j.Slf4j;
|
| 16 | +import org.springframework.http.HttpMethod; |
15 | 17 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
16 | 18 | import org.springframework.security.core.Authentication;
|
17 | 19 | import org.springframework.security.core.context.SecurityContext;
|
18 | 20 | import org.springframework.security.core.context.SecurityContextHolder;
|
19 | 21 | import org.springframework.security.core.userdetails.UserDetails;
|
20 | 22 | import org.springframework.security.core.userdetails.UserDetailsService;
|
| 23 | +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
| 24 | +import org.springframework.security.web.util.matcher.RequestMatcher; |
21 | 25 | import org.springframework.util.StringUtils;
|
22 | 26 | import org.springframework.web.filter.OncePerRequestFilter;
|
23 | 27 |
|
24 | 28 | @Slf4j(topic = "JWT validation & authorization")
|
25 | 29 | @RequiredArgsConstructor
|
26 | 30 | public class JwtAuthorizationFilter extends OncePerRequestFilter {
|
27 | 31 |
|
| 32 | + private static final List<RequestMatcher> whiteList = |
| 33 | + List.of( |
| 34 | + new AntPathRequestMatcher("/api/migration"), |
| 35 | + new AntPathRequestMatcher("/api/koyeon/**"), |
| 36 | + new AntPathRequestMatcher("/api/routes/**"), |
| 37 | + new AntPathRequestMatcher("/api/search/**", HttpMethod.GET.name()), |
| 38 | + new AntPathRequestMatcher("/api/suggestions"), |
| 39 | + new AntPathRequestMatcher("/api/users/login/**")); |
| 40 | + |
28 | 41 | private final JwtUtil jwtUtil;
|
29 | 42 | private final RedisUtil redisUtil;
|
30 | 43 | private final UserDetailsService userDetailsService;
|
@@ -53,6 +66,12 @@ protected void doFilterInternal(
|
53 | 66 | filterChain.doFilter(request, response);
|
54 | 67 | }
|
55 | 68 |
|
| 69 | + @Override |
| 70 | + protected boolean shouldNotFilter(HttpServletRequest request) { |
| 71 | + // 현재 URL 이 화이트 리스트에 존재하는지 체크 |
| 72 | + return whiteList.stream().anyMatch(whitePath -> whitePath.matches(request)); |
| 73 | + } |
| 74 | + |
56 | 75 | /**
|
57 | 76 | * 인증 처리 (인증 객체를 생성하여 context에 설정)
|
58 | 77 | */
|
|
0 commit comments