diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 564bf4ed25e..96647f82113 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -3314,17 +3314,20 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (resourceIdStr != null) { resourceId = _taggedResourceMgr.getResourceId(resourceIdStr, resourceType); } + if (resourceId == null) { + throw new InvalidParameterValueException("Cannot find resource with resourceId " + resourceIdStr + " and of resource type " + resourceType); + } List detailList = new ArrayList(); ResourceDetail requestedDetail = null; - if (key == null) { + if (key == null) { detailList = _resourceMetaDataMgr.getDetailsList(resourceId, resourceType, forDisplay); - } else { + } else { requestedDetail = _resourceMetaDataMgr.getDetail(resourceId, resourceType, key); if (forDisplay != null && requestedDetail.isDisplay() != forDisplay) { requestedDetail = null; } - } + } List responseList = new ArrayList(); if (requestedDetail != null) { diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java index e9915378291..d37cc3cb7b6 100644 --- a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java +++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java @@ -39,7 +39,6 @@ import com.cloud.event.EventTypes; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; -import com.cloud.utils.db.EntityManager; @APICommand(name = "addIAMPermissionToIAMPolicy", description = "Add IAM permission to an iam policy", responseObject = IAMPolicyResponse.class) @@ -49,8 +48,6 @@ public class AddIAMPermissionToIAMPolicyCmd extends BaseAsyncCmd { @Inject public IAMApiService _iamApiSrv; - @Inject - public EntityManager _entityMgr; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java index b7af4dad4b2..5def248d7a8 100644 --- a/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java +++ b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java @@ -108,13 +108,13 @@ public class IAMPermissionResponse extends BaseResponse { if (getClass() != obj.getClass()) return false; IAMPermissionResponse other = (IAMPermissionResponse) obj; - if ((entityType == null && other.entityType != null) || !entityType.equals(other.entityType)) { + if ((entityType == null && other.entityType != null) || (entityType != null && !entityType.equals(other.entityType))) { return false; - } else if ((action == null && other.action != null) || !action.equals(other.action)) { + } else if ((action == null && other.action != null) || (action != null && !action.equals(other.action))) { return false; - } else if ((scope == null && other.scope != null) || !scope.equals(other.scope)) { + } else if ((scope == null && other.scope != null) || (scope != null && !scope.equals(other.scope))) { return false; - } else if ((scopeId == null && other.scopeId != null) || !scopeId.equals(other.scopeId)) { + } else if ((scopeId == null && other.scopeId != null) || (scopeId != null && !scopeId.equals(other.scopeId))) { return false; } return true; diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java b/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java index 47b7697124d..9e941f20e22 100644 --- a/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java +++ b/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java @@ -591,8 +591,9 @@ public class IAMApiServiceImpl extends ManagerBase implements IAMApiService, Man if (BaseListCmd.class.isAssignableFrom(cmdClass)) { accessType = AccessType.UseEntry; } + String accessTypeStr = (accessType != null) ? accessType.toString() : null; return _iamSrv.addIAMPermissionToIAMPolicy(iamPolicyId, entityType, scope.toString(), scopeId, action, - accessType.toString(), perm, recursive); + accessTypeStr, perm, recursive); } @DB diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java index d0d9d88120e..02bb7022eed 100644 --- a/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java +++ b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java @@ -35,6 +35,7 @@ import org.apache.cloudstack.iam.api.IAMService; import com.cloud.acl.DomainChecker; import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.user.Account; import com.cloud.user.AccountService; @@ -73,7 +74,14 @@ public class RoleBasedEntityAccessChecker extends DomainChecker implements Secur return true; } - String entityType = entity.getEntityType().toString(); + if (entity == null) { + throw new InvalidParameterValueException("Entity and action cannot be both NULL in checkAccess!"); + } + + String entityType = null; + if (entity.getEntityType() != null) { + entityType = entity.getEntityType().toString(); + } if (accessType == null) { accessType = AccessType.UseEntry;