Browse Source

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]
Filip Hanik 6 năm trước cách đây
mục cha
commit
ddf68821cb

+ 5 - 11
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<String, String> extractVariables(HttpServletRequest request) {
-			return this.matcher.extractUriTemplateVariables(request);
+			return this.matcher.matcher(request).getVariables();
 		}
 	}
 

+ 2 - 7
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<String, String> 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<String, String> extractUriTemplateVariables(
-				HttpServletRequest request) {
-			return matcher(request).getVariables();
-		}
-
 		@Override
 		public MatchResult matcher(HttpServletRequest request) {
 			String lookupPath = this.pathHelper.getLookupPathForRequest(request);

+ 2 - 1
web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java

@@ -182,6 +182,7 @@ public final class AntPathRequestMatcher
 	}
 
 	@Override
+	@Deprecated
 	public Map<String, String> 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<String, String> extractUriTemplateVariables(String path);

+ 1 - 1
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 {