Skip to content

Commit ddf6882

Browse files
fhanikjzheaux
authored andcommitted
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]
1 parent 496579d commit ddf6882

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

web/src/main/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSource.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource;
3434
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
3535
import org.springframework.security.web.util.matcher.RequestMatcher;
36-
import org.springframework.security.web.util.matcher.RequestVariablesExtractor;
3736
import org.springframework.util.Assert;
3837

3938
/**
@@ -92,13 +91,8 @@ private static LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> proces
9291
return requestToExpressionAttributesMap;
9392
}
9493

95-
private static AbstractVariableEvaluationContextPostProcessor createPostProcessor(
96-
Object request) {
97-
if (request instanceof RequestVariablesExtractor) {
98-
return new RequestVariablesExtractorEvaluationContextPostProcessor(
99-
(RequestVariablesExtractor) request);
100-
}
101-
return null;
94+
private static AbstractVariableEvaluationContextPostProcessor createPostProcessor(RequestMatcher request) {
95+
return new RequestVariablesExtractorEvaluationContextPostProcessor(request);
10296
}
10397

10498
static class AntPathMatcherEvaluationContextPostProcessor
@@ -118,16 +112,16 @@ Map<String, String> extractVariables(HttpServletRequest request) {
118112

119113
static class RequestVariablesExtractorEvaluationContextPostProcessor
120114
extends AbstractVariableEvaluationContextPostProcessor {
121-
private final RequestVariablesExtractor matcher;
115+
private final RequestMatcher matcher;
122116

123117
public RequestVariablesExtractorEvaluationContextPostProcessor(
124-
RequestVariablesExtractor matcher) {
118+
RequestMatcher matcher) {
125119
this.matcher = matcher;
126120
}
127121

128122
@Override
129123
Map<String, String> extractVariables(HttpServletRequest request) {
130-
return this.matcher.extractUriTemplateVariables(request);
124+
return this.matcher.matcher(request).getVariables();
131125
}
132126
}
133127

web/src/main/java/org/springframework/security/web/servlet/util/matcher/MvcRequestMatcher.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private MatchableHandlerMapping getMapping(HttpServletRequest request) {
9292
* extractUriTemplateVariables(javax.servlet.http.HttpServletRequest)
9393
*/
9494
@Override
95+
@Deprecated
9596
public Map<String, String> extractUriTemplateVariables(HttpServletRequest request) {
9697
return matcher(request).getVariables();
9798
}
@@ -146,7 +147,7 @@ public String toString() {
146147
return sb.toString();
147148
}
148149

149-
private class DefaultMatcher implements RequestMatcher, RequestVariablesExtractor {
150+
private class DefaultMatcher implements RequestMatcher {
150151

151152
private final UrlPathHelper pathHelper = new UrlPathHelper();
152153

@@ -162,12 +163,6 @@ private boolean matches(String lookupPath) {
162163
return this.pathMatcher.match(MvcRequestMatcher.this.pattern, lookupPath);
163164
}
164165

165-
@Override
166-
public Map<String, String> extractUriTemplateVariables(
167-
HttpServletRequest request) {
168-
return matcher(request).getVariables();
169-
}
170-
171166
@Override
172167
public MatchResult matcher(HttpServletRequest request) {
173168
String lookupPath = this.pathHelper.getLookupPathForRequest(request);

web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public boolean matches(HttpServletRequest request) {
182182
}
183183

184184
@Override
185+
@Deprecated
185186
public Map<String, String> extractUriTemplateVariables(HttpServletRequest request) {
186187
return matcher(request).getVariables();
187188
}
@@ -264,7 +265,7 @@ private static HttpMethod valueOf(String method) {
264265
return null;
265266
}
266267

267-
private static interface Matcher {
268+
private interface Matcher {
268269
boolean matches(String path);
269270

270271
Map<String, String> extractUriTemplateVariables(String path);

web/src/main/java/org/springframework/security/web/util/matcher/RequestVariablesExtractor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author Rob Winch
2727
* @since 4.1.1
28-
* @deprecated
28+
* @deprecated use {@link RequestMatcher.MatchResult} from {@link RequestMatcher#matcher(HttpServletRequest)}
2929
*/
3030
public interface RequestVariablesExtractor {
3131

0 commit comments

Comments
 (0)