ソースを参照

AccessInterceptor 中只对以 /bg 为前缀的后台请求进行校验

reghao 4 ヶ月 前
コミット
c978903b9b

+ 5 - 39
web/src/main/java/cn/reghao/bnt/web/config/AccessInterceptor.java

@@ -2,7 +2,6 @@ package cn.reghao.bnt.web.config;
 
 import cn.reghao.bnt.web.admin.model.dto.AccountInfo;
 import cn.reghao.bnt.web.admin.service.*;
-import cn.reghao.bnt.web.config.spring.SpringLifecycle;
 import cn.reghao.jutil.jdk.http.HeaderNames;
 import cn.reghao.jutil.web.ServletUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -49,49 +48,16 @@ public class AccessInterceptor implements HandlerInterceptor {
         String uri = request.getRequestURI();
         String method = request.getMethod();
         String host = request.getHeader("host");
-        if (uri.startsWith("/swagger-ui") || uri.startsWith("/v3/api-docs")) {
+        // 后台访问
+        Set<String> backgroundDomainSet = siteOptionService.getBackgroundDomain();
+        if (uri.startsWith("/bg") && backgroundDomainSet.contains(host)) {
             return true;
-        } else if (uri.equals("/") || uri.startsWith("/file/") || uri.startsWith("/bg/api/actuator")) {
-            return true;
-        }
-
-        if (isForegroundAccess(uri)) {
-            // 前台访问
-            String foregroundDomain = siteOptionService.getForegroundDomain();
-            if (host.equals(foregroundDomain)) {
-                return true;
-            }
         } else {
-            // 后台访问
-            Set<String> backgroundDomainSet = siteOptionService.getBackgroundDomain();
-            if (backgroundDomainSet.contains(host)) {
-                return true;
-            }
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
         }
 
-        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
         logService.saveAccessLog();
-        return false;
-    }
-
-    private boolean isOssSdkAccess(String uri, String method) {
-        return uri.startsWith("/bg/api/oss/") && !method.equalsIgnoreCase("options");
-    }
-
-    private boolean isForegroundAccess(String uri) {
-        if (uri.equals("/")) {
-            return true;
-        }
-
-        boolean matched = false;
-        for (String url : SpringLifecycle.foregroundUrlsPrefix) {
-            if (uri.startsWith(url)) {
-                matched = true;
-                break;
-            }
-        }
-
-        return matched;
+        return true;
     }
 
     @Override