|
| 1 | +//package com.zerodaycode.summonerssync.apigateway.config; |
| 2 | +// |
| 3 | +//import org.springframework.cloud.gateway.filter.GatewayFilter; |
| 4 | +//import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| 5 | +//import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; |
| 6 | +//import org.springframework.context.annotation.Configuration; |
| 7 | +//import org.springframework.http.HttpHeaders; |
| 8 | +//import org.springframework.http.HttpStatus; |
| 9 | +//import org.springframework.http.server.reactive.ServerHttpRequest; |
| 10 | +//import org.springframework.http.server.reactive.ServerHttpResponse; |
| 11 | +//import org.springframework.web.server.ServerWebExchange; |
| 12 | +//import reactor.core.publisher.Mono; |
| 13 | +// |
| 14 | +//@Configuration |
| 15 | +//public class AuthFilter implements GatewayFilter { |
| 16 | +// |
| 17 | +// @Override |
| 18 | +// public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { |
| 19 | +// ServerHttpRequest request = exchange.getRequest(); |
| 20 | +//// if (routerValidator.isSecured.test(request)) { |
| 21 | +//// if (this.isAuthMissing(request)) |
| 22 | +//// return this.onError(exchange, "Authorization header is missing in request", HttpStatus.UNAUTHORIZED); |
| 23 | +//// final String token = this.getAuthHeader(request); |
| 24 | +//// if (jwtUtil.isInvalid(token)) |
| 25 | +//// return this.onError(exchange, "Authorization header is invalid", HttpStatus.UNAUTHORIZED); |
| 26 | +//// this.populateRequestWithHeaders(exchange, token); |
| 27 | +//// } |
| 28 | +// return chain.filter(exchange); |
| 29 | +// } |
| 30 | +// /*PRIVATE*/ |
| 31 | +// private Mono<Void> onError(ServerWebExchange exchange, String err, HttpStatus httpStatus) { |
| 32 | +// ServerHttpResponse response = exchange.getResponse(); |
| 33 | +// response.setStatusCode(httpStatus); |
| 34 | +// return response.setComplete(); |
| 35 | +// } |
| 36 | +// private String getAuthHeader(ServerHttpRequest request) { |
| 37 | +// return request.getHeaders().getOrEmpty("Authorization").getFirst(); |
| 38 | +// } |
| 39 | +// private boolean isAuthMissing(ServerHttpRequest request) { |
| 40 | +// return !request.getHeaders().containsKey("Authorization"); |
| 41 | +// } |
| 42 | +// private void populateRequestWithHeaders(ServerWebExchange exchange, String token) { |
| 43 | +// Claims claims = jwtUtil.getAllClaimsFromToken(token); |
| 44 | +// exchange.getRequest().mutate() |
| 45 | +// .header("id", String.valueOf(claims.get("id"))) |
| 46 | +// .header("role", String.valueOf(claims.get("role"))) |
| 47 | +// .build(); |
| 48 | +// } |
| 49 | +//} |
0 commit comments