1
0
mirror of synced 2026-08-04 17:27:13 +00:00

Add hasAnyAuthority() and hasAnyRole() in AuthorizeExchangeSpec

Fixes gh-6306
This commit is contained in:
Robbie Martinus
2018-12-19 22:36:30 +11:00
committed by Rob Winch
parent a919b4e916
commit e60ae4984a
3 changed files with 114 additions and 7 deletions
@@ -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);
}
}