2828import org .apache .cloudstack .acl .AclRolePermissionVO ;
2929import org .apache .cloudstack .acl .AclService ;
3030import org .apache .cloudstack .acl .ControlledEntity ;
31+ import org .apache .cloudstack .acl .PermissionScope ;
3132import org .apache .cloudstack .acl .SecurityChecker ;
3233import org .apache .cloudstack .acl .SecurityChecker .AccessType ;
3334import org .apache .cloudstack .acl .dao .AclEntityPermissionDao ;
3940
4041import com .cloud .acl .DomainChecker ;
4142import com .cloud .api .ApiDispatcher ;
43+ import com .cloud .domain .dao .DomainDao ;
4244import com .cloud .exception .PermissionDeniedException ;
4345import com .cloud .template .VirtualMachineTemplate ;
4446import 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