Add pathPattern Factory Methods

Closes gh-17476
This commit is contained in:
Josh Cummings 2025-07-02 14:06:12 -06:00
parent 98686a5139
commit f709a9efef
No known key found for this signature in database
GPG Key ID: 869B37A20E876129
2 changed files with 35 additions and 0 deletions

View File

@ -20,6 +20,7 @@
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.csrf.CsrfTokenAssert.*" /> <property name="avoidStaticImportExcludes" value="org.springframework.security.web.csrf.CsrfTokenAssert.*" />
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.servlet.TestMockHttpServletRequests.*" /> <property name="avoidStaticImportExcludes" value="org.springframework.security.web.servlet.TestMockHttpServletRequests.*" />
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.util.matcher.AntPathRequestMatcher.*" /> <property name="avoidStaticImportExcludes" value="org.springframework.security.web.util.matcher.AntPathRequestMatcher.*" />
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher.*" />
<property name="avoidStaticImportExcludes" value="org.springframework.security.web.util.matcher.RegexRequestMatcher.*" /> <property name="avoidStaticImportExcludes" value="org.springframework.security.web.util.matcher.RegexRequestMatcher.*" />
<property name="avoidStaticImportExcludes" value="org.springframework.core.annotation.MergedAnnotations.SearchStrategy.*" /> <property name="avoidStaticImportExcludes" value="org.springframework.core.annotation.MergedAnnotations.SearchStrategy.*" />
<property name="avoidStaticImportExcludes" value="org.assertj.core.api.InstanceOfAssertFactories.*"/> <property name="avoidStaticImportExcludes" value="org.assertj.core.api.InstanceOfAssertFactories.*"/>

View File

@ -70,6 +70,40 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
this.pattern = pattern; this.pattern = pattern;
} }
/**
* Construct a {@link PathPatternRequestMatcher} using the {@link PathPatternParser}
* defaults.
* <p>
* If you are configuring a custom {@link PathPatternParser}, please use
* {@link #withPathPatternParser} instead.
* @param pattern the URI pattern to match
* @return a {@link PathPatternRequestMatcher} that matches requests to the given
* {@code pattern}
* @since 7.0
* @see PathPattern
*/
public static PathPatternRequestMatcher pathPattern(String pattern) {
return pathPattern(null, pattern);
}
/**
* Construct a {@link PathPatternRequestMatcher} using the {@link PathPatternParser}
* defaults.
* <p>
* If you are configuring a custom {@link PathPatternParser}, please use
* {@link #withPathPatternParser} instead.
* @param method the HTTP method to match, {@code null} indicates that the method does
* not matter
* @param pattern the URI pattern to match
* @return a {@link PathPatternRequestMatcher} that matches requests to the given
* {@code pattern} and {@code method}
* @since 7.0
* @see PathPattern
*/
public static PathPatternRequestMatcher pathPattern(@Nullable HttpMethod method, String pattern) {
return withDefaults().matcher(method, pattern);
}
/** /**
* Use {@link PathPatternParser#defaultInstance} to parse path patterns. * Use {@link PathPatternParser#defaultInstance} to parse path patterns.
* @return a {@link Builder} that treats URIs as relative to the context path, if any * @return a {@link Builder} that treats URIs as relative to the context path, if any