From f709a9efef6e82ec480ab4230142670b6d2f9719 Mon Sep 17 00:00:00 2001 From: Josh Cummings <3627351+jzheaux@users.noreply.github.com> Date: Wed, 2 Jul 2025 14:06:12 -0600 Subject: [PATCH] Add pathPattern Factory Methods Closes gh-17476 --- etc/checkstyle/checkstyle.xml | 1 + .../matcher/PathPatternRequestMatcher.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/etc/checkstyle/checkstyle.xml b/etc/checkstyle/checkstyle.xml index 04453420b3..8963755388 100644 --- a/etc/checkstyle/checkstyle.xml +++ b/etc/checkstyle/checkstyle.xml @@ -20,6 +20,7 @@ + diff --git a/web/src/main/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcher.java b/web/src/main/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcher.java index 1abe7d94c9..17faf11432 100644 --- a/web/src/main/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcher.java @@ -70,6 +70,40 @@ public final class PathPatternRequestMatcher implements RequestMatcher { this.pattern = pattern; } + /** + * Construct a {@link PathPatternRequestMatcher} using the {@link PathPatternParser} + * defaults. + *

+ * 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. + *

+ * 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. * @return a {@link Builder} that treats URIs as relative to the context path, if any