|
17 | 17 | package org.springframework.security.acls.domain;
|
18 | 18 |
|
19 | 19 | import java.util.Arrays;
|
| 20 | +import java.util.Collection; |
20 | 21 | import java.util.List;
|
21 | 22 | import java.util.Set;
|
22 | 23 |
|
23 | 24 | import org.springframework.security.access.AccessDeniedException;
|
| 25 | +import org.springframework.security.access.hierarchicalroles.NullRoleHierarchy; |
| 26 | +import org.springframework.security.access.hierarchicalroles.RoleHierarchy; |
24 | 27 | import org.springframework.security.acls.model.Acl;
|
25 | 28 | import org.springframework.security.acls.model.Sid;
|
26 | 29 | import org.springframework.security.acls.model.SidRetrievalStrategy;
|
@@ -59,6 +62,8 @@ public class AclAuthorizationStrategyImpl implements AclAuthorizationStrategy {
|
59 | 62 |
|
60 | 63 | private SidRetrievalStrategy sidRetrievalStrategy = new SidRetrievalStrategyImpl();
|
61 | 64 |
|
| 65 | + private RoleHierarchy roleHierarchy = new NullRoleHierarchy(); |
| 66 | + |
62 | 67 | /**
|
63 | 68 | * Constructor. The only mandatory parameter relates to the system-wide
|
64 | 69 | * {@link GrantedAuthority} instances that can be held to always permit ACL changes.
|
@@ -100,7 +105,9 @@ public void securityCheck(Acl acl, int changeType) {
|
100 | 105 | }
|
101 | 106 |
|
102 | 107 | // Iterate this principal's authorities to determine right
|
103 |
| - Set<String> authorities = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); |
| 108 | + Collection<? extends GrantedAuthority> reachableGrantedAuthorities = this.roleHierarchy |
| 109 | + .getReachableGrantedAuthorities(authentication.getAuthorities()); |
| 110 | + Set<String> authorities = AuthorityUtils.authorityListToSet(reachableGrantedAuthorities); |
104 | 111 | if (acl.getOwner() instanceof GrantedAuthoritySid
|
105 | 112 | && authorities.contains(((GrantedAuthoritySid) acl.getOwner()).getGrantedAuthority())) {
|
106 | 113 | return;
|
@@ -162,4 +169,14 @@ public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy secur
|
162 | 169 | this.securityContextHolderStrategy = securityContextHolderStrategy;
|
163 | 170 | }
|
164 | 171 |
|
| 172 | + /** |
| 173 | + * Sets the {@link RoleHierarchy} to use. The default is to use a |
| 174 | + * {@link NullRoleHierarchy} |
| 175 | + * @since 6.4 |
| 176 | + */ |
| 177 | + public void setRoleHierarchy(RoleHierarchy roleHierarchy) { |
| 178 | + Assert.notNull(roleHierarchy, "roleHierarchy cannot be null"); |
| 179 | + this.roleHierarchy = roleHierarchy; |
| 180 | + } |
| 181 | + |
165 | 182 | }
|
0 commit comments