Github user ustcweizhou commented on the pull request:

    https://github.com/apache/cloudstack/pull/508#issuecomment-158164720
  
    @pdube 
    
    try this change:
    
    ```
    diff --git a/server/src/com/cloud/acl/AffinityGroupAccessChecker.java 
b/server/src/com/cloud/acl/AffinityGroupAccessChecker.java
    index 57f7b37..c6e44d6 100644
    --- a/server/src/com/cloud/acl/AffinityGroupAccessChecker.java
    +++ b/server/src/com/cloud/acl/AffinityGroupAccessChecker.java
    @@ -30,6 +30,9 @@ import 
org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
    
     import com.cloud.domain.DomainVO;
     import com.cloud.exception.PermissionDeniedException;
    +import com.cloud.projects.ProjectVO;
    +import com.cloud.projects.dao.ProjectAccountDao;
    +import com.cloud.projects.dao.ProjectDao;
     import com.cloud.user.Account;
     import com.cloud.user.AccountManager;
     import com.cloud.utils.exception.CloudRuntimeException;
    @@ -44,6 +47,10 @@ public class AffinityGroupAccessChecker extends 
DomainChecker {
         AccountManager _accountMgr;
         @Inject
         AffinityGroupDomainMapDao _affinityGroupDomainMapDao;
    +    @Inject
    +    ProjectDao _projectDao;
    +    @Inject
    +    ProjectAccountDao _projectAccountDao;
    
         @Override
         public boolean checkAccess(Account caller, ControlledEntity entity, 
AccessType accessType) throws PermissionDeniedException {
    @@ -72,6 +79,15 @@ public class AffinityGroupAccessChecker extends 
DomainChecker {
                 } else {
                     //acl_type account
                     if (caller.getId() != group.getAccountId()) {
    +                    //check if the group belongs to a project
    +                    ProjectVO project = 
_projectDao.findByProjectAccountId(group.getAccountId());
    +                    if (project != null) {
    +                        if (AccessType.ModifyProject.equals(accessType) && 
_projectAccountDao.canModifyProjectAccount(caller.getId(), 
group.getAccountId())) {
    +                            return true;
    +                        } else if 
(!AccessType.ModifyProject.equals(accessType) && 
_projectAccountDao.canAccessProjectAccount(caller.getId(), 
group.getAccountId())) {
    +                            return true;
    +                        }
    +                    }
                         throw new PermissionDeniedException(caller + " does 
not have permission to operate with resource " + entity);
                     } else {
                         return true;
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to