1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| @Order(-1) @Component public class AuthorizeFilter implements GlobalFilter {
@Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest(); MultiValueMap<String, String> params = request.getQueryParams();
String auth = params.getFirst("authorization");
if("admin".equals(auth)) { return chain.filter(exchange); }
exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED); return exchange.getResponse().setComplete();
} }
|