You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2014/04/19 02:24:25 UTC
git commit: updated refs/heads/master to 82821da
Repository: cloudstack
Updated Branches:
refs/heads/master 6cfe248e2 -> 82821daff
Fix listAccountsCmd logic to be consistent with new interpretation of
listAll, isRecursive and domainId parameters.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/82821daf
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/82821daf
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/82821daf
Branch: refs/heads/master
Commit: 82821daffc3e408f0b65e7316ea58245776b22ce
Parents: 6cfe248
Author: Min Chen <mi...@citrix.com>
Authored: Fri Apr 18 16:57:22 2014 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Fri Apr 18 17:24:00 2014 -0700
----------------------------------------------------------------------
.../com/cloud/api/query/QueryManagerImpl.java | 106 ++++++++-----------
1 file changed, 42 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/82821daf/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index 157d7fb..7aaa4e0 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -26,6 +26,9 @@ import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -95,8 +98,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.query.QueryService;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
import com.cloud.api.query.dao.AccountJoinDao;
import com.cloud.api.query.dao.AffinityGroupJoinDao;
@@ -1834,52 +1835,19 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
private Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccountsCmd cmd) {
Account caller = CallContext.current().getCallingAccount();
- Long domainId = cmd.getDomainId();
- Long accountId = cmd.getId();
- String accountName = cmd.getSearchName();
- boolean isRecursive = cmd.isRecursive();
- boolean listAll = cmd.listAll();
- Boolean listForDomain = false;
-
- if (accountId != null) {
- Account account = _accountDao.findById(accountId);
- if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
- throw new InvalidParameterValueException("Unable to find account by id " + accountId);
- }
-
- _accountMgr.checkAccess(caller, null, account);
- }
-
- if (domainId != null) {
- Domain domain = _domainDao.findById(domainId);
- if (domain == null) {
- throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
- }
-
- _accountMgr.checkAccess(caller, domain);
-
- if (accountName != null) {
- Account account = _accountDao.findActiveAccount(accountName, domainId);
- if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
- throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain " + domainId);
- }
- _accountMgr.checkAccess(caller, null, account);
- }
- }
+ List<Long> permittedDomains = new ArrayList<Long>();
+ List<Long> permittedAccounts = new ArrayList<Long>();
+ List<Long> permittedResources = new ArrayList<Long>();
- if (accountId == null) {
- if (_accountMgr.isAdmin(caller.getType()) && listAll && domainId == null) {
- listForDomain = true;
- isRecursive = true;
- if (domainId == null) {
- domainId = caller.getDomainId();
- }
- } else if (_accountMgr.isAdmin(caller.getType()) && domainId != null) {
- listForDomain = true;
- } else {
- accountId = caller.getAccountId();
- }
- }
+ boolean listAll = cmd.listAll();
+ Long id = cmd.getId();
+ String accountName = cmd.getSearchName();
+ Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
+ cmd.getDomainId(), cmd.isRecursive(), null);
+ // ListAccountsCmd is not BaseListAccountResourcesCmd, so no (domainId, accountName) combination
+ _accountMgr.buildACLSearchParameters(caller, id, null, null, permittedDomains, permittedAccounts, permittedResources,
+ domainIdRecursiveListProject, listAll, false, "listAccounts");
+ Boolean isRecursive = domainIdRecursiveListProject.second();
Filter searchFilter = new Filter(AccountJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
@@ -1890,7 +1858,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
SearchBuilder<AccountJoinVO> sb = _accountJoinDao.createSearchBuilder();
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.EQ);
- sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
@@ -1898,11 +1865,31 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.and("typeNEQ", sb.entity().getType(), SearchCriteria.Op.NEQ);
sb.and("idNEQ", sb.entity().getId(), SearchCriteria.Op.NEQ);
- if (listForDomain && isRecursive) {
- sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
- }
-
SearchCriteria<AccountJoinVO> sc = sb.create();
+ SearchCriteria<AccountJoinVO> aclSc = _accountJoinDao.createSearchCriteria();
+ // building ACL search criteria. Here we cannot use the common accountMgr.buildACLViewSearchCriteria because
+ // 1) AccountJoinVO does not have accountId field, permittedAccounts correspond to list of resource ids.
+ // 2) AccountJoinVO use type not accountType field to indicate its type
+ if (!permittedDomains.isEmpty() || !permittedAccounts.isEmpty() || !permittedResources.isEmpty()) {
+ if (!permittedDomains.isEmpty()) {
+ if (isRecursive) {
+ for (int i = 0; i < permittedDomains.size(); i++) {
+ Domain domain = _domainDao.findById(permittedDomains.get(i));
+ aclSc.addOr("domainPath", SearchCriteria.Op.LIKE, domain.getPath() + "%");
+ }
+ } else {
+ aclSc.addOr("domainId", SearchCriteria.Op.IN, permittedDomains.toArray());
+ }
+ }
+ if (!permittedAccounts.isEmpty()) {
+ aclSc.addOr("id", SearchCriteria.Op.IN, permittedAccounts.toArray());
+ }
+ if (!permittedResources.isEmpty()) {
+ aclSc.addOr("id", SearchCriteria.Op.IN, permittedResources.toArray());
+ }
+
+ sc.addAnd("id", SearchCriteria.Op.SC, aclSc);
+ }
sc.setParameters("idNEQ", Account.ACCOUNT_ID_SYSTEM);
@@ -1930,19 +1917,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
}
// don't return account of type project to the end user
- sc.setParameters("typeNEQ", 5);
-
- if (accountId != null) {
- sc.setParameters("id", accountId);
- }
+ sc.setParameters("typeNEQ", Account.ACCOUNT_TYPE_PROJECT);
- if (listForDomain) {
- if (isRecursive) {
- Domain domain = _domainDao.findById(domainId);
- sc.setParameters("path", domain.getPath() + "%");
- } else {
- sc.setParameters("domainId", domainId);
- }
+ if (id != null) {
+ sc.setParameters("id", id);
}
return _accountJoinDao.searchAndCount(sc, searchFilter);