Skip to content

Commit a6d07c8

Browse files
author
Prachi Damle
committed
Changes to QuerySelector to list the parent group resources with recursive = true access
1 parent 939b151 commit a6d07c8

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
21962196
NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(networkFinal.getId());
21972197
if (networkAccount != null)
21982198
_networkAccountDao.remove(networkAccount.getId());
2199-
2199+
22002200
// remove its related ACL permission
22012201
Pair<AclEntityType, Long> networkMsg = new Pair<AclEntityType, Long>(AclEntityType.Network, networkFinal.getId());
22022202
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);

‎services/iam/plugin/src/org/apache/cloudstack/acl/RoleBasedEntityAccessChecker.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private List<AclPolicy> getEffectivePolicies(Account caller, ControlledEntity en
172172
List<AclGroup> groups = _iamSrv.listAclGroups(caller.getId());
173173
for (AclGroup group : groups) {
174174
// for each group find the grand parent groups.
175-
List<AclGroup> parentGroups = _iamSrv.listParentAclGroupsOnPath(group.getPath());
175+
List<AclGroup> parentGroups = _iamSrv.listParentAclGroups(group.getId());
176176
for (AclGroup parentGroup : parentGroups) {
177177
policies.addAll(_iamSrv.listRecursiveAclPoliciesByGroup(parentGroup.getId()));
178178
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ public List<Long> getAuthorizedResources(Account caller, String action) {
8383
long accountId = caller.getAccountId();
8484
// Get the static Policies of the Caller
8585
List<AclPolicy> policies = _iamService.listAclPolicies(accountId);
86+
87+
// add the policies that grant recursive access
88+
List<AclGroup> groups = _iamService.listAclGroups(caller.getId());
89+
for (AclGroup group : groups) {
90+
// for each group find the grand parent groups.
91+
List<AclGroup> parentGroups = _iamService.listParentAclGroups(group.getId());
92+
for (AclGroup parentGroup : parentGroups) {
93+
policies.addAll(_iamService.listRecursiveAclPoliciesByGroup(parentGroup.getId()));
94+
}
95+
}
96+
8697
// for each policy, find granted permission with Resource scope
8798
List<Long> entityIds = new ArrayList<Long>();
8899
for (AclPolicy policy : policies) {

‎services/iam/server/src/org/apache/cloudstack/iam/api/IAMService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ AclPolicy removeAclPermissionFromAclPolicy(long aclPolicyId, String entityType,
8585
List<AclPolicyPermission> listPolicyPermissionByAccessAndEntity(long policyId, String accessType,
8686
String entityType);
8787

88-
List<AclGroup> listParentAclGroupsOnPath(String path);
88+
List<AclGroup> listParentAclGroups(long groupId);
8989

9090
List<AclPolicy> listRecursiveAclPoliciesByGroup(long groupId);
9191

‎services/iam/server/src/org/apache/cloudstack/iam/server/IAMServiceImpl.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,13 @@ public Pair<List<AclGroup>, Integer> listAclGroups(Long aclGroupId, String aclGr
257257
}
258258

259259
@Override
260-
public List<AclGroup> listParentAclGroupsOnPath(String path) {
260+
public List<AclGroup> listParentAclGroups(long groupId) {
261+
AclGroup group = _aclGroupDao.findById(groupId);
262+
if (group == null) {
263+
throw new InvalidParameterValueException("Unable to find acl group by id " + groupId);
264+
}
261265

266+
String path = group.getPath();
262267
List<String> pathList = new ArrayList<String>();
263268

264269
String[] parts = path.split("/");

0 commit comments

Comments
 (0)