-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Support Authorities Without Role Prefix in RoleHierarchyImpl
Builder
#15272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2016 the original author or authors. | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -28,6 +28,7 @@ | |
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
import static org.springframework.security.access.hierarchicalroles.HierarchicalRolesTestHelper.assertHierarchy; | ||
|
||
/** | ||
* Tests for {@link RoleHierarchyImpl}. | ||
|
@@ -249,29 +250,34 @@ public void testBuilderWithDefaultRolePrefix() { | |
.implies("B") | ||
.role("B") | ||
.implies("C", "D") | ||
.authority("C") | ||
.implies("E", "F", "B") | ||
.build(); | ||
List<GrantedAuthority> flatAuthorities = AuthorityUtils.createAuthorityList("ROLE_A"); | ||
List<GrantedAuthority> allAuthorities = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B", "ROLE_C", | ||
"ROLE_D"); | ||
|
||
assertThat(roleHierarchyImpl).isNotNull(); | ||
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)) | ||
.containsExactlyInAnyOrderElementsOf(allAuthorities); | ||
assertHierarchy(roleHierarchyImpl).givesToAuthorities("ROLE_A") | ||
.theseAuthorities("ROLE_A", "ROLE_B", "ROLE_C", "ROLE_D"); | ||
|
||
assertHierarchy(roleHierarchyImpl).givesToAuthorities("C") | ||
.theseAuthorities("C", "ROLE_B", "ROLE_C", "ROLE_D", "ROLE_E", "ROLE_F"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of now, using I'm thinking that when using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mindset when writing this was that
So from your example assuming the 'user:...' are externally provided authorities I see this as a possible way of doing this:
This would make all members of "Team XYZ" have the roles USER_READ, USER_WRITE and USER_DELETE. Primary question: Does this reasoning make sense? It is correct? The way I normally structure this is that in an application I define roles being groups of users with the same set of tasks like "Administrator", "Manager", "User", etc. Those are then assigned to the user in an external IGA/IAM system (often based on department/job title/...). Then via the authentication of the specific user; the application receives one or more of these "external roles" as the authorities via the authentication. From there my application has something like this
As said; I you want I'm willing to make a first draft on documenting this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to be able to imply an authority then something like this is needed: A separate function is needed because there is no way to make any distinction between Also
|
||
} | ||
|
||
@Test | ||
public void testBuilderWithRolePrefix() { | ||
RoleHierarchyImpl roleHierarchyImpl = RoleHierarchyImpl.withRolePrefix("CUSTOM_PREFIX_") | ||
.role("A") | ||
.implies("B") | ||
.role("B") | ||
.implies("C", "D") | ||
.authority("C") | ||
.implies("E", "F", "B") | ||
.build(); | ||
List<GrantedAuthority> flatAuthorities = AuthorityUtils.createAuthorityList("CUSTOM_PREFIX_A"); | ||
List<GrantedAuthority> allAuthorities = AuthorityUtils.createAuthorityList("CUSTOM_PREFIX_A", | ||
"CUSTOM_PREFIX_B"); | ||
|
||
assertThat(roleHierarchyImpl).isNotNull(); | ||
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)) | ||
.containsExactlyInAnyOrderElementsOf(allAuthorities); | ||
assertHierarchy(roleHierarchyImpl).givesToAuthorities("CUSTOM_PREFIX_A") | ||
.theseAuthorities("CUSTOM_PREFIX_A", "CUSTOM_PREFIX_B", "CUSTOM_PREFIX_C", "CUSTOM_PREFIX_D"); | ||
|
||
assertHierarchy(roleHierarchyImpl).givesToAuthorities("C") | ||
.theseAuthorities("C", "CUSTOM_PREFIX_B", "CUSTOM_PREFIX_C", "CUSTOM_PREFIX_D", "CUSTOM_PREFIX_E", | ||
"CUSTOM_PREFIX_F"); | ||
} | ||
|
||
@Test | ||
|
Uh oh!
There was an error while loading. Please reload this page.