Add hasAnyAuthority() and hasAnyRole() in AuthorizeExchangeSpec
Fixes gh-6306
This commit is contained in:
committed by
Rob Winch
parent
a919b4e916
commit
e60ae4984a
+47
-1
@@ -105,7 +105,7 @@ public class AuthorityReactiveAuthorizationManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenHasRoleAndNotAuthorizedThenReturnTrue() {
|
||||
public void checkWhenHasRoleAndNotAuthorizedThenReturnFalse() {
|
||||
manager = AuthorityReactiveAuthorizationManager.hasRole("ADMIN");
|
||||
authentication = new TestingAuthenticationToken("rob", "secret", "ADMIN");
|
||||
|
||||
@@ -114,6 +114,26 @@ public class AuthorityReactiveAuthorizationManagerTests {
|
||||
assertThat(granted).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenHasAnyRoleAndAuthorizedThenReturnTrue() {
|
||||
manager = AuthorityReactiveAuthorizationManager.hasAnyRole("GENERAL", "USER", "TEST");
|
||||
authentication = new TestingAuthenticationToken("rob", "secret", "ROLE_USER", "ROLE_AUDITING", "ROLE_ADMIN");
|
||||
|
||||
boolean granted = manager.check(Mono.just(authentication), null).block().isGranted();
|
||||
|
||||
assertThat(granted).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenHasAnyRoleAndNotAuthorizedThenReturnFalse() {
|
||||
manager = AuthorityReactiveAuthorizationManager.hasAnyRole("GENERAL", "USER", "TEST");
|
||||
authentication = new TestingAuthenticationToken("rob", "secret", "USER", "AUDITING", "ADMIN");
|
||||
|
||||
boolean granted = manager.check(Mono.just(authentication), null).block().isGranted();
|
||||
|
||||
assertThat(granted).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void hasRoleWhenNullThenException() {
|
||||
String role = null;
|
||||
@@ -125,4 +145,30 @@ public class AuthorityReactiveAuthorizationManagerTests {
|
||||
String authority = null;
|
||||
AuthorityReactiveAuthorizationManager.hasAuthority(authority);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void hasAnyRoleWhenNullThenException() {
|
||||
String role = null;
|
||||
AuthorityReactiveAuthorizationManager.hasAnyRole(role);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void hasAnyAuthorityWhenNullThenException() {
|
||||
String authority = null;
|
||||
AuthorityReactiveAuthorizationManager.hasAnyAuthority(authority);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void hasAnyRoleWhenOneIsNullThenException() {
|
||||
String role1 = "ROLE_ADMIN";
|
||||
String role2 = null;
|
||||
AuthorityReactiveAuthorizationManager.hasAnyRole(role1, role2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void hasAnyAuthorityWhenOneIsNullThenException() {
|
||||
String authority1 = "ADMIN";
|
||||
String authority2 = null;
|
||||
AuthorityReactiveAuthorizationManager.hasAnyAuthority(authority1, authority2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user