mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Refactor db view based list apis to use new IAM acl search criteria.
This commit is contained in:
parent
841dcb0e8e
commit
729a79e85c
@ -35,7 +35,6 @@ import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.api.query.dao.AccountJoinDao;
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
import com.cloud.configuration.ResourceLimit;
|
||||
import com.cloud.configuration.dao.ResourceCountDao;
|
||||
import com.cloud.domain.Domain;
|
||||
@ -232,21 +231,6 @@ public class MockAccountManager extends ManagerBase implements AccountManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(
|
||||
SearchBuilder<? extends ControlledViewEntity> arg0, Long arg1,
|
||||
boolean arg2, List<Long> arg3, ListProjectResourcesCriteria arg4) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(
|
||||
SearchCriteria<? extends ControlledViewEntity> arg0, Long arg1,
|
||||
boolean arg2, List<Long> arg3, ListProjectResourcesCriteria arg4) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long checkAccessAndSpecifyAuthority(Account arg0, Long arg1) {
|
||||
@ -372,20 +356,6 @@ public class MockAccountManager extends ManagerBase implements AccountManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledEntity> sc, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDomainAdmin(long accountId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -500,7 +500,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
|
||||
private Pair<List<EventJoinVO>, Integer> searchForEventsInternal(ListEventsCmd cmd) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
|
||||
Long id = cmd.getId();
|
||||
String type = cmd.getType();
|
||||
@ -513,17 +515,15 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false, "listEvents");
|
||||
//Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
|
||||
Filter searchFilter = new Filter(EventJoinVO.class, "createDate", false, cmd.getStartIndex(),
|
||||
cmd.getPageSizeVal());
|
||||
SearchBuilder<EventJoinVO> sb = _eventJoinDao.createSearchBuilder();
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("levelL", sb.entity().getLevel(), SearchCriteria.Op.LIKE);
|
||||
@ -538,9 +538,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
sb.and("archived", sb.entity().getArchived(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchCriteria<EventJoinVO> sc = sb.create();
|
||||
// building ACL condition
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<EventJoinVO> aclSc = _eventJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (id != null) {
|
||||
sc.setParameters("id", id);
|
||||
@ -615,7 +615,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
|
||||
private Pair<List<ResourceTagJoinVO>, Integer> listTagsInternal(ListTagsCmd cmd) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
String key = cmd.getKey();
|
||||
String value = cmd.getValue();
|
||||
String resourceId = cmd.getResourceId();
|
||||
@ -626,8 +628,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
|
||||
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, listAll, false);
|
||||
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, listAll, false, "listTags");
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
@ -635,8 +637,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
cmd.getPageSizeVal());
|
||||
|
||||
SearchBuilder<ResourceTagJoinVO> sb = _resourceTagJoinDao.createSearchBuilder();
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
sb.and("key", sb.entity().getKey(), SearchCriteria.Op.EQ);
|
||||
sb.and("value", sb.entity().getValue(), SearchCriteria.Op.EQ);
|
||||
@ -652,8 +652,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
|
||||
// now set the SC criteria...
|
||||
SearchCriteria<ResourceTagJoinVO> sc = sb.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<ResourceTagJoinVO> aclSc = _resourceTagJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (key != null) {
|
||||
sc.setParameters("key", key);
|
||||
@ -696,12 +697,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
String keyword = cmd.getKeyword();
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false, "listInstanceGroups");
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
@ -710,15 +713,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
cmd.getPageSizeVal());
|
||||
|
||||
SearchBuilder<InstanceGroupJoinVO> sb = _vmGroupJoinDao.createSearchBuilder();
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
|
||||
SearchCriteria<InstanceGroupJoinVO> sc = sb.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<InstanceGroupJoinVO> aclSc = _vmGroupJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<InstanceGroupJoinVO> ssc = _vmGroupJoinDao.createSearchCriteria();
|
||||
@ -984,7 +986,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
String securityGroup = cmd.getSecurityGroupName();
|
||||
Long id = cmd.getId();
|
||||
Object keyword = cmd.getKeyword();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
|
||||
if (instanceId != null) {
|
||||
@ -999,8 +1003,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false, "listSecurityGroups");
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
@ -1010,16 +1014,15 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
SearchBuilder<SecurityGroupJoinVO> sb = _securityGroupJoinDao.createSearchBuilder();
|
||||
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct
|
||||
// ids
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
|
||||
|
||||
SearchCriteria<SecurityGroupJoinVO> sc = sb.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<SecurityGroupJoinVO> aclSc = _securityGroupJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (id != null) {
|
||||
sc.setParameters("id", id);
|
||||
@ -1113,27 +1116,30 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
String name, String state, Long zoneId, Long podId, Long hostId, String keyword, Long networkId, Long vpcId, Boolean forVpc, String role) {
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
String action = "listRouters";
|
||||
if (cmd instanceof ListInternalLBVMsCmd) {
|
||||
action = "listInternalLoadBalancerVMs";
|
||||
}
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false, action);
|
||||
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
Filter searchFilter = new Filter(DomainRouterJoinVO.class, "id", true, cmd.getStartIndex(),
|
||||
cmd.getPageSizeVal());
|
||||
// Filter searchFilter = new Filter(DomainRouterJoinVO.class, null,
|
||||
// true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchBuilder<DomainRouterJoinVO> sb = _routerJoinDao.createSearchBuilder();
|
||||
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct
|
||||
// ids to get
|
||||
// number of
|
||||
// records with
|
||||
// pagination
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
sb.and("name", sb.entity().getInstanceName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
@ -1158,8 +1164,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
}
|
||||
|
||||
SearchCriteria<DomainRouterJoinVO> sc = sb.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<DomainRouterJoinVO> aclSc = _routerJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<DomainRouterJoinVO> ssc = _routerJoinDao.createSearchCriteria();
|
||||
@ -1392,20 +1399,20 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
boolean listAll = cmd.listAll();
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
domainId, isRecursive, null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts,
|
||||
domainIdRecursiveListProject, listAll, true);
|
||||
domainId = domainIdRecursiveListProject.first();
|
||||
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, listAll, true, "listProjectInvitations");
|
||||
//domainId = domainIdRecursiveListProject.first();
|
||||
isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
|
||||
Filter searchFilter = new Filter(ProjectInvitationJoinVO.class, "id", true, startIndex, pageSizeVal);
|
||||
SearchBuilder<ProjectInvitationJoinVO> sb = _projectInvitationJoinDao.createSearchBuilder();
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
sb.and("projectId", sb.entity().getProjectId(), SearchCriteria.Op.EQ);
|
||||
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
|
||||
@ -1413,8 +1420,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchCriteria<ProjectInvitationJoinVO> sc = sb.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<ProjectInvitationJoinVO> aclSc = _projectInvitationJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (projectId != null) {
|
||||
sc.setParameters("projectId", projectId);
|
||||
@ -3141,18 +3149,20 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
return listAffinityGroupsByVM(vmId.longValue(), startIndex, pageSize);
|
||||
}
|
||||
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
domainId, isRecursive, null);
|
||||
_accountMgr.buildACLSearchParameters(caller, affinityGroupId, accountName, null, permittedAccounts,
|
||||
domainIdRecursiveListProject, listAll, true);
|
||||
domainId = domainIdRecursiveListProject.first();
|
||||
_accountMgr.buildACLSearchParameters(caller, affinityGroupId, accountName, null, permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, listAll, true, "listAffinityGroups");
|
||||
//domainId = domainIdRecursiveListProject.first();
|
||||
isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
|
||||
Filter searchFilter = new Filter(AffinityGroupJoinVO.class, "id", true, startIndex, pageSize);
|
||||
SearchCriteria<AffinityGroupJoinVO> sc = buildAffinityGroupSearchCriteria(domainId, isRecursive,
|
||||
permittedAccounts, listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType);
|
||||
SearchCriteria<AffinityGroupJoinVO> sc = buildAffinityGroupSearchCriteria(isRecursive,
|
||||
permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType);
|
||||
|
||||
Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc,
|
||||
searchFilter);
|
||||
@ -3169,6 +3179,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
vrs = _affinityGroupJoinDao.searchByIds(vrIds);
|
||||
}
|
||||
|
||||
/* TODO: confirm with Prachi if we still need this complicated logic with new ACL model
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
// add domain level affinity groups
|
||||
if (domainId != null) {
|
||||
@ -3194,25 +3205,24 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
affinityGroupType);
|
||||
vrs.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
|
||||
}
|
||||
*/
|
||||
|
||||
return new Pair<List<AffinityGroupJoinVO>, Integer>(vrs, vrs.size());
|
||||
|
||||
}
|
||||
|
||||
private SearchCriteria<AffinityGroupJoinVO> buildAffinityGroupSearchCriteria(Long domainId, boolean isRecursive,
|
||||
List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria,
|
||||
private SearchCriteria<AffinityGroupJoinVO> buildAffinityGroupSearchCriteria(boolean isRecursive,
|
||||
List<Long> permittedDomains, List<Long> permittedAccounts, List<Long> permittedResources, ListProjectResourcesCriteria listProjectResourcesCriteria,
|
||||
Long affinityGroupId, String affinityGroupName, String affinityGroupType) {
|
||||
|
||||
SearchBuilder<AffinityGroupJoinVO> groupSearch = _affinityGroupJoinDao.createSearchBuilder();
|
||||
_accountMgr.buildACLViewSearchBuilder(groupSearch, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
groupSearch.select(null, Func.DISTINCT, groupSearch.entity().getId()); // select
|
||||
// distinct
|
||||
|
||||
SearchCriteria<AffinityGroupJoinVO> sc = groupSearch.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<AffinityGroupJoinVO> aclSc = _affinityGroupJoinDao.createSearchCriteria();
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (affinityGroupId != null) {
|
||||
sc.addAnd("id", SearchCriteria.Op.EQ, affinityGroupId);
|
||||
|
||||
@ -24,7 +24,6 @@ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
|
||||
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.projects.Project.ListProjectResourcesCriteria;
|
||||
@ -87,23 +86,10 @@ public interface AccountManager extends AccountService {
|
||||
void buildACLSearchBuilder(SearchBuilder<? extends ControlledEntity> sb, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria);
|
||||
|
||||
void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria);
|
||||
|
||||
void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds);
|
||||
|
||||
void buildACLSearchCriteria(SearchCriteria<? extends ControlledEntity> sc,
|
||||
void buildACLSearchCriteria(SearchCriteria<? extends ControlledEntity> sc,
|
||||
Long domainId, boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria);
|
||||
|
||||
|
||||
void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEntity> sc,
|
||||
Long domainId, boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria);
|
||||
|
||||
void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledEntity> sc,
|
||||
Long domainId, boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds,
|
||||
List<Long> revokedIds);
|
||||
|
||||
void buildACLSearchParameters(Account caller, Long id,
|
||||
String accountName, Long projectId, List<Long> permittedAccounts, Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject, boolean listAll, boolean forProjectInvitation);
|
||||
|
||||
|
||||
@ -64,7 +64,6 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||
import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.Resource.ResourceOwnerType;
|
||||
@ -2414,128 +2413,6 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) {
|
||||
|
||||
sb.and("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN);
|
||||
sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
|
||||
if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
|
||||
// if accountId isn't specified, we can do a domain match for the
|
||||
// admin case if isRecursive is true
|
||||
sb.and("domainPath", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
|
||||
}
|
||||
|
||||
if (listProjectResourcesCriteria != null) {
|
||||
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
|
||||
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.EQ);
|
||||
} else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.NEQ);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds) {
|
||||
|
||||
if (!revokedIds.isEmpty()) {
|
||||
sb.and("idNIN", sb.entity().getId(), SearchCriteria.Op.NIN);
|
||||
}
|
||||
if (permittedAccounts.isEmpty() && domainId == null && listProjectResourcesCriteria == null) {
|
||||
// caller role authorize him to access everything matching query criteria
|
||||
return;
|
||||
|
||||
}
|
||||
boolean hasOp = true;
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
sb.and().op("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN);
|
||||
} else if (domainId != null) {
|
||||
if (isRecursive) {
|
||||
// if accountId isn't specified, we can do a domain match for the
|
||||
// admin case if isRecursive is true
|
||||
sb.and().op("domainPath", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
|
||||
} else {
|
||||
sb.and().op("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
}
|
||||
} else {
|
||||
hasOp = false;
|
||||
}
|
||||
|
||||
|
||||
if (listProjectResourcesCriteria != null) {
|
||||
if (hasOp) {
|
||||
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
|
||||
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.EQ);
|
||||
} else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.NEQ);
|
||||
}
|
||||
} else {
|
||||
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
|
||||
sb.and().op("accountType", sb.entity().getAccountType(), SearchCriteria.Op.EQ);
|
||||
} else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
sb.and().op("accountType", sb.entity().getAccountType(), SearchCriteria.Op.NEQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!grantedIds.isEmpty()) {
|
||||
sb.or("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
|
||||
}
|
||||
sb.cp();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEntity> sc,
|
||||
Long domainId, boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) {
|
||||
if (listProjectResourcesCriteria != null) {
|
||||
sc.setParameters("accountType", Account.ACCOUNT_TYPE_PROJECT);
|
||||
}
|
||||
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
sc.setParameters("accountIdIN", permittedAccounts.toArray());
|
||||
} else if (domainId != null) {
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if (isRecursive) {
|
||||
sc.setParameters("domainPath", domain.getPath() + "%");
|
||||
} else {
|
||||
sc.setParameters("domainId", domainId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledEntity> sc, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds) {
|
||||
if (!revokedIds.isEmpty()) {
|
||||
sc.setParameters("idNIN", revokedIds.toArray());
|
||||
}
|
||||
|
||||
if (listProjectResourcesCriteria != null) {
|
||||
sc.setParameters("accountType", Account.ACCOUNT_TYPE_PROJECT);
|
||||
}
|
||||
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
sc.setParameters("accountIdIN", permittedAccounts.toArray());
|
||||
} else if (domainId != null) {
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if (isRecursive) {
|
||||
sc.setParameters("domainPath", domain.getPath() + "%");
|
||||
} else {
|
||||
sc.setParameters("domainId", domainId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!grantedIds.isEmpty()) {
|
||||
sc.setParameters("idIN", grantedIds.toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserAccount getUserByApiKey(String apiKey) {
|
||||
return _userAccountDao.getUserByApiKey(apiKey);
|
||||
@ -2639,6 +2516,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledEntity> sc, SearchCriteria<? extends ControlledEntity> aclSc, boolean isRecursive,
|
||||
List<Long> permittedDomains,
|
||||
|
||||
@ -32,7 +32,6 @@ import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
|
||||
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.PartOf;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
@ -280,31 +279,6 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEntity> sc, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledEntity> sc, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, List<Long> grantedIds, List<Long> revokedIds) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.user.AccountService#getUserByApiKey(java.lang.String)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user