@@ -363,6 +363,9 @@ public AccountVO getSystemAccount() {
363363 public boolean isAdmin (Long accountId ) {
364364 if (accountId != null ) {
365365 AccountVO acct = _accountDao .findById (accountId );
366+ if (acct == null ) {
367+ return false ; //account is deleted or does not exist
368+ }
366369 if ((isRootAdmin (accountId )) || (isDomainAdmin (accountId )) || (isResourceDomainAdmin (accountId ))) {
367370 return true ;
368371 } else if (acct .getType () == Account .ACCOUNT_TYPE_READ_ONLY_ADMIN ) {
@@ -377,6 +380,9 @@ public boolean isAdmin(Long accountId) {
377380 public boolean isRootAdmin (Long accountId ) {
378381 if (accountId != null ) {
379382 AccountVO acct = _accountDao .findById (accountId );
383+ if (acct == null ) {
384+ return false ; //account is deleted or does not exist
385+ }
380386 for (SecurityChecker checker : _securityCheckers ) {
381387 try {
382388 if (checker .checkAccess (acct , null , null , "SystemCapability" )) {
@@ -397,6 +403,9 @@ public boolean isRootAdmin(Long accountId) {
397403 public boolean isDomainAdmin (Long accountId ) {
398404 if (accountId != null ) {
399405 AccountVO acct = _accountDao .findById (accountId );
406+ if (acct == null ) {
407+ return false ; //account is deleted or does not exist
408+ }
400409 for (SecurityChecker checker : _securityCheckers ) {
401410 try {
402411 if (checker .checkAccess (acct , null , null , "DomainCapability" )) {
@@ -425,6 +434,9 @@ public boolean isNormalUser(long accountId) {
425434 public boolean isResourceDomainAdmin (Long accountId ) {
426435 if (accountId != null ) {
427436 AccountVO acct = _accountDao .findById (accountId );
437+ if (acct == null ) {
438+ return false ; //account is deleted or does not exist
439+ }
428440 for (SecurityChecker checker : _securityCheckers ) {
429441 try {
430442 if (checker .checkAccess (acct , null , null , "DomainResourceCapability" )) {
@@ -443,6 +455,9 @@ public boolean isResourceDomainAdmin(Long accountId) {
443455
444456 public boolean isInternalAccount (long accountId ) {
445457 Account account = _accountDao .findById (accountId );
458+ if (account == null ) {
459+ return false ; //account is deleted or does not exist
460+ }
446461 if (isRootAdmin (accountId ) || (account .getType () == Account .ACCOUNT_ID_SYSTEM )) {
447462 return true ;
448463 }
@@ -1138,14 +1153,17 @@ public UserAccount updateUser(UpdateUserCmd cmd) {
11381153
11391154 // If the account is an admin type, return an error. We do not allow this
11401155 Account account = _accountDao .findById (user .getAccountId ());
1156+ if (account == null ) {
1157+ throw new InvalidParameterValueException ("unable to find user account " + user .getAccountId ());
1158+ }
11411159
11421160 // don't allow updating project account
11431161 if (account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
11441162 throw new InvalidParameterValueException ("unable to find user by id" );
11451163 }
11461164
11471165 // don't allow updating system account
1148- if (account != null && ( account .getId () == Account .ACCOUNT_ID_SYSTEM ) ) {
1166+ if (account .getId () == Account .ACCOUNT_ID_SYSTEM ) {
11491167 throw new PermissionDeniedException ("user id : " + id + " is system account, update is not allowed" );
11501168 }
11511169
@@ -1252,6 +1270,9 @@ public UserAccount disableUser(long userId) {
12521270 }
12531271
12541272 Account account = _accountDao .findById (user .getAccountId ());
1273+ if (account == null ) {
1274+ throw new InvalidParameterValueException ("unable to find user account " + user .getAccountId ());
1275+ }
12551276
12561277 // don't allow disabling user belonging to project's account
12571278 if (account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
@@ -1291,6 +1312,9 @@ public UserAccount enableUser(final long userId) {
12911312 }
12921313
12931314 Account account = _accountDao .findById (user .getAccountId ());
1315+ if (account == null ) {
1316+ throw new InvalidParameterValueException ("unable to find user account " + user .getAccountId ());
1317+ }
12941318
12951319 if (account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
12961320 throw new InvalidParameterValueException ("Unable to find active user by id " + userId );
@@ -1339,6 +1363,9 @@ public UserAccount lockUser(long userId) {
13391363 }
13401364
13411365 Account account = _accountDao .findById (user .getAccountId ());
1366+ if (account == null ) {
1367+ throw new InvalidParameterValueException ("unable to find user account " + user .getAccountId ());
1368+ }
13421369
13431370 // don't allow to lock user of the account of type Project
13441371 if (account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
@@ -1404,7 +1431,7 @@ boolean deleteUserAccount(long accountId) {
14041431 // If the user is a System user, return an error. We do not allow this
14051432 AccountVO account = _accountDao .findById (accountId );
14061433
1407- if (account .getRemoved () != null ) {
1434+ if (account == null || account .getRemoved () != null ) {
14081435 s_logger .info ("The account:" + account .getAccountName () + " is already removed" );
14091436 return true ;
14101437 }
0 commit comments