Repository: cloudstack
Updated Branches:
  refs/heads/master f21e52792 -> 51cb0f9a4


CLOUDSTACK-6598:IAM - listAccount() retrurns "Caller cannot be passed as
NULL to IAM!" when domain deletion is in progress.


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

Branch: refs/heads/master
Commit: 51cb0f9a4a58d772d822a8f90fd0e29523e384c9
Parents: 218158b
Author: Min Chen <[email protected]>
Authored: Thu May 8 15:19:23 2014 -0700
Committer: Min Chen <[email protected]>
Committed: Thu May 8 17:56:20 2014 -0700

----------------------------------------------------------------------
 .../resourcelimit/ResourceLimitManagerImpl.java |  6 ++++
 .../src/com/cloud/user/AccountManagerImpl.java  | 31 ++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/51cb0f9a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java 
b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index 2b5d976..0c0c588 100755
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -325,6 +325,9 @@ public class ResourceLimitManagerImpl extends ManagerBase 
implements ResourceLim
         }
 
         Account account = _accountDao.findById(accountId);
+        if (account == null) {
+            return max;
+        }
 
         // Check if limit is configured for account
         if (limit != null) {
@@ -633,6 +636,9 @@ public class ResourceLimitManagerImpl extends ManagerBase 
implements ResourceLim
 
         if (accountId != null) {
             Account account = _entityMgr.findById(Account.class, accountId);
+            if (account == null) {
+                throw new InvalidParameterValueException("Unable to find 
account " + accountId);
+            }
             if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
                 throw new InvalidParameterValueException("Can't update system 
account");
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/51cb0f9a/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java 
b/server/src/com/cloud/user/AccountManagerImpl.java
index 1db977a..a2f3b09 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -355,6 +355,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
     public boolean isAdmin(Long accountId) {
         if (accountId != null) {
             AccountVO acct = _accountDao.findById(accountId);
+            if (acct == null) {
+                return false;  //account is deleted or does not exist
+            }
             if ((isRootAdmin(accountId)) || (isDomainAdmin(accountId)) || 
(isResourceDomainAdmin(accountId))) {
                 return true;
             } else if (acct.getType() == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN) 
{
@@ -369,6 +372,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
     public boolean isRootAdmin(Long accountId) {
         if (accountId != null) {
             AccountVO acct = _accountDao.findById(accountId);
+            if (acct == null) {
+                return false;  //account is deleted or does not exist
+            }
             for (SecurityChecker checker : _securityCheckers) {
                 try {
                     if (checker.checkAccess(acct, null, null, 
"SystemCapability")) {
@@ -389,6 +395,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
     public boolean isDomainAdmin(Long accountId) {
         if (accountId != null) {
             AccountVO acct = _accountDao.findById(accountId);
+            if (acct == null) {
+                return false;  //account is deleted or does not exist
+            }
             for (SecurityChecker checker : _securityCheckers) {
                 try {
                     if (checker.checkAccess(acct, null, null, 
"DomainCapability")) {
@@ -417,6 +426,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
     public boolean isResourceDomainAdmin(Long accountId) {
         if (accountId != null) {
             AccountVO acct = _accountDao.findById(accountId);
+            if (acct == null) {
+                return false;  //account is deleted or does not exist
+            }
             for (SecurityChecker checker : _securityCheckers) {
                 try {
                     if (checker.checkAccess(acct, null, null, 
"DomainResourceCapability")) {
@@ -435,6 +447,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
 
     public boolean isInternalAccount(long accountId) {
         Account account = _accountDao.findById(accountId);
+        if (account == null) {
+            return false;  //account is deleted or does not exist
+        }
         if (isRootAdmin(accountId) || (account.getType() == 
Account.ACCOUNT_ID_SYSTEM)) {
             return true;
         }
@@ -1051,6 +1066,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
 
         // If the account is an admin type, return an error. We do not allow 
this
         Account account = _accountDao.findById(user.getAccountId());
+        if (account == null) {
+            throw new InvalidParameterValueException("unable to find user 
account " + user.getAccountId());
+        }
 
         // don't allow updating project account
         if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
@@ -1058,7 +1076,7 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
         }
 
         // don't allow updating system account
-        if (account != null && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) 
{
+        if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
             throw new PermissionDeniedException("user id : " + id + " is 
system account, update is not allowed");
         }
 
@@ -1165,6 +1183,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
         }
 
         Account account = _accountDao.findById(user.getAccountId());
+        if (account == null) {
+            throw new InvalidParameterValueException("unable to find user 
account " + user.getAccountId());
+        }
 
         // don't allow disabling user belonging to project's account
         if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
@@ -1204,6 +1225,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
         }
 
         Account account = _accountDao.findById(user.getAccountId());
+        if (account == null) {
+            throw new InvalidParameterValueException("unable to find user 
account " + user.getAccountId());
+        }
 
         if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
             throw new InvalidParameterValueException("Unable to find active 
user by id " + userId);
@@ -1252,6 +1276,9 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
         }
 
         Account account = _accountDao.findById(user.getAccountId());
+        if (account == null) {
+            throw new InvalidParameterValueException("unable to find user 
account " + user.getAccountId());
+        }
 
         // don't allow to lock user of the account of type Project
         if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
@@ -1316,7 +1343,7 @@ public class AccountManagerImpl extends ManagerBase 
implements AccountManager, M
         // If the user is a System user, return an error. We do not allow this
         AccountVO account = _accountDao.findById(accountId);
 
-        if (account.getRemoved() != null) {
+        if (account == null || account.getRemoved() != null) {
             s_logger.info("The account:" + account.getAccountName() + " is 
already removed");
             return true;
         }

Reply via email to