Commit 9fd172f9 by 刘宇峰

加入swagger放通拦截

1 parent 4afb0539
...@@ -24,6 +24,7 @@ import org.springframework.http.MediaType; ...@@ -24,6 +24,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
...@@ -32,6 +33,7 @@ import java.nio.charset.StandardCharsets; ...@@ -32,6 +33,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* @author payu * @author payu
...@@ -64,7 +66,7 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered { ...@@ -64,7 +66,7 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered {
String url = request.getURI().getPath(); String url = request.getURI().getPath();
//跳过不需要验证的路径 //跳过不需要验证的路径
if (Arrays.asList(skipAuthUrls).contains(url)) { if (isMatchedStr(skipAuthUrls, url)) {
return chain.filter(exchange); return chain.filter(exchange);
} }
...@@ -157,4 +159,26 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered { ...@@ -157,4 +159,26 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered {
//return stringRedisTemplate.hasKey(String.format(properties.getBlacklistKey(), token)); //return stringRedisTemplate.hasKey(String.format(properties.getBlacklistKey(), token));
} }
/**
* 判断当前访问的url是否开头URI是在配置的忽略url列表中
*
* @param url
* @return
*/
public static boolean isMatchedStr(String[] skipAuthUrls, String url) {
if (StringUtils.isEmpty(url)) {
return false;
}
if (Objects.isNull(skipAuthUrls)) {
return false;
}
AntPathMatcher matcher = new AntPathMatcher();
for (String skipAuthUrl : skipAuthUrls) {
if (matcher.match(skipAuthUrl, url)) {
return true;
}
}
return false;
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!