cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject git commit: updated refs/heads/4.4 to 6c0b434
Date Fri, 06 Jun 2014 13:55:12 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4 0b08d5319 -> 6c0b43431


CLOUDSTACK-6793: Fixed an invalid Domain Id Issue

Signed-off-by: sedukull <santhosh.edukulla@gmail.com>
(cherry picked from commit 91d054cb00f6a5818f2be1c7e4d3f44a2c58bfcc)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6c0b4343
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6c0b4343
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6c0b4343

Branch: refs/heads/4.4
Commit: 6c0b43431f7f117c1fcb049c483407b96b56d961
Parents: 0b08d53
Author: sedukull <santhosh.edukulla@gmail.com>
Authored: Fri Jun 6 13:48:13 2014 +0530
Committer: Daan Hoogland <daan@onecht.net>
Committed: Fri Jun 6 15:54:45 2014 +0200

----------------------------------------------------------------------
 .../schema/src/com/cloud/user/dao/AccountDao.java   |  9 +++++++++
 .../src/com/cloud/user/dao/AccountDaoImpl.java      | 16 ++++++++++++++++
 .../com/cloud/tags/TaggedResourceManagerImpl.java   | 16 ++++++++++++----
 3 files changed, 37 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6c0b4343/engine/schema/src/com/cloud/user/dao/AccountDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/user/dao/AccountDao.java b/engine/schema/src/com/cloud/user/dao/AccountDao.java
index 2f737cd..4c7ce8e 100644
--- a/engine/schema/src/com/cloud/user/dao/AccountDao.java
+++ b/engine/schema/src/com/cloud/user/dao/AccountDao.java
@@ -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);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6c0b4343/engine/schema/src/com/cloud/user/dao/AccountDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/user/dao/AccountDaoImpl.java b/engine/schema/src/com/cloud/user/dao/AccountDaoImpl.java
index 4bc23ed..99bd7ee 100755
--- a/engine/schema/src/com/cloud/user/dao/AccountDaoImpl.java
+++ b/engine/schema/src/com/cloud/user/dao/AccountDaoImpl.java
@@ -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;
+        }
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6c0b4343/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
index fa7fcb7..2ccab0b 100644
--- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
+++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
@@ -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()))
{


Mime
View raw message