Skip to content

Commit f709a9e

Browse files
committed
Add pathPattern Factory Methods
Closes gh-17476
1 parent 98686a5 commit f709a9e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

etc/checkstyle/checkstyle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.csrf.CsrfTokenAssert.*" />
2121
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.servlet.TestMockHttpServletRequests.*" />
2222
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.util.matcher.AntPathRequestMatcher.*" />
23+
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher.*" />
2324
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.util.matcher.RegexRequestMatcher.*" />
2425
<property name="avoidStaticImportExcludes" value="org.springframework.core.annotation.MergedAnnotations.SearchStrategy.*" />
2526
<property name="avoidStaticImportExcludes" value="org.assertj.core.api.InstanceOfAssertFactories.*"/>

web/src/main/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcher.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,40 @@ private PathPatternRequestMatcher(PathPattern pattern) {
7070
this.pattern = pattern;
7171
}
7272

73+
/**
74+
* Construct a {@link PathPatternRequestMatcher} using the {@link PathPatternParser}
75+
* defaults.
76+
* <p>
77+
* If you are configuring a custom {@link PathPatternParser}, please use
78+
* {@link #withPathPatternParser} instead.
79+
* @param pattern the URI pattern to match
80+
* @return a {@link PathPatternRequestMatcher} that matches requests to the given
81+
* {@code pattern}
82+
* @since 7.0
83+
* @see PathPattern
84+
*/
85+
public static PathPatternRequestMatcher pathPattern(String pattern) {
86+
return pathPattern(null, pattern);
87+
}
88+
89+
/**
90+
* Construct a {@link PathPatternRequestMatcher} using the {@link PathPatternParser}
91+
* defaults.
92+
* <p>
93+
* If you are configuring a custom {@link PathPatternParser}, please use
94+
* {@link #withPathPatternParser} instead.
95+
* @param method the HTTP method to match, {@code null} indicates that the method does
96+
* not matter
97+
* @param pattern the URI pattern to match
98+
* @return a {@link PathPatternRequestMatcher} that matches requests to the given
99+
* {@code pattern} and {@code method}
100+
* @since 7.0
101+
* @see PathPattern
102+
*/
103+
public static PathPatternRequestMatcher pathPattern(@Nullable HttpMethod method, String pattern) {
104+
return withDefaults().matcher(method, pattern);
105+
}
106+
73107
/**
74108
* Use {@link PathPatternParser#defaultInstance} to parse path patterns.
75109
* @return a {@link Builder} that treats URIs as relative to the context path, if any

0 commit comments

Comments
 (0)