Skip to content

Commit 9d40c41

Browse files
authored
Merge pull request #152 from DevKor-github/develop
main에 shouldNotFilter(화이트리스트) 반영
2 parents 6fa14a7 + 82f1e1f commit 9d40c41

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/devkor/com/teamcback/global/jwt/JwtAuthorizationFilter.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,34 @@
1010
import jakarta.servlet.http.HttpServletRequest;
1111
import jakarta.servlet.http.HttpServletResponse;
1212
import java.io.IOException;
13+
import java.util.List;
1314
import lombok.RequiredArgsConstructor;
1415
import lombok.extern.slf4j.Slf4j;
16+
import org.springframework.http.HttpMethod;
1517
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
1618
import org.springframework.security.core.Authentication;
1719
import org.springframework.security.core.context.SecurityContext;
1820
import org.springframework.security.core.context.SecurityContextHolder;
1921
import org.springframework.security.core.userdetails.UserDetails;
2022
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;
2125
import org.springframework.util.StringUtils;
2226
import org.springframework.web.filter.OncePerRequestFilter;
2327

2428
@Slf4j(topic = "JWT validation & authorization")
2529
@RequiredArgsConstructor
2630
public class JwtAuthorizationFilter extends OncePerRequestFilter {
2731

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+
2841
private final JwtUtil jwtUtil;
2942
private final RedisUtil redisUtil;
3043
private final UserDetailsService userDetailsService;
@@ -53,6 +66,12 @@ protected void doFilterInternal(
5366
filterChain.doFilter(request, response);
5467
}
5568

69+
@Override
70+
protected boolean shouldNotFilter(HttpServletRequest request) {
71+
// 현재 URL 이 화이트 리스트에 존재하는지 체크
72+
return whiteList.stream().anyMatch(whitePath -> whitePath.matches(request));
73+
}
74+
5675
/**
5776
* 인증 처리 (인증 객체를 생성하여 context에 설정)
5877
*/

0 commit comments

Comments
 (0)