MCPcopy Create free account
hub / github.com/diyhi/bbs / MyAntPathRequestMatcher

Class MyAntPathRequestMatcher

src/main/java/cms/security/MyAntPathRequestMatcher.java:51–244  ·  view source on GitHub ↗

ant 风格的路径匹配 Matcher which compares a pre-defined ant-style pattern against the URL (servletPath + pathInfo) of an HttpServletRequest. The query string of the URL is ignored and matching is case-insensitive or case-sensitive depending on the arguments passed into the constructor.

Source from the content-addressed store, hash-verified

49 * @see org.springframework.util.AntPathMatcher
50 */
51public final class MyAntPathRequestMatcher implements RequestMatcher {
52 private static final Logger logger = LogManager.getLogger(MyAntPathRequestMatcher.class);
53 private static final String MATCH_ALL = "/**";
54
55 private final Matcher matcher;
56 private final String pattern;
57 private final HttpMethod httpMethod;
58 private final boolean caseSensitive;
59 private final PathMatcher pathMatcher = new AntPathMatcher();
60 /**
61 * Creates a matcher with the specific pattern which will match all HTTP
62 * methods in a case insensitive manner.
63 *
64 * @param pattern
65 * the ant pattern to use for matching
66 */
67 public MyAntPathRequestMatcher(String pattern) {
68 this(pattern, null);
69 }
70
71 /**
72 * Creates a matcher with the supplied pattern and HTTP method in a case
73 * insensitive manner.
74 *
75 * @param pattern
76 * the ant pattern to use for matching
77 * @param httpMethod
78 * the HTTP method. The {@code matches} method will return false
79 * if the incoming request doesn't have the same method.
80 */
81 public MyAntPathRequestMatcher(String pattern, String httpMethod) {
82 this(pattern,httpMethod,false);
83 }
84
85 /**
86 * Creates a matcher with the supplied pattern which will match the
87 * specified Http method
88 *
89 * @param pattern 模式
90 * the ant pattern to use for matching
91 * @param httpMethod HTTP方法
92 * the HTTP method. The {@code matches} method will return false
93 * if the incoming request doesn't doesn't have the same method.
94 * @param caseSensitive 区分大小写
95 * true if the matcher should consider case, else false
96 */
97 public MyAntPathRequestMatcher(String pattern, String httpMethod, boolean caseSensitive) {
98 Assert.hasText(pattern, "Pattern cannot be null or empty");
99 this.caseSensitive = caseSensitive;
100
101 if (pattern.equals(MATCH_ALL) || pattern.equals("**")) {
102 pattern = MATCH_ALL;
103 matcher = null;
104 } else {
105 if(!caseSensitive) {
106 pattern = pattern.toLowerCase();
107 }
108

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…