From ddf68821cbd459452b267c4d2521e0e48854bb0b Mon Sep 17 00:00:00 2001 From: Filip Hanik Date: Thu, 1 Aug 2019 10:52:02 -0700 Subject: [PATCH] Add RequestMatcher.matcher(HttpServletRequest) Step 3 - Usage of RequestVariablesExtractor or types that are assigned to AntPathRequestMatcher should be replaced with the new method. [closes #7148] --- ...edFilterInvocationSecurityMetadataSource.java | 16 +++++----------- .../servlet/util/matcher/MvcRequestMatcher.java | 9 ++------- .../web/util/matcher/AntPathRequestMatcher.java | 3 ++- .../util/matcher/RequestVariablesExtractor.java | 2 +- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSource.java b/web/src/main/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSource.java index da0f3e35f7..02b2183d12 100644 --- a/web/src/main/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSource.java +++ b/web/src/main/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSource.java @@ -33,7 +33,6 @@ import org.springframework.security.web.FilterInvocation; import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; -import org.springframework.security.web.util.matcher.RequestVariablesExtractor; import org.springframework.util.Assert; /** @@ -92,13 +91,8 @@ public final class ExpressionBasedFilterInvocationSecurityMetadataSource return requestToExpressionAttributesMap; } - private static AbstractVariableEvaluationContextPostProcessor createPostProcessor( - Object request) { - if (request instanceof RequestVariablesExtractor) { - return new RequestVariablesExtractorEvaluationContextPostProcessor( - (RequestVariablesExtractor) request); - } - return null; + private static AbstractVariableEvaluationContextPostProcessor createPostProcessor(RequestMatcher request) { + return new RequestVariablesExtractorEvaluationContextPostProcessor(request); } static class AntPathMatcherEvaluationContextPostProcessor @@ -118,16 +112,16 @@ public final class ExpressionBasedFilterInvocationSecurityMetadataSource static class RequestVariablesExtractorEvaluationContextPostProcessor extends AbstractVariableEvaluationContextPostProcessor { - private final RequestVariablesExtractor matcher; + private final RequestMatcher matcher; public RequestVariablesExtractorEvaluationContextPostProcessor( - RequestVariablesExtractor matcher) { + RequestMatcher matcher) { this.matcher = matcher; } @Override Map extractVariables(HttpServletRequest request) { - return this.matcher.extractUriTemplateVariables(request); + return this.matcher.matcher(request).getVariables(); } } diff --git a/web/src/main/java/org/springframework/security/web/servlet/util/matcher/MvcRequestMatcher.java b/web/src/main/java/org/springframework/security/web/servlet/util/matcher/MvcRequestMatcher.java index 168a77c681..7a667df589 100644 --- a/web/src/main/java/org/springframework/security/web/servlet/util/matcher/MvcRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/servlet/util/matcher/MvcRequestMatcher.java @@ -92,6 +92,7 @@ public class MvcRequestMatcher implements RequestMatcher, RequestVariablesExtrac * extractUriTemplateVariables(javax.servlet.http.HttpServletRequest) */ @Override + @Deprecated public Map extractUriTemplateVariables(HttpServletRequest request) { return matcher(request).getVariables(); } @@ -146,7 +147,7 @@ public class MvcRequestMatcher implements RequestMatcher, RequestVariablesExtrac return sb.toString(); } - private class DefaultMatcher implements RequestMatcher, RequestVariablesExtractor { + private class DefaultMatcher implements RequestMatcher { private final UrlPathHelper pathHelper = new UrlPathHelper(); @@ -162,12 +163,6 @@ public class MvcRequestMatcher implements RequestMatcher, RequestVariablesExtrac return this.pathMatcher.match(MvcRequestMatcher.this.pattern, lookupPath); } - @Override - public Map extractUriTemplateVariables( - HttpServletRequest request) { - return matcher(request).getVariables(); - } - @Override public MatchResult matcher(HttpServletRequest request) { String lookupPath = this.pathHelper.getLookupPathForRequest(request); diff --git a/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java index 7861e983ef..b77be2390b 100644 --- a/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java @@ -182,6 +182,7 @@ public final class AntPathRequestMatcher } @Override + @Deprecated public Map extractUriTemplateVariables(HttpServletRequest request) { return matcher(request).getVariables(); } @@ -264,7 +265,7 @@ public final class AntPathRequestMatcher return null; } - private static interface Matcher { + private interface Matcher { boolean matches(String path); Map extractUriTemplateVariables(String path); diff --git a/web/src/main/java/org/springframework/security/web/util/matcher/RequestVariablesExtractor.java b/web/src/main/java/org/springframework/security/web/util/matcher/RequestVariablesExtractor.java index c3444d0e70..db26547e0d 100644 --- a/web/src/main/java/org/springframework/security/web/util/matcher/RequestVariablesExtractor.java +++ b/web/src/main/java/org/springframework/security/web/util/matcher/RequestVariablesExtractor.java @@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletRequest; * * @author Rob Winch * @since 4.1.1 - * @deprecated + * @deprecated use {@link RequestMatcher.MatchResult} from {@link RequestMatcher#matcher(HttpServletRequest)} */ public interface RequestVariablesExtractor {