Skip to content

Commit ec4fa61

Browse files
author
Prachi Damle
committed
Tested ACL for StartVmCmd using the new RoleBasedEntityAccessChecker
1 parent 7d1ba65 commit ec4fa61

9 files changed

Lines changed: 53 additions & 5 deletions

File tree

‎api/src/org/apache/cloudstack/acl/AclRolePermission.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface AclRolePermission extends InternalIdentity {
3030
PermissionScope getScope();
3131

3232
boolean isAllowed();
33+
34+
PermissionScope getScope();
3335
}

‎api/src/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
20+
import org.apache.cloudstack.api.ACL;
1921
import org.apache.cloudstack.api.APICommand;
2022
import org.apache.cloudstack.api.ApiCommandJobType;
2123
import org.apache.cloudstack.api.ApiConstants;
@@ -50,6 +52,7 @@ public class StartVMCmd extends BaseAsyncCmd {
5052
// ////////////// API parameters /////////////////////
5153
// ///////////////////////////////////////////////////
5254

55+
@ACL(accessType = AccessType.OperateEntry)
5356
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType=UserVmResponse.class,
5457
required = true, description = "The ID of the virtual machine")
5558
private Long id;

‎client/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<artifactId>cloud-plugin-acl-static-role-based</artifactId>
3535
<version>${project.version}</version>
3636
</dependency>
37+
<dependency>
38+
<groupId>org.apache.cloudstack</groupId>
39+
<artifactId>cloud-plugin-acl-role-based-access-checkers</artifactId>
40+
<version>${project.version}</version>
41+
</dependency>
3742
<dependency>
3843
<groupId>org.apache.cloudstack</groupId>
3944
<artifactId>cloud-plugin-dedicated-resources</artifactId>

‎client/tomcatconf/applicationContext.xml.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@
389389
<bean id="databaseIntegrityChecker" class="com.cloud.upgrade.DatabaseIntegrityChecker" />
390390
<bean id="domainChecker" class="com.cloud.acl.DomainChecker" />
391391
<bean id="affinityGroupAccessChecker" class="com.cloud.acl.AffinityGroupAccessChecker" />
392+
<bean id="roleBasedEntityAccessChecker" class="org.apache.cloudstack.acl.entity.RoleBasedEntityAccessChecker" />
392393

393394
<!--
394395
Authenticators

‎client/tomcatconf/componentContext.xml.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<bean id="securityCheckers" class="com.cloud.utils.component.AdapterList">
147147
<property name="Adapters">
148148
<list>
149+
<ref bean="roleBasedEntityAccessChecker"/>
149150
<ref bean="affinityGroupAccessChecker"/>
150151
<ref bean="domainChecker"/>
151152
</list>

‎client/tomcatconf/nonossComponentContext.xml.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
<bean id="securityCheckers" class="com.cloud.utils.component.AdapterList">
244244
<property name="Adapters">
245245
<list>
246+
<ref bean="roleBasedEntityAccessChecker"/>
246247
<ref bean="affinityGroupAccessChecker"/>
247248
<ref bean="domainChecker"/>
248249
</list>

‎client/tomcatconf/simulatorComponentContext.xml.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<bean id="securityCheckers" class="com.cloud.utils.component.AdapterList">
9494
<property name="Adapters">
9595
<list>
96+
<ref bean="roleBasedEntityAccessChecker"/>
9697
<ref bean="affinityGroupAccessChecker"/>
9798
<ref bean="domainChecker"/>
9899
</list>

‎engine/schema/src/org/apache/cloudstack/acl/AclRolePermissionVO.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class AclRolePermissionVO implements AclRolePermission {
5353
@Column(name = "permission")
5454
private boolean allowed;
5555

56+
5657
public AclRolePermissionVO() {
5758

5859
}
@@ -114,4 +115,12 @@ public void setAllowed(boolean allowed) {
114115
this.allowed = allowed;
115116
}
116117

118+
@Override
119+
public PermissionScope getScope() {
120+
return scope;
121+
}
122+
123+
public void setScope(PermissionScope scope) {
124+
this.scope = scope;
125+
}
117126
}

‎plugins/acl/role-based-access-checkers/src/org/apache/cloudstack/acl/entity/RoleBasedEntityAccessChecker.java‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.cloudstack.acl.AclRolePermissionVO;
2929
import org.apache.cloudstack.acl.AclService;
3030
import org.apache.cloudstack.acl.ControlledEntity;
31+
import org.apache.cloudstack.acl.PermissionScope;
3132
import org.apache.cloudstack.acl.SecurityChecker;
3233
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
3334
import org.apache.cloudstack.acl.dao.AclEntityPermissionDao;
@@ -39,6 +40,7 @@
3940

4041
import com.cloud.acl.DomainChecker;
4142
import com.cloud.api.ApiDispatcher;
43+
import com.cloud.domain.dao.DomainDao;
4244
import com.cloud.exception.PermissionDeniedException;
4345
import com.cloud.template.VirtualMachineTemplate;
4446
import com.cloud.user.Account;
@@ -53,6 +55,8 @@ public class RoleBasedEntityAccessChecker extends DomainChecker implements Secur
5355
AccountService _accountService;
5456
@Inject
5557
AclService _aclService;
58+
59+
@Inject DomainDao _domainDao;
5660

5761
@Inject
5862
AclGroupAccountMapDao _aclGroupAccountMapDao;
@@ -70,6 +74,10 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
7074

7175
String entityType = AclEntityType.VM.toString();
7276

77+
if (accessType == null) {
78+
accessType = AccessType.ListEntry;
79+
}
80+
7381
// check if explicit allow/deny is present for this entity in
7482
// acl_entity_permission
7583

@@ -105,11 +113,13 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
105113
List<AclRolePermissionVO> permissions = _rolePermissionDao.listByRoleAndEntity(role.getId(),
106114
entityType, accessType);
107115
for (AclRolePermissionVO permission : permissions) {
108-
if (permission.getEntityType().equals(entityType)) {
109-
rolePermissionMap.put(role, permission.isAllowed());
110-
break;
111-
} else if (permission.getEntityType().equals("*")) {
112-
rolePermissionMap.put(role, permission.isAllowed());
116+
if (checkPermissionScope(caller, permission.getScope(), entity)) {
117+
if (permission.getEntityType().equals(entityType)) {
118+
rolePermissionMap.put(role, permission.isAllowed());
119+
break;
120+
} else if (permission.getEntityType().equals("*")) {
121+
rolePermissionMap.put(role, permission.isAllowed());
122+
}
113123
}
114124
}
115125
if (rolePermissionMap.containsKey(role) && rolePermissionMap.get(role)) {
@@ -129,4 +139,19 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
129139

130140
return false;
131141
}
142+
143+
private boolean checkPermissionScope(Account caller, PermissionScope scope, ControlledEntity entity) {
144+
145+
if(scope.equals(PermissionScope.ACCOUNT)){
146+
if(caller.getAccountId() == entity.getAccountId()){
147+
return true;
148+
}
149+
}else if(scope.equals(PermissionScope.DOMAIN)){
150+
if (_domainDao.isChildDomain(caller.getDomainId(), entity.getDomainId())) {
151+
return true;
152+
}
153+
}
154+
155+
return false;
156+
}
132157
}

0 commit comments

Comments
 (0)