Skip to content

Commit bc525d2

Browse files
committed
CLOUDSTACK-6428:IAM - Domain Admin - When his sub-domainId is passed to
the listVirtualMachine command, Vms from all the domains are being listed.
1 parent cdd39a8 commit bc525d2

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityQuerySelector.java‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.apache.cloudstack.iam.api.IAMPolicyPermission;
3232
import org.apache.cloudstack.iam.api.IAMService;
3333

34+
import com.cloud.domain.DomainVO;
35+
import com.cloud.domain.dao.DomainDao;
3436
import com.cloud.user.Account;
3537
import 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

Comments
 (0)