File tree Expand file tree Collapse file tree
java/flipnote/apigateway/filter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import flipnote .apigateway .client .TokenValidationClient ;
44import lombok .extern .slf4j .Slf4j ;
55import org .springframework .cloud .gateway .filter .GatewayFilter ;
6- import org .springframework .cloud .gateway .filter .OrderedGatewayFilter ;
76import org .springframework .cloud .gateway .filter .factory .AbstractGatewayFilterFactory ;
8- import org .springframework .core .Ordered ;
97import org .springframework .http .HttpCookie ;
108import org .springframework .http .HttpStatus ;
119import org .springframework .stereotype .Component ;
@@ -27,7 +25,7 @@ public AuthenticationFilter(TokenValidationClient tokenValidationClient) {
2725
2826 @ Override
2927 public GatewayFilter apply (Config config ) {
30- GatewayFilter filter = (exchange , chain ) -> {
28+ return (exchange , chain ) -> {
3129 HttpCookie cookie = exchange .getRequest ().getCookies ().getFirst (ACCESS_TOKEN_COOKIE );
3230
3331 if (cookie == null ) {
@@ -56,7 +54,6 @@ public GatewayFilter apply(Config config) {
5654 return onError (exchange , HttpStatus .UNAUTHORIZED );
5755 });
5856 };
59- return new OrderedGatewayFilter (filter , Ordered .LOWEST_PRECEDENCE );
6057 }
6158
6259 private Mono <Void > onError (ServerWebExchange exchange , HttpStatus status ) {
Original file line number Diff line number Diff line change 1+ package flipnote .apigateway .filter ;
2+
3+ import java .util .List ;
4+
5+ import org .springframework .cloud .gateway .filter .GatewayFilterChain ;
6+ import org .springframework .cloud .gateway .filter .GlobalFilter ;
7+ import org .springframework .core .Ordered ;
8+ import org .springframework .http .server .reactive .ServerHttpRequest ;
9+ import org .springframework .stereotype .Component ;
10+ import org .springframework .web .server .ServerWebExchange ;
11+
12+ import reactor .core .publisher .Mono ;
13+
14+ @ Component
15+ public class HeaderCleanupGlobalFilter implements GlobalFilter , Ordered {
16+
17+ private static final List <String > HEADERS_TO_REMOVE = List .of (
18+ "X-User-Id" ,
19+ "X-User-Email" ,
20+ "X-User-Role"
21+ );
22+
23+ @ Override
24+ public Mono <Void > filter (ServerWebExchange exchange , GatewayFilterChain chain ) {
25+ ServerHttpRequest request = exchange .getRequest ().mutate ()
26+ .headers (headers -> HEADERS_TO_REMOVE .forEach (headers ::remove ))
27+ .build ();
28+
29+ return chain .filter (exchange .mutate ().request (request ).build ());
30+ }
31+
32+ @ Override
33+ public int getOrder () {
34+ return Ordered .HIGHEST_PRECEDENCE ;
35+ }
36+ }
Original file line number Diff line number Diff line change 77
88 cloud :
99 gateway :
10- default-filters :
11- - RemoveRequestHeader=X-User-Id
12- - RemoveRequestHeader=X-User-Email
13- - RemoveRequestHeader=X-User-Role
1410 routes :
1511 - id : user-private
1612 uri : http://user-service:8081
You can’t perform that action at this time.
0 commit comments