Parcourir la source

拦截器里直接排除onlyoffice需要访问的地址。

wukai il y a 1 an
Parent
commit
a5e7ef45d0

+ 4 - 1
doc-framework/src/main/java/com/doc/framework/config/ResourcesConfig.java

@@ -50,7 +50,10 @@ public class ResourcesConfig implements WebMvcConfigurer {
         //下面这句代码相当于添加一个拦截器,添加的拦截器就是我们刚刚创建的
         //addPathPatterns()配置我们要拦截哪些路径 addPathPatterns("/**")表示拦截所有请求,包括我们的静态资源
         registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
-        registry.addInterceptor(whiteListInterceptor).addPathPatterns("/**");
+        //排除onlyoffice需要访问的接口
+        registry.addInterceptor(whiteListInterceptor).addPathPatterns("/**")
+                .excludePathPatterns("/api/access/**")
+                .excludePathPatterns("/only-office/callback/**");
     }
 
     /**

+ 3 - 2
doc-framework/src/main/java/com/doc/framework/interceptor/WhiteListInterceptor.java

@@ -25,14 +25,15 @@ public class WhiteListInterceptor implements HandlerInterceptor {
     private ISysConfigService configService;
 
     @Override
-    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
         String whiteList = configService.selectConfigByKey("access.whiteIPList");
         String no = "false";
         if (StringUtils.isEmpty(whiteList) || no.equals(whiteList)) {
             return true;
         }
+        System.err.println(IpUtils.getIpAddr());
         //需要排除本机和docker的访问
-        whiteList += ";127.0.0.1;172.17.0.*";
+        whiteList += ";127.0.0.1";
         if (IpUtils.isMatchedIp(whiteList, IpUtils.getIpAddr())) {
             return true;
         } else {