Fix issues found through FindBugs.

This commit is contained in:
Min Chen 2014-03-11 11:49:48 -07:00
parent 1c85af3193
commit b554d4ac1f
5 changed files with 21 additions and 12 deletions

View File

@ -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<? extends ResourceDetail> detailList = new ArrayList<ResourceDetail>();
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<ResourceDetailResponse> responseList = new ArrayList<ResourceDetailResponse>();
if (requestedDetail != null) {

View File

@ -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 /////////////////////

View File

@ -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;

View File

@ -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

View File

@ -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;