Skip to content

Commit 185991a

Browse files
committed
Revert "Add default AuthorizationManager"
This reverts commit 4ddec07.
1 parent 440748e commit 185991a

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho
4949

5050
private final List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings;
5151

52-
private AuthorizationManager<RequestAuthorizationContext> defaultManager = (authentication, request) -> null;
53-
5452
private RequestMatcherDelegatingAuthorizationManager(
5553
List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings) {
5654
Assert.notEmpty(mappings, "mappings cannot be empty");
@@ -84,10 +82,8 @@ public AuthorizationDecision check(Supplier<Authentication> authentication, Http
8482
new RequestAuthorizationContext(request, matchResult.getVariables()));
8583
}
8684
}
87-
if (this.logger.isTraceEnabled()) {
88-
this.logger.trace(LogMessage.format("Checking authorization on %s using %s", request, this.defaultManager));
89-
}
90-
return this.defaultManager.check(authentication, new RequestAuthorizationContext(request));
85+
this.logger.trace("Abstaining since did not find matching RequestMatcher");
86+
return null;
9187
}
9288

9389
/**
@@ -98,21 +94,6 @@ public static Builder builder() {
9894
return new Builder();
9995
}
10096

101-
/**
102-
* Use this {@link AuthorizationManager} if the request fails to match any other
103-
* configured {@link AuthorizationManager}.
104-
*
105-
* <p>
106-
* This is specifically handy when considering whether to accept or deny requests by
107-
* default. The default is to abstain from deciding on requests that don't match
108-
* configuration.
109-
* @param authorizationManager the {@link AuthorizationManager} to use
110-
* @since 5.8
111-
*/
112-
public void setDefaultAuthorizationManager(AuthorizationManager<RequestAuthorizationContext> authorizationManager) {
113-
this.defaultManager = authorizationManager;
114-
}
115-
11697
/**
11798
* A builder for {@link RequestMatcherDelegatingAuthorizationManager}.
11899
*/

web/src/test/java/org/springframework/security/web/access/intercept/RequestMatcherDelegatingAuthorizationManagerTests.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
import org.springframework.security.authentication.TestingAuthenticationToken;
2525
import org.springframework.security.authorization.AuthorityAuthorizationManager;
2626
import org.springframework.security.authorization.AuthorizationDecision;
27-
import org.springframework.security.authorization.AuthorizationManager;
2827
import org.springframework.security.core.Authentication;
2928
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
3029
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
3130
import org.springframework.security.web.util.matcher.RequestMatcherEntry;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
3433
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
35-
import static org.mockito.ArgumentMatchers.any;
36-
import static org.mockito.BDDMockito.given;
37-
import static org.mockito.Mockito.mock;
38-
import static org.mockito.Mockito.verify;
3934

4035
/**
4136
* Tests for {@link RequestMatcherDelegatingAuthorizationManager}.
@@ -120,20 +115,6 @@ public void checkWhenMultipleMappingsConfiguredWithConsumerThenDelegatesMatching
120115
assertThat(unmapped.isGranted()).isFalse();
121116
}
122117

123-
@Test
124-
public void checkWhenNoMatchesThenUsesDefaultAuthorizationManager() {
125-
RequestMatcherDelegatingAuthorizationManager manager = RequestMatcherDelegatingAuthorizationManager.builder()
126-
.add((request) -> false, (authentication, context) -> new AuthorizationDecision(false)).build();
127-
AuthorizationManager<RequestAuthorizationContext> defaultManager = mock(AuthorizationManager.class);
128-
given(defaultManager.check(any(), any())).willReturn(new AuthorizationDecision(true));
129-
manager.setDefaultAuthorizationManager(defaultManager);
130-
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password");
131-
AuthorizationDecision decision = manager.check(authentication, new MockHttpServletRequest(null, "/endpoint"));
132-
assertThat(decision).isNotNull();
133-
assertThat(decision.isGranted()).isTrue();
134-
verify(defaultManager).check(any(), any());
135-
}
136-
137118
@Test
138119
public void addWhenMappingsConsumerNullThenException() {
139120
assertThatIllegalArgumentException()

0 commit comments

Comments
 (0)