From 866ce5eaec8f88571e7201c3d0916e550e70abe4 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 10 Oct 2017 09:36:35 -0500 Subject: [PATCH] AuthorityAuthorizationManager->AuthorityReactiveAuthorizationManager Issue gh-4615 --- .../config/web/server/HttpSecurity.java | 6 +++--- ... AuthorityReactiveAuthorizationManager.java} | 10 +++++----- ...orityReactiveAuthorizationManagerTests.java} | 17 +++++++---------- ...gatingReactiveAuthorizationManagerTests.java | 8 +++----- 4 files changed, 18 insertions(+), 23 deletions(-) rename core/src/main/java/org/springframework/security/authorization/{AuthorityAuthorizationManager.java => AuthorityReactiveAuthorizationManager.java} (78%) rename core/src/test/java/org/springframework/security/authorization/{AuthorityAuthorizationManagerTests.java => AuthorityReactiveAuthorizationManagerTests.java} (85%) diff --git a/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java b/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java index 339e444b36..deb76a937b 100644 --- a/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java +++ b/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java @@ -21,7 +21,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.security.authentication.ReactiveAuthenticationManager; import org.springframework.security.authorization.AuthenticatedAuthorizationManager; -import org.springframework.security.authorization.AuthorityAuthorizationManager; +import org.springframework.security.authorization.AuthorityReactiveAuthorizationManager; import org.springframework.security.authorization.AuthorizationDecision; import org.springframework.security.authorization.ReactiveAuthorizationManager; import org.springframework.security.web.server.AuthenticationEntryPoint; @@ -293,11 +293,11 @@ public class HttpSecurity { } public AuthorizeExchangeBuilder hasRole(String role) { - return access(AuthorityAuthorizationManager.hasRole(role)); + return access(AuthorityReactiveAuthorizationManager.hasRole(role)); } public AuthorizeExchangeBuilder hasAuthority(String authority) { - return access(AuthorityAuthorizationManager.hasAuthority(authority)); + return access(AuthorityReactiveAuthorizationManager.hasAuthority(authority)); } public AuthorizeExchangeBuilder authenticated() { diff --git a/core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java b/core/src/main/java/org/springframework/security/authorization/AuthorityReactiveAuthorizationManager.java similarity index 78% rename from core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java rename to core/src/main/java/org/springframework/security/authorization/AuthorityReactiveAuthorizationManager.java index 912fbcfb80..8a07d40057 100644 --- a/core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java +++ b/core/src/main/java/org/springframework/security/authorization/AuthorityReactiveAuthorizationManager.java @@ -24,10 +24,10 @@ import reactor.core.publisher.Mono; * @author Rob Winch * @since 5.0 */ -public class AuthorityAuthorizationManager implements ReactiveAuthorizationManager { +public class AuthorityReactiveAuthorizationManager implements ReactiveAuthorizationManager { private final String authority; - private AuthorityAuthorizationManager(String authority) { + private AuthorityReactiveAuthorizationManager(String authority) { this.authority = authority; } @@ -42,12 +42,12 @@ public class AuthorityAuthorizationManager implements ReactiveAuthorizationMa .defaultIfEmpty(new AuthorizationDecision(false)); } - public static AuthorityAuthorizationManager hasAuthority(String authority) { + public static AuthorityReactiveAuthorizationManager hasAuthority(String authority) { Assert.notNull(authority, "authority cannot be null"); - return new AuthorityAuthorizationManager<>(authority); + return new AuthorityReactiveAuthorizationManager<>(authority); } - public static AuthorityAuthorizationManager hasRole(String role) { + public static AuthorityReactiveAuthorizationManager hasRole(String role) { Assert.notNull(role, "role cannot be null"); return hasAuthority("ROLE_" + role); } diff --git a/core/src/test/java/org/springframework/security/authorization/AuthorityAuthorizationManagerTests.java b/core/src/test/java/org/springframework/security/authorization/AuthorityReactiveAuthorizationManagerTests.java similarity index 85% rename from core/src/test/java/org/springframework/security/authorization/AuthorityAuthorizationManagerTests.java rename to core/src/test/java/org/springframework/security/authorization/AuthorityReactiveAuthorizationManagerTests.java index 4c2972be7a..406650f0b5 100644 --- a/core/src/test/java/org/springframework/security/authorization/AuthorityAuthorizationManagerTests.java +++ b/core/src/test/java/org/springframework/security/authorization/AuthorityReactiveAuthorizationManagerTests.java @@ -22,28 +22,25 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.AuthorityUtils; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.util.Collection; import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; -import static org.springframework.security.core.authority.AuthorityUtils.createAuthorityList; /** * @author Rob Winch * @since 5.0 */ @RunWith(MockitoJUnitRunner.class) -public class AuthorityAuthorizationManagerTests { +public class AuthorityReactiveAuthorizationManagerTests { @Mock Authentication authentication; - AuthorityAuthorizationManager manager = AuthorityAuthorizationManager.hasAuthority("ADMIN"); + AuthorityReactiveAuthorizationManager manager = AuthorityReactiveAuthorizationManager + .hasAuthority("ADMIN"); @Test public void checkWhenHasAuthorityAndNotAuthenticatedThenReturnFalse() { @@ -99,7 +96,7 @@ public class AuthorityAuthorizationManagerTests { @Test public void checkWhenHasRoleAndAuthorizedThenReturnTrue() { - manager = AuthorityAuthorizationManager.hasRole("ADMIN"); + manager = AuthorityReactiveAuthorizationManager.hasRole("ADMIN"); authentication = new TestingAuthenticationToken("rob", "secret", "ROLE_ADMIN"); boolean granted = manager.check(Mono.just(authentication), null).block().isGranted(); @@ -109,7 +106,7 @@ public class AuthorityAuthorizationManagerTests { @Test public void checkWhenHasRoleAndNotAuthorizedThenReturnTrue() { - manager = AuthorityAuthorizationManager.hasRole("ADMIN"); + manager = AuthorityReactiveAuthorizationManager.hasRole("ADMIN"); authentication = new TestingAuthenticationToken("rob", "secret", "ADMIN"); boolean granted = manager.check(Mono.just(authentication), null).block().isGranted(); @@ -120,12 +117,12 @@ public class AuthorityAuthorizationManagerTests { @Test(expected = IllegalArgumentException.class) public void hasRoleWhenNullThenException() { String role = null; - AuthorityAuthorizationManager.hasRole(role); + AuthorityReactiveAuthorizationManager.hasRole(role); } @Test(expected = IllegalArgumentException.class) public void hasAuthorityWhenNullThenException() { String authority = null; - AuthorityAuthorizationManager.hasAuthority(authority); + AuthorityReactiveAuthorizationManager.hasAuthority(authority); } } diff --git a/webflux/src/test/java/org/springframework/security/web/server/authorization/DelegatingReactiveAuthorizationManagerTests.java b/webflux/src/test/java/org/springframework/security/web/server/authorization/DelegatingReactiveAuthorizationManagerTests.java index 4c16447295..845c7ceaea 100644 --- a/webflux/src/test/java/org/springframework/security/web/server/authorization/DelegatingReactiveAuthorizationManagerTests.java +++ b/webflux/src/test/java/org/springframework/security/web/server/authorization/DelegatingReactiveAuthorizationManagerTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.security.authorization.AuthorityAuthorizationManager; +import org.springframework.security.authorization.AuthorityReactiveAuthorizationManager; import org.springframework.security.authorization.AuthorizationDecision; import org.springframework.security.core.Authentication; import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; @@ -45,10 +45,8 @@ public class DelegatingReactiveAuthorizationManagerTests { ServerWebExchangeMatcher match1; @Mock ServerWebExchangeMatcher match2; - @Mock - AuthorityAuthorizationManager delegate1; - @Mock - AuthorityAuthorizationManager delegate2; + @Mock AuthorityReactiveAuthorizationManager delegate1; + @Mock AuthorityReactiveAuthorizationManager delegate2; @Mock ServerWebExchange exchange; @Mock