I don't know if you meant the ROLE separator as whitespace>whitespace ( String[] roles = line.trim().split("\\s+>\\s+"); ), but this confuses developers.
**lines of RoleHierarchyImpl.java **
private void buildRolesReachableInOneStepMap() {
this.rolesReachableInOneStepMap = new HashMap<>();
for (String line : this.roleHierarchyStringRepresentation.split("\n")) {
// Split on > and trim excessive whitespace
String[] roles = line.trim().split("\\s+>\\s+"); // -> this regex is right?
for (int i = 1; i < roles.length; i++) {
String higherRole = roles[i - 1];
GrantedAuthority lowerRole = new SimpleGrantedAuthority(roles[i]);
Set<GrantedAuthority> rolesReachableInOneStepSet;
if (!this.rolesReachableInOneStepMap.containsKey(higherRole)) {
rolesReachableInOneStepSet = new HashSet<>();
this.rolesReachableInOneStepMap.put(higherRole, rolesReachableInOneStepSet);
}
else {
rolesReachableInOneStepSet = this.rolesReachableInOneStepMap.get(higherRole);
}
rolesReachableInOneStepSet.add(lowerRole);
logger.debug(LogMessage.format(
"buildRolesReachableInOneStepMap() - From role %s one can reach role %s in one step.",
higherRole, lowerRole));
}
}
}
Expected Behavior
@ParameterizedTest
@CsvSource(value = {"A>B>C", "A > B > C"})
void expectedSplitHierarchicalroles(String givenRoles) {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy(givenRoles);
Collection<GrantedAuthority> grantedAuthorities = roleHierarchy.getReachableGrantedAuthorities(AuthorityUtils.createAuthorityList("A"));
assertThat(grantedAuthorities).hasSize(3); // i think so that must be success
}
Current Behavior
@ParameterizedTest
@CsvSource(value = {"A>B>C", "A > B > C"})
void expectedSplitHierarchicalroles(String givenRoles) {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy(givenRoles);
Collection<GrantedAuthority> grantedAuthorities = roleHierarchy.getReachableGrantedAuthorities(AuthorityUtils.createAuthorityList("A"));
assertThat(grantedAuthorities).hasSize(3); // current version is failed
}
Context If my intended results are correct, I will write a PR on this issue.
Version 5.6.1
Comment From: sjohnr
Hi @jaceshim. It does indeed look as though requiring spaces was introduced with a refactoring in 2019. However, the documentation and tests all work on the assumption that white space is either required or preferred. I'm hesitant to recommend making more changes to this class unless you're facing a regression/bug, which it sounds like you're not.
If you were able to write several additional tests that covered the types of scenarios you're concerned about, without modifying any of the existing ones, it might be plausible to work on this as an enhancement for the 5.7 release. What do you think?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.