Skip to content

Commit

Permalink
Handle Empty Role
Browse files Browse the repository at this point in the history
Closes gh-13079
  • Loading branch information
jzheaux committed Apr 24, 2023
1 parent e3cc8d1 commit 73a543d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static String[] toNamedRolesArray(String rolePrefix, String[] roles) {
String[] result = new String[roles.length];
for (int i = 0; i < roles.length; 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
+ " is automatically prepended when using hasAnyRole. Consider using hasAnyAuthority instead.");
result[i] = rolePrefix + role;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,9 @@ public void hasRoleWhenRoleHierarchySetThenGreaterRoleTakesPrecedence() {
assertThat(manager.check(authentication, object).isGranted()).isTrue();
}

// gh-13079
@Test
void hasAnyRoleWhenEmptyRolePrefixThenNoException() {
AuthorityAuthorizationManager.hasAnyRole("", new String[] { "USER" });
}
}

0 comments on commit 73a543d

Please sign in to comment.