Procházet zdrojové kódy

【CHG】修改签名过滤方法

zhaomn před 3 roky
rodič
revize
219dea1c45

+ 0 - 6
railway-admin/src/main/java/com/railway/RailwayApplication.java

@@ -1,6 +1,5 @@
 package com.railway;
 
-import com.railway.framework.web.service.INeedSignCheck;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -20,10 +19,5 @@ public class RailwayApplication {
   public static void main(String[] args) {
     SpringApplication.run(RailwayApplication.class, args);
     System.out.println("启动成功");
-    INeedSignCheck.SIGN_IGNORE_URLS.add("monitor");
-    INeedSignCheck.SIGN_IGNORE_URLS.add("common");
-    INeedSignCheck.SIGN_IGNORE_URLS.add("captchaImage");
-    INeedSignCheck.SIGN_IGNORE_URLS.add("profile");
-    INeedSignCheck.SIGN_IGNORE_URLS.add("error");
   }
 }

+ 7 - 1
railway-framework/src/main/java/com/railway/framework/config/ResourcesConfig.java

@@ -53,7 +53,13 @@ public class ResourcesConfig implements WebMvcConfigurer {
   @Override
   public void addInterceptors(InterceptorRegistry registry) {
     registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
-    registry.addInterceptor(signatureInterceptor).addPathPatterns("/**");
+    registry.addInterceptor(signatureInterceptor)
+        // 默认拦截所有的路径
+        .addPathPatterns("/**")
+        // 不需要拦截的路由,swagger3
+        .excludePathPatterns("/swagger-resources/**","/swagger-ui/**", "/v3/**", "/error")
+        // 不需要拦截的路由
+        .excludePathPatterns("/profile/**","/captchaImage", "/common/**", "/monitor/**");
   }
 
   /**

+ 0 - 10
railway-framework/src/main/java/com/railway/framework/interceptor/SignatureInterceptor.java

@@ -53,16 +53,6 @@ public class SignatureInterceptor extends HandlerInterceptorAdapter {
     if (iNeedSignCheck.needCheckSignature(unSign)) {
       return true;
     }
-    // 过滤接口
-    String servletPath = request.getServletPath().replaceFirst("/", "");
-    log.info("servletPath = {}", servletPath);
-    int first = servletPath.indexOf("/");
-    if(first > 0){
-      servletPath = servletPath.substring(0, first);
-    }
-    if (INeedSignCheck.SIGN_IGNORE_URLS.contains(servletPath)) {
-      return true;
-    }
     response.setCharacterEncoding("UTF-8");
     response.setHeader("Access-Control-Allow-Origin", "*");
 

+ 7 - 0
railway-framework/src/main/java/com/railway/framework/security/advice/SecretRequestAdvice.java

@@ -59,6 +59,13 @@ public class SecretRequestAdvice extends RequestBodyAdviceAdapter {
         || !INeedSignCheck.SIGN_IGNORE_URLS.contains(ignorePath[0]);
   }
 
+  @Override
+  public Object handleEmptyBody(Object body, @NonNull HttpInputMessage inputMessage,
+      @NonNull MethodParameter parameter, @NonNull Type targetType,
+      @NonNull Class<? extends HttpMessageConverter<?>> converterType) {
+    return body;
+  }
+
   @Override
   @Nonnull
   public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage,