From ea3ba62022120cb18f21af441c78e9095458dc03 Mon Sep 17 00:00:00 2001 From: Josh Cummings <3627351+jzheaux@users.noreply.github.com> Date: Mon, 7 Jul 2025 11:27:39 -0600 Subject: [PATCH] Correct Servlet Path JavaDoc Initially PathPatternRequestMatcher was designed to match relative to the servlet path. However, this was changed to be relative to the context path. This commit updates the documentation and removes references to the servlet path other than in the context of setting a basePath to remove boilerplate. Issue gh-16430 --- .../matcher/PathPatternRequestMatcher.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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..81ee5976b2 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 @@ -38,8 +38,8 @@ import org.springframework.web.util.pattern.PathPatternParser; * (that is, it should exclude any context path). * *
- * You can provide the servlet path in {@link PathPatternRequestMatcher#servletPath} and - * reuse for multiple matchers. + * You can provide the servlet path in {@link PathPatternRequestMatcher.Builder#basePath} + * and reuse for multiple matchers. * *
* Note that the {@link org.springframework.web.servlet.HandlerMapping} that contains the @@ -55,14 +55,12 @@ public final class PathPatternRequestMatcher implements RequestMatcher { private final PathPattern pattern; - private RequestMatcher servletPath = AnyRequestMatcher.INSTANCE; - private RequestMatcher method = AnyRequestMatcher.INSTANCE; /** * Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}. *
- * The {@code pattern} should be relative to the servlet path + * The {@code pattern} should be relative to the context path *
* @param pattern the pattern used to match */ @@ -102,9 +100,6 @@ public final class PathPatternRequestMatcher implements RequestMatcher { */ @Override public MatchResult matcher(HttpServletRequest request) { - if (!this.servletPath.matches(request)) { - return MatchResult.notMatch(); - } if (!this.method.matches(request)) { return MatchResult.notMatch(); } @@ -232,8 +227,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher { * also be followed by {@code /**} to signify all URIs under a given path. * *- * These must be specified relative to any servlet path prefix (meaning you should - * exclude the context path and any servlet path prefix in stating your pattern). + * These must be specified relative to any context path prefix. A + * {@link #basePath} may be specified to reuse a common prefix, for example a + * servlet path. * *
* The following are valid patterns and their meaning @@ -266,8 +262,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher { * also be followed by {@code /**} to signify all URIs under a given path. * *
- * These must be specified relative to any servlet path prefix (meaning you should - * exclude the context path and any servlet path prefix in stating your pattern). + * These must be specified relative to any context path prefix. A + * {@link #basePath} may be specified to reuse a common prefix, for example a + * servlet path. * *
* The following are valid patterns and their meaning