Browse Source

优化token接口放行支持通配符匹配逻辑

test
smallchill 4 years ago
parent
commit
02eace3b94
  1. 6
      blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java
  2. 2
      blade-gateway/src/main/java/org/springblade/gateway/provider/AuthProvider.java

6
blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java

@ -36,6 +36,7 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@ -54,6 +55,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
private final AuthProperties authProperties;
private final ObjectMapper objectMapper;
private final JwtProperties jwtProperties;
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
@ -89,8 +91,8 @@ public class AuthFilter implements GlobalFilter, Ordered {
}
private boolean isSkip(String path) {
return AuthProvider.getDefaultSkipUrl().stream().map(url -> url.replace(AuthProvider.TARGET, AuthProvider.REPLACEMENT)).anyMatch(path::startsWith)
|| authProperties.getSkipUrl().stream().map(url -> url.replace(AuthProvider.TARGET, AuthProvider.REPLACEMENT)).anyMatch(path::startsWith);
return AuthProvider.getDefaultSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path))
|| authProperties.getSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path));
}
private Mono<Void> unAuth(ServerHttpResponse resp, String msg) {

2
blade-gateway/src/main/java/org/springblade/gateway/provider/AuthProvider.java

@ -28,8 +28,6 @@ import java.util.List;
*/
public class AuthProvider {
public static final String TARGET = "/**";
public static final String REPLACEMENT = "";
public static final String AUTH_KEY = TokenConstant.HEADER;
private static final List<String> DEFAULT_SKIP_URL = new ArrayList<>();

Loading…
Cancel
Save