3131import org .apache .cloudstack .iam .api .IAMPolicyPermission ;
3232import org .apache .cloudstack .iam .api .IAMService ;
3333
34+ import com .cloud .domain .DomainVO ;
35+ import com .cloud .domain .dao .DomainDao ;
3436import com .cloud .user .Account ;
3537import com .cloud .utils .component .AdapterBase ;
3638
@@ -40,6 +42,8 @@ public class RoleBasedEntityQuerySelector extends AdapterBase implements QuerySe
4042
4143 @ Inject
4244 IAMService _iamService ;
45+ @ Inject
46+ DomainDao _domainDao ;
4347
4448 @ Override
4549 public List <Long > getAuthorizedDomains (Account caller , String action , AccessType accessType ) {
@@ -61,11 +65,23 @@ public List<Long> getAuthorizedDomains(Account caller, String action, AccessType
6165 if (pp != null ) {
6266 for (IAMPolicyPermission p : pp ) {
6367 if (p .getScopeId () != null ) {
68+ Long domainId = null ;
6469 if (p .getScopeId ().longValue () == -1 ) {
65- domainIds .add (caller .getDomainId ());
70+ domainId = caller .getDomainId ();
71+ //domainIds.add(caller.getDomainId());
6672 } else {
67- domainIds .add (p .getScopeId ());
73+ domainId = p .getScopeId ();
74+ //domainIds.add(p.getScopeId());
75+ }
76+ domainIds .add (domainId );
77+ // add all the domain children from this domain. Like RoleBasedEntityAccessChecker, we made an assumption, if DOMAIN scope is granted, it means that
78+ // the whole domain tree is granted access.
79+ DomainVO domain = _domainDao .findById (domainId );
80+ List <Long > childDomains = _domainDao .getDomainChildrenIds (domain .getPath ());
81+ if (childDomains != null && childDomains .size () > 0 ) {
82+ domainIds .addAll (childDomains );
6883 }
84+
6985 }
7086 }
7187 }
0 commit comments