mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-6793 : Added fix
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
This commit is contained in:
parent
99e4da15da
commit
f89100ed72
@ -63,4 +63,13 @@ public interface AccountDao extends GenericDao<AccountVO, Long> {
|
||||
Account findActiveNonProjectAccount(String accountName, Long domainId);
|
||||
|
||||
List<Long> getAccountIdsForDomains(List<Long> ids);
|
||||
|
||||
/*
|
||||
@Desc: Retrieves the DomainId for a given Account Id
|
||||
@Input: id : Id of the Account
|
||||
@Output: DomainId matching for the given Account Id. Returns -1
|
||||
in case of no match;
|
||||
*/
|
||||
long getDomainIdForGivenAccountId(long id);
|
||||
|
||||
}
|
||||
|
||||
@ -278,4 +278,20 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDomainIdForGivenAccountId(long id) {
|
||||
long domain_id = -1;
|
||||
try {
|
||||
AccountVO account_vo = findById(id);
|
||||
domain_id = account_vo.getDomainId();
|
||||
}
|
||||
catch (Exception e) {
|
||||
s_logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage());
|
||||
}
|
||||
finally {
|
||||
return domain_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
@ -33,7 +35,6 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.query.dao.ResourceTagJoinDao;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.PartOf;
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.EventTypes;
|
||||
@ -136,6 +137,8 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
|
||||
ResourceTagJoinDao _resourceTagJoinDao;
|
||||
@Inject
|
||||
DomainManager _domainMgr;
|
||||
@Inject
|
||||
AccountDao _accountDao;
|
||||
|
||||
|
||||
@Override
|
||||
@ -185,10 +188,10 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
|
||||
accountId = Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
if (domainId == null) {
|
||||
domainId = Domain.ROOT_DOMAIN;
|
||||
if ( ((accountId != null) && (domainId == -1)) || (domainId == null) )
|
||||
{
|
||||
domainId = _accountDao.getDomainIdForGivenAccountId(accountId);
|
||||
}
|
||||
|
||||
return new Pair<Long, Long>(accountId, domainId);
|
||||
}
|
||||
|
||||
@ -226,6 +229,11 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
|
||||
Pair<Long, Long> accountDomainPair = getAccountDomain(id, resourceType);
|
||||
Long domainId = accountDomainPair.second();
|
||||
Long accountId = accountDomainPair.first();
|
||||
|
||||
if ((domainId != null) && (domainId == -1))
|
||||
{
|
||||
throw new CloudRuntimeException("Invalid DomainId : -1");
|
||||
}
|
||||
if (accountId != null) {
|
||||
_accountMgr.checkAccess(caller, null, false, _accountMgr.getAccount(accountId));
|
||||
} else if (domainId != null && !_accountMgr.isNormalUser(caller.getId())) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user