mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-01 09:42:13 +00:00
Handle Empty Role
Closes gh-13079
This commit is contained in:
parent
e3cc8d13e8
commit
73a543d318
@ -130,7 +130,7 @@ public final class AuthorityAuthorizationManager<T> implements AuthorizationMana
|
|||||||
String[] result = new String[roles.length];
|
String[] result = new String[roles.length];
|
||||||
for (int i = 0; i < roles.length; i++) {
|
for (int i = 0; i < roles.length; i++) {
|
||||||
String role = roles[i];
|
String role = roles[i];
|
||||||
Assert.isTrue(!role.startsWith(rolePrefix), () -> role + " should not start with " + rolePrefix + " since "
|
Assert.isTrue(rolePrefix.isEmpty() || !role.startsWith(rolePrefix), () -> role + " should not start with " + rolePrefix + " since "
|
||||||
+ rolePrefix
|
+ rolePrefix
|
||||||
+ " is automatically prepended when using hasAnyRole. Consider using hasAnyAuthority instead.");
|
+ " is automatically prepended when using hasAnyRole. Consider using hasAnyAuthority instead.");
|
||||||
result[i] = rolePrefix + role;
|
result[i] = rolePrefix + role;
|
||||||
|
@ -266,4 +266,9 @@ public class AuthorityAuthorizationManagerTests {
|
|||||||
assertThat(manager.check(authentication, object).isGranted()).isTrue();
|
assertThat(manager.check(authentication, object).isGranted()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-13079
|
||||||
|
@Test
|
||||||
|
void hasAnyRoleWhenEmptyRolePrefixThenNoException() {
|
||||||
|
AuthorityAuthorizationManager.hasAnyRole("", new String[] { "USER" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user