Jelajahi Sumber

放行文件

xucaiqin 1 bulan lalu
induk
melakukan
c89b9e7d85

+ 9 - 3
sckw-gateway/src/main/java/com/sckw/gateway/filter/AuthenticationFilter.java

@@ -12,6 +12,7 @@ import com.sckw.core.utils.EncryUtil;
 import com.sckw.core.utils.NumberUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.config.CustomConfig;
+import com.sckw.core.web.constant.CommonConstants;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.constant.RequestConstant;
 import com.sckw.core.web.model.LoginEntInfo;
@@ -29,6 +30,8 @@ import org.springframework.core.io.buffer.DataBuffer;
 import org.springframework.http.server.reactive.ServerHttpRequest;
 import org.springframework.http.server.reactive.ServerHttpResponse;
 import org.springframework.stereotype.Component;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.util.PathMatcher;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 
@@ -59,7 +62,7 @@ public class AuthenticationFilter implements GlobalFilter, Ordered {
     private static final List<String> WITHOUTPATH = new ArrayList<>();
 
     private static final String REGISTER = "/kwsEnt/register";
-
+    private final PathMatcher pathMatcher = new AntPathMatcher();
 
     /**
      * @desc: 初始化放行路径
@@ -92,8 +95,11 @@ public class AuthenticationFilter implements GlobalFilter, Ordered {
         Integer systemType = systemTypeStr == null ? null : Integer.parseInt(systemTypeStr);
 //        String accessSpecial = request.getHeader(RequestConstant.ACCESS_SPECIAL);
         String requestUri = request.getPath().value();
+        boolean isExcluded = EXCLUDEPATH.stream()
+                .anyMatch(pattern -> pathMatcher.match(pattern, requestUri));
+
         /*1、非token校验接口放行*/
-        if (EXCLUDEPATH.contains(requestUri)) {
+        if (isExcluded) {
             if (StrUtil.isNotBlank(token)) {
                 Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, token);
                 if (tokenMap != null) {
@@ -117,7 +123,7 @@ public class AuthenticationFilter implements GlobalFilter, Ordered {
         // 添加对Swagger相关路径的放行
         if (requestUri.startsWith("/swagger-ui") ||
                 requestUri.startsWith("/v3/api-docs") || requestUri.startsWith("/doc.htm")||
-                requestUri.startsWith("/webjars/")) {
+                requestUri.startsWith("/webjars/")||requestUri.startsWith(CommonConstants.RESOURCE_PREFIX)) {
             return chain.filter(exchange);
         }