فهرست منبع

取消antpathmather匹配

xiehui 3 سال پیش
والد
کامیت
39f590531e

+ 1 - 0
.gitignore

@@ -11,6 +11,7 @@
 .mtj.tmp/
 
 .idea/
+**/src/test/**
 target/
 # Package Files #
 *.jar

+ 8 - 0
spring-wechars/pom.xml

@@ -52,6 +52,14 @@
             <artifactId>common-tools</artifactId>
             <version>${revision}</version>
         </dependency>
+
+        <!--springboot程序测试依赖,如果是自动创建项目默认添加-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        
     </dependencies>
 
 </project>

+ 0 - 10
spring-wechars/src/main/java/cn/org/spring/wechar/config/MessageConfig.java

@@ -9,7 +9,6 @@ import cn.org.spring.wechar.service.message.TextMessageService;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.util.AntPathMatcher;
 
 /**
  * 消息配置类
@@ -33,14 +32,5 @@ public class MessageConfig {
         return contextMessageFactory;
     }
 
-    /**
-     * 注入一个字符匹配工具类,由spring提供
-     *
-     * @return
-     */
-    @Bean
-    public AntPathMatcher getAntPathMatcher() {
-        return new AntPathMatcher();
-    }
 
 }

+ 1 - 0
spring-wechars/src/main/java/cn/org/spring/wechar/config/WebConfig.java

@@ -29,6 +29,7 @@ public class WebConfig implements WebMvcConfigurer {
         InterceptorRegistration registration = registry.addInterceptor(loginUserInterceptor);
         System.out.println("loginUserInterceptor:" + loginUserInterceptor);
         registration.addPathPatterns("/**");
+        registration.excludePathPatterns("/**/weChar","/**/weChar/getCode","/**/index","/**/login");
     }
 
 

+ 1 - 21
spring-wechars/src/main/java/cn/org/spring/wechar/interceptor/LoginUserInterceptor.java

@@ -5,12 +5,9 @@ import cn.org.spring.wechar.config.BasicInfo;
 import cn.org.spring.wechar.utils.CacheUtil;
 import cn.org.spring.wechar.utils.CookieUtils;
 import com.alibaba.fastjson.JSONObject;
-import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
-import org.springframework.util.AntPathMatcher;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
 import javax.servlet.http.HttpServletRequest;
@@ -27,9 +24,8 @@ import java.io.PrintWriter;
  */
 
 @Slf4j
-@Data
+
 @Component
-@ConfigurationProperties(prefix = "login-interceptor")
 public class LoginUserInterceptor extends HandlerInterceptorAdapter {
     @Autowired
     CacheUtil cacheUtil;
@@ -37,27 +33,11 @@ public class LoginUserInterceptor extends HandlerInterceptorAdapter {
     @Autowired
     BasicInfo basicInfo;
 
-    @Autowired
-    AntPathMatcher antPathMatcher;
-
-    private String excludePatterns = "";
 
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         String uri = request.getRequestURI();
-
         System.out.println("request.getRequestURI():" + uri);
-        System.out.println("不拦截路径信息:" + excludePatterns);
-
-        String[] split = excludePatterns.split(",");
-        for (String s : split) {
-            boolean match = antPathMatcher.match(s, uri);
-            if (match) {
-                log.info("匹配到不拦截的路径:【{}】", s);
-                return true;
-            }
-        }
-
 
         String cookieValue = CookieUtils.getCookieValue(request, "wechat-token");
         Object o = cacheUtil.get("wechatuser:" + cookieValue);

+ 0 - 3
spring-wechars/src/main/resources/application.yml

@@ -53,7 +53,4 @@ basicinfo:
 logging:
   config: classpath:logback-spring.xml
 
-#登录拦截器设置放行路径,多个用,号隔开
-login-interceptor:
-  exclude-patterns: /**/weChar,/**/weChar/getCode,/**/index,/**/login,/**/*.html,/**/*.js,/**/*.css
 

+ 32 - 0
spring-wechars/src/test/java/com/xieh/AntPathTest.java

@@ -0,0 +1,32 @@
+package com.xieh;
+
+import cn.org.spring.wechar.WeCharApplication;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.util.AntPathMatcher;
+
+/**
+ * @author: 谢辉
+ * @date: 2021/5/12
+ * @email: xieh_mail@163.com
+ * @description:
+ * @modifiedBy:
+ * @version: 1.0
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes={WeCharApplication.class})// 指定启动类
+public class AntPathTest {
+
+
+
+
+    @Test
+    public void test(){
+        String uri = "/v1/k/getCode";
+        AntPathMatcher antPathMatcher = new AntPathMatcher();
+        boolean match = antPathMatcher.match("/getCode", uri);
+        System.out.println(match);
+    }
+}