66import io .jsonwebtoken .UnsupportedJwtException ;
77import lombok .RequiredArgsConstructor ;
88import lombok .extern .slf4j .Slf4j ;
9- import org .springframework .cloud .gateway .filter .GatewayFilterChain ;
10- import org .springframework .cloud .gateway .filter .GlobalFilter ;
11- import org .springframework .core .Ordered ;
129import org .springframework .http .HttpMethod ;
1310import org .springframework .http .HttpStatus ;
1411import org .springframework .http .server .reactive .ServerHttpRequest ;
1512import org .springframework .stereotype .Component ;
1613import org .springframework .web .server .ServerWebExchange ;
14+ import org .springframework .web .server .WebFilter ;
15+ import org .springframework .web .server .WebFilterChain ;
1716import reactor .core .publisher .Mono ;
1817
1918@ Component
2019@ RequiredArgsConstructor
2120@ Slf4j
22- public class JwtFilter implements GlobalFilter , Ordered {
21+ public class JwtFilter implements WebFilter {
2322
2423 private final JwtUtil jwtUtil ;
2524
2625 @ Override
27- public Mono <Void > filter (ServerWebExchange exchange , GatewayFilterChain chain ) {
26+ public Mono <Void > filter (ServerWebExchange exchange , WebFilterChain chain ) {
2827
2928 // CORS 프리플라이트는 바로 통과
3029 HttpMethod method = exchange .getRequest ().getMethod ();
@@ -36,6 +35,17 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
3635 String authHeader = exchange .getRequest ().getHeaders ().getFirst ("Authorization" );
3736 log .info ("[JwtFilter] 요청 path={}, Authorization={}" , path , authHeader );
3837
38+ // 화이트리스트 경로 예외 처리
39+ if (path .startsWith ("/actuator/health" ) ||
40+ path .startsWith ("/test-token" ) ||
41+ path .startsWith ("/user/auth/" ) ||
42+ path .startsWith ("/swagger-ui" ) ||
43+ path .startsWith ("/v3/api-docs" ) ||
44+ path .startsWith ("/error" )) {
45+ log .info ("[JwtFilter] 통과 path={}" , path );
46+ return chain .filter (exchange );
47+ }
48+
3949 if (authHeader == null || !authHeader .startsWith ("Bearer " )) {
4050 log .warn ("[JwtFilter] Authorization 헤더 없음 또는 Bearer 형식 아님" );
4151 exchange .getResponse ().setStatusCode (HttpStatus .UNAUTHORIZED );
@@ -75,9 +85,4 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
7585 exchange .getResponse ().setStatusCode (HttpStatus .UNAUTHORIZED );
7686 return exchange .getResponse ().setComplete ();
7787 }
78-
79- @ Override
80- public int getOrder () {
81- return -1 ; // 먼저 실행
82- }
8388}
0 commit comments