Skip to content

Commit bce8049

Browse files
committed
Web uses AuthorizationManager<? super RequestAuthorizationContext>
This allows AuthorizationManager<Object> to be used instead of just AuthorizationManager<RequestAuthorizationContext>. In addition, the code was updated to use `AuthorizationManagerFactory<? super RequestAuthorizationContext>` Closes gh-17931
1 parent 675835e commit bce8049

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/AuthorizeHttpRequestsConfigurer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder
6060

6161
private final AuthorizationEventPublisher publisher;
6262

63-
private final AuthorizationManagerFactory<RequestAuthorizationContext> authorizationManagerFactory;
63+
private final AuthorizationManagerFactory<? super RequestAuthorizationContext> authorizationManagerFactory;
6464

6565
private ObjectPostProcessor<AuthorizationManager<HttpServletRequest>> postProcessor = ObjectPostProcessor
6666
.identity();
@@ -85,7 +85,7 @@ public AuthorizeHttpRequestsConfigurer(ApplicationContext context) {
8585
provider.ifUnique((postProcessor) -> this.postProcessor = postProcessor);
8686
}
8787

88-
private AuthorizationManagerFactory<RequestAuthorizationContext> getAuthorizationManagerFactory(
88+
private AuthorizationManagerFactory<? super RequestAuthorizationContext> getAuthorizationManagerFactory(
8989
ApplicationContext context) {
9090
ResolvableType authorizationManagerFactoryType = ResolvableType
9191
.forClassWithGenerics(AuthorizationManagerFactory.class, RequestAuthorizationContext.class);
@@ -134,7 +134,7 @@ public void configure(H http) {
134134
}
135135

136136
private AuthorizationManagerRequestMatcherRegistry addMapping(List<? extends RequestMatcher> matchers,
137-
AuthorizationManager<RequestAuthorizationContext> manager) {
137+
AuthorizationManager<? super RequestAuthorizationContext> manager) {
138138
for (RequestMatcher matcher : matchers) {
139139
this.registry.addMapping(matcher, manager);
140140
}
@@ -166,13 +166,15 @@ private AuthorizationManagerRequestMatcherRegistry(ApplicationContext context) {
166166
setApplicationContext(context);
167167
}
168168

169-
private void addMapping(RequestMatcher matcher, AuthorizationManager<RequestAuthorizationContext> manager) {
169+
private void addMapping(RequestMatcher matcher,
170+
AuthorizationManager<? super RequestAuthorizationContext> manager) {
170171
this.unmappedMatchers = null;
171172
this.managerBuilder.add(matcher, manager);
172173
this.mappingCount++;
173174
}
174175

175-
private void addFirst(RequestMatcher matcher, AuthorizationManager<RequestAuthorizationContext> manager) {
176+
private void addFirst(RequestMatcher matcher,
177+
AuthorizationManager<? super RequestAuthorizationContext> manager) {
176178
this.unmappedMatchers = null;
177179
this.managerBuilder.mappings((m) -> m.add(0, new RequestMatcherEntry<>(matcher, manager)));
178180
this.mappingCount++;
@@ -220,7 +222,7 @@ public class AuthorizedUrl {
220222

221223
private final List<? extends RequestMatcher> matchers;
222224

223-
private AuthorizationManagerFactory<RequestAuthorizationContext> authorizationManagerFactory;
225+
private AuthorizationManagerFactory<? super RequestAuthorizationContext> authorizationManagerFactory;
224226

225227
private boolean not;
226228

@@ -231,7 +233,7 @@ public class AuthorizedUrl {
231233
* creating instances of {@link AuthorizationManager}
232234
*/
233235
AuthorizedUrl(List<? extends RequestMatcher> matchers,
234-
AuthorizationManagerFactory<RequestAuthorizationContext> authorizationManagerFactory) {
236+
AuthorizationManagerFactory<? super RequestAuthorizationContext> authorizationManagerFactory) {
235237
this.matchers = matchers;
236238
this.authorizationManagerFactory = authorizationManagerFactory;
237239
}
@@ -241,7 +243,7 @@ protected List<? extends RequestMatcher> getMatchers() {
241243
}
242244

243245
void setAuthorizationManagerFactory(
244-
AuthorizationManagerFactory<RequestAuthorizationContext> authorizationManagerFactory) {
246+
AuthorizationManagerFactory<? super RequestAuthorizationContext> authorizationManagerFactory) {
245247
this.authorizationManagerFactory = authorizationManagerFactory;
246248
}
247249

@@ -403,7 +405,7 @@ public AuthorizedUrlVariable hasVariable(String variable) {
403405
* customizations
404406
*/
405407
public AuthorizationManagerRequestMatcherRegistry access(
406-
AuthorizationManager<RequestAuthorizationContext> manager) {
408+
AuthorizationManager<? super RequestAuthorizationContext> manager) {
407409
Assert.notNull(manager, "manager cannot be null");
408410
return (this.not)
409411
? AuthorizeHttpRequestsConfigurer.this.addMapping(this.matchers, AuthorizationManagers.not(manager))

web/src/main/java/org/springframework/security/web/access/intercept/RequestMatcherDelegatingAuthorizationManager.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho
5555

5656
private final Log logger = LogFactory.getLog(getClass());
5757

58-
private final List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings;
58+
private final List<RequestMatcherEntry<AuthorizationManager<? super RequestAuthorizationContext>>> mappings;
5959

6060
private RequestMatcherDelegatingAuthorizationManager(
61-
List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings) {
61+
List<RequestMatcherEntry<AuthorizationManager<? super RequestAuthorizationContext>>> mappings) {
6262
Assert.notEmpty(mappings, "mappings cannot be empty");
6363
this.mappings = mappings;
6464
}
@@ -69,12 +69,12 @@ private RequestMatcherDelegatingAuthorizationManager(
6969
if (this.logger.isTraceEnabled()) {
7070
this.logger.trace(LogMessage.format("Authorizing %s", requestLine(request)));
7171
}
72-
for (RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>> mapping : this.mappings) {
72+
for (RequestMatcherEntry<AuthorizationManager<? super RequestAuthorizationContext>> mapping : this.mappings) {
7373

7474
RequestMatcher matcher = mapping.getRequestMatcher();
7575
MatchResult matchResult = matcher.matcher(request);
7676
if (matchResult.isMatch()) {
77-
AuthorizationManager<RequestAuthorizationContext> manager = mapping.getEntry();
77+
AuthorizationManager<? super RequestAuthorizationContext> manager = mapping.getEntry();
7878
if (this.logger.isTraceEnabled()) {
7979
this.logger.trace(
8080
LogMessage.format("Checking authorization on %s using %s", requestLine(request), manager));
@@ -108,15 +108,15 @@ public static final class Builder {
108108

109109
private boolean anyRequestConfigured;
110110

111-
private final List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings = new ArrayList<>();
111+
private final List<RequestMatcherEntry<AuthorizationManager<? super RequestAuthorizationContext>>> mappings = new ArrayList<>();
112112

113113
/**
114114
* Maps a {@link RequestMatcher} to an {@link AuthorizationManager}.
115115
* @param matcher the {@link RequestMatcher} to use
116116
* @param manager the {@link AuthorizationManager} to use
117117
* @return the {@link Builder} for further customizations
118118
*/
119-
public Builder add(RequestMatcher matcher, AuthorizationManager<RequestAuthorizationContext> manager) {
119+
public Builder add(RequestMatcher matcher, AuthorizationManager<? super RequestAuthorizationContext> manager) {
120120
Assert.state(!this.anyRequestConfigured, "Can't add mappings after anyRequest");
121121
Assert.notNull(matcher, "matcher cannot be null");
122122
Assert.notNull(manager, "manager cannot be null");
@@ -133,7 +133,7 @@ public Builder add(RequestMatcher matcher, AuthorizationManager<RequestAuthoriza
133133
* @since 5.7
134134
*/
135135
public Builder mappings(
136-
Consumer<List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>>> mappingsConsumer) {
136+
Consumer<List<RequestMatcherEntry<AuthorizationManager<? super RequestAuthorizationContext>>>> mappingsConsumer) {
137137
Assert.state(!this.anyRequestConfigured, "Can't configure mappings after anyRequest");
138138
Assert.notNull(mappingsConsumer, "mappingsConsumer cannot be null");
139139
mappingsConsumer.accept(this.mappings);

0 commit comments

Comments
 (0)