mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Removed unused methods from BaseCmd class. Moved some helper methods to AccountManagerImpl class
This commit is contained in:
parent
c257fb0e3e
commit
7b0c5cfcbe
@ -269,10 +269,6 @@ public interface ManagementService {
|
||||
*/
|
||||
String generateRandomPassword();
|
||||
|
||||
public Long saveStartedEvent(Long userId, Long accountId, String type, String description, boolean startEventId, Long displayResourceEnabled);
|
||||
|
||||
public Long saveCompletedEvent(Long userId, Long accountId, String level, String type, String description, boolean displayResourceEnabled, long startEventId);
|
||||
|
||||
/**
|
||||
* Search registered key pairs for the logged in user.
|
||||
*
|
||||
|
||||
@ -103,4 +103,6 @@ public interface AccountService {
|
||||
|
||||
void checkAccess(Account account, AccessType accessType, boolean sameOwner, ControlledEntity... entities) throws PermissionDeniedException;
|
||||
|
||||
Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly);
|
||||
|
||||
}
|
||||
|
||||
@ -16,9 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api;
|
||||
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.user.User;
|
||||
|
||||
/**
|
||||
* queryAsyncJobResult API command.
|
||||
@ -92,37 +89,4 @@ public abstract class BaseAsyncCmd extends BaseCmd {
|
||||
public Object getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
protected long saveStartedEvent() {
|
||||
return saveStartedEvent(getEventType(), "Executing job for " + getEventDescription(), getStartEventId());
|
||||
}
|
||||
|
||||
protected long saveStartedEvent(String eventType, String description, Long startEventId) {
|
||||
CallContext ctx = CallContext.current();
|
||||
Long userId = ctx.getCallingUserId();
|
||||
userId = (userId == null) ? User.UID_SYSTEM : userId;
|
||||
Long startEvent = startEventId;
|
||||
if (startEvent == null) {
|
||||
startEvent = 0L;
|
||||
}
|
||||
return _mgr.saveStartedEvent((userId == null) ? User.UID_SYSTEM : userId, getEntityOwnerId(), eventType, description,
|
||||
isDisplayResourceEnabled(), startEvent);
|
||||
}
|
||||
|
||||
protected long saveCompletedEvent(String level, String description) {
|
||||
return saveCompletedEvent(level, getEventType(), description, getStartEventId());
|
||||
}
|
||||
|
||||
protected long saveCompletedEvent(String level, String eventType, String description, Long startEventId) {
|
||||
CallContext ctx = CallContext.current();
|
||||
Long userId = ctx.getCallingUserId();
|
||||
userId = (userId == null) ? User.UID_SYSTEM : userId;
|
||||
Long startEvent = startEventId;
|
||||
if (startEvent == null) {
|
||||
startEvent = 0L;
|
||||
}
|
||||
return _mgr.saveCompletedEvent((userId == null) ? User.UID_SYSTEM : userId, getEntityOwnerId(), level, eventType, description,
|
||||
isDisplayResourceEnabled(), startEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,16 +38,12 @@ import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService;
|
||||
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
|
||||
import org.apache.cloudstack.query.QueryService;
|
||||
import org.apache.cloudstack.usage.UsageService;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.ConfigurationService;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.NetworkModel;
|
||||
@ -65,7 +61,6 @@ import com.cloud.network.vpc.VpcProvisioningService;
|
||||
import com.cloud.network.vpc.VpcService;
|
||||
import com.cloud.network.vpn.RemoteAccessVpnService;
|
||||
import com.cloud.network.vpn.Site2SiteVpnService;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectService;
|
||||
import com.cloud.resource.ResourceService;
|
||||
import com.cloud.server.ManagementService;
|
||||
@ -88,36 +83,28 @@ import com.cloud.vm.snapshot.VMSnapshotService;
|
||||
|
||||
public abstract class BaseCmd {
|
||||
private static final Logger s_logger = Logger.getLogger(BaseCmd.class.getName());
|
||||
|
||||
public static final String USER_ERROR_MESSAGE = "Internal error executing command, please contact your system administrator";
|
||||
public static final int PROGRESS_INSTANCE_CREATED = 1;
|
||||
|
||||
public static final String RESPONSE_TYPE_XML = "xml";
|
||||
public static final String RESPONSE_TYPE_JSON = "json";
|
||||
|
||||
public enum CommandType {
|
||||
public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
||||
public static final DateFormat NEW_INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
public static final String USER_ERROR_MESSAGE = "Internal error executing command, please contact your system administrator";
|
||||
public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+");
|
||||
private static final DateFormat s_outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
protected static final Map<Class<?>, List<Field>> fieldsForCmdClass = new HashMap<Class<?>, List<Field>>();
|
||||
public static enum HTTPMethod {
|
||||
GET, POST, PUT, DELETE
|
||||
}
|
||||
public static enum CommandType {
|
||||
BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID
|
||||
}
|
||||
|
||||
public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
||||
public static final DateFormat NEW_INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+");
|
||||
private static final DateFormat s_outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
|
||||
protected static final Map<Class<?>, List<Field>> fieldsForCmdClass = new HashMap<Class<?>, List<Field>>();
|
||||
|
||||
private Object _responseObject;
|
||||
private Map<String, String> fullUrlParams;
|
||||
|
||||
public enum HTTPMethod {
|
||||
GET, POST, PUT, DELETE
|
||||
}
|
||||
|
||||
private HTTPMethod httpMethod;
|
||||
|
||||
@Parameter(name = "response", type = CommandType.STRING)
|
||||
private String responseType;
|
||||
|
||||
|
||||
@Inject
|
||||
public ConfigurationService _configService;
|
||||
@Inject
|
||||
@ -174,7 +161,6 @@ public abstract class BaseCmd {
|
||||
public NetworkACLService _networkACLService;
|
||||
@Inject
|
||||
public Site2SiteVpnService _s2sVpnService;
|
||||
|
||||
@Inject
|
||||
public QueryService _queryService;
|
||||
@Inject
|
||||
@ -282,10 +268,6 @@ public abstract class BaseCmd {
|
||||
_responseObject = responseObject;
|
||||
}
|
||||
|
||||
public ManagementService getMgmtServiceRef() {
|
||||
return _mgr;
|
||||
}
|
||||
|
||||
public static String getDateString(final Date date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
@ -318,10 +300,6 @@ public abstract class BaseCmd {
|
||||
return filteredFields;
|
||||
}
|
||||
|
||||
protected Account getCurrentContextAccount() {
|
||||
return CallContext.current().getCallingAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method doesn't return all the @{link Parameter}, but only the ones exposed
|
||||
* and allowed for current @{link RoleType}. This method will get the fields for a given
|
||||
@ -334,7 +312,7 @@ public abstract class BaseCmd {
|
||||
public List<Field> getParamFields() {
|
||||
final List<Field> allFields = getAllFieldsForClass(this.getClass());
|
||||
final List<Field> validFields = new ArrayList<Field>();
|
||||
final Account caller = getCurrentContextAccount();
|
||||
final Account caller = CallContext.current().getCallingAccount();
|
||||
|
||||
for (final Field field : allFields) {
|
||||
final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
|
||||
@ -362,20 +340,6 @@ public abstract class BaseCmd {
|
||||
return validFields;
|
||||
}
|
||||
|
||||
protected long getInstanceIdFromJobSuccessResult(final String result) {
|
||||
s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName());
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean isAdmin(final short accountType) {
|
||||
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) ||
|
||||
(accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
|
||||
}
|
||||
|
||||
public static boolean isRootAdmin(final short accountType) {
|
||||
return ((accountType == Account.ACCOUNT_TYPE_ADMIN));
|
||||
}
|
||||
|
||||
public void setFullUrlParams(final Map<String, String> map) {
|
||||
fullUrlParams = map;
|
||||
}
|
||||
@ -384,52 +348,6 @@ public abstract class BaseCmd {
|
||||
return fullUrlParams;
|
||||
}
|
||||
|
||||
public Long finalyzeAccountId(final String accountName, final Long domainId, final Long projectId, final boolean enabledOnly) {
|
||||
if (accountName != null) {
|
||||
if (domainId == null) {
|
||||
throw new InvalidParameterValueException("Account must be specified with domainId parameter");
|
||||
}
|
||||
|
||||
final Domain domain = _domainService.getDomain(domainId);
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("Unable to find domain by id");
|
||||
}
|
||||
|
||||
final Account account = _accountService.getActiveAccountByName(accountName, domainId);
|
||||
if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
|
||||
if (!enabledOnly || account.getState() == Account.State.enabled) {
|
||||
return account.getId();
|
||||
} else {
|
||||
throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() +
|
||||
" as it's no longer active");
|
||||
}
|
||||
} else {
|
||||
// idList is not used anywhere, so removed it now
|
||||
//List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
//idList.add(new IdentityProxy("domain", domainId, "domainId"));
|
||||
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain with specified id");
|
||||
}
|
||||
}
|
||||
|
||||
if (projectId != null) {
|
||||
final Project project = _projectService.getProject(projectId);
|
||||
if (project != null) {
|
||||
if (!enabledOnly || project.getState() == Project.State.Active) {
|
||||
return project.getProjectAccountId();
|
||||
} else {
|
||||
final PermissionDeniedException ex =
|
||||
new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() +
|
||||
" as it's no longer active");
|
||||
ex.addProxyObject(project.getUuid(), "projectId");
|
||||
throw ex;
|
||||
}
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Unable to find project by id");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be overwritten by any class who needs specific validation
|
||||
*/
|
||||
|
||||
@ -18,10 +18,9 @@ package org.apache.cloudstack.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
@ -80,7 +79,7 @@ public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
|
||||
List<String> accountNames = _templateService.listTemplatePermissions(this);
|
||||
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
boolean isAdmin = (isAdmin(account.getType()));
|
||||
boolean isAdmin = (_accountService.isAdmin(account.getType()));
|
||||
|
||||
TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames, id, isAdmin);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.user;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -27,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.UserResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
@ -132,7 +131,7 @@ public class CreateUserCmd extends BaseCmd {
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((account == null) || _accountService.isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
|
||||
if (userAccount != null) {
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.affinitygroup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.affinity.AffinityGroup;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
@ -29,6 +27,7 @@ import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
@ -102,7 +101,7 @@ public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd {
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((account == null) || _accountService.isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
|
||||
if (userAccount != null) {
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.affinitygroup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
@ -29,6 +27,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
@ -105,7 +104,7 @@ public class DeleteAffinityGroupCmd extends BaseAsyncCmd {
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((account == null) || _accountService.isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
|
||||
if (userAccount != null) {
|
||||
|
||||
@ -17,8 +17,6 @@
|
||||
|
||||
package org.apache.cloudstack.api.command.user.autoscale;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -30,6 +28,7 @@ import org.apache.cloudstack.api.response.ConditionResponse;
|
||||
import org.apache.cloudstack.api.response.CounterResponse;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
@ -138,7 +137,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.iso;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -27,6 +25,7 @@ import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
@ -120,7 +119,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
|
||||
public boolean listInReadyState() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
// It is account specific if account is admin type and domainId and accountName are not null
|
||||
boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
|
||||
boolean isAccountSpecific = (account == null || _accountService.isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
|
||||
// Show only those that are downloaded.
|
||||
TemplateFilter templateFilter = TemplateFilter.valueOf(getIsoFilter());
|
||||
boolean onlyReady =
|
||||
|
||||
@ -18,8 +18,6 @@ package org.apache.cloudstack.api.command.user.iso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -33,6 +31,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
@ -182,7 +181,7 @@ public class RegisterIsoCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ public class CreateNetworkCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -19,8 +19,6 @@ package org.apache.cloudstack.api.command.user.region.ha.gslb;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -32,6 +30,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.RegionResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
@ -192,7 +191,7 @@ public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -19,14 +19,13 @@ package org.apache.cloudstack.api.command.user.resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ResourceLimitResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.ResourceLimit;
|
||||
|
||||
@ -78,7 +77,7 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd
|
||||
@Override
|
||||
public void execute() {
|
||||
List<? extends ResourceLimit> result =
|
||||
_resourceLimitService.searchForLimits(id, finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(),
|
||||
_resourceLimitService.searchForLimits(id, _accountService.finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(),
|
||||
resourceType, this.getStartIndex(), this.getPageSizeVal());
|
||||
ListResponse<ResourceLimitResponse> response = new ListResponse<ResourceLimitResponse>();
|
||||
List<ResourceLimitResponse> limitResponses = new ArrayList<ResourceLimitResponse>();
|
||||
|
||||
@ -19,8 +19,6 @@ package org.apache.cloudstack.api.command.user.resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -32,6 +30,7 @@ import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.ResourceCountResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.ResourceCount;
|
||||
import com.cloud.user.Account;
|
||||
@ -107,7 +106,7 @@ public class UpdateResourceCountCmd extends BaseCmd {
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((account == null) || _accountService.isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
|
||||
if (userAccount != null) {
|
||||
@ -126,7 +125,7 @@ public class UpdateResourceCountCmd extends BaseCmd {
|
||||
@Override
|
||||
public void execute() {
|
||||
List<? extends ResourceCount> result =
|
||||
_resourceLimitService.recalculateResourceCount(finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType());
|
||||
_resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType());
|
||||
|
||||
if ((result != null) && (result.size() > 0)) {
|
||||
ListResponse<ResourceCountResponse> response = new ListResponse<ResourceCountResponse>();
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.resource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -28,6 +26,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.ResourceLimitResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.ResourceLimit;
|
||||
|
||||
@ -96,7 +95,7 @@ public class UpdateResourceLimitCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
@ -106,7 +105,7 @@ public class UpdateResourceLimitCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
ResourceLimit result = _resourceLimitService.updateResourceLimit(finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max);
|
||||
ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max);
|
||||
if (result != null || (result == null && max != null && max.longValue() == -1L)) {
|
||||
ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -22,8 +22,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -36,6 +34,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupRuleResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
@ -176,7 +175,7 @@ public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -22,8 +22,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -36,6 +34,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupRuleResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
@ -175,7 +174,7 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.securitygroup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -28,6 +26,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.security.SecurityGroup;
|
||||
import com.cloud.user.Account;
|
||||
@ -97,7 +96,7 @@ public class CreateSecurityGroupCmd extends BaseCmd {
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((account == null) || _accountService.isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
|
||||
if (userAccount != null) {
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.securitygroup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -29,6 +27,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
@ -110,7 +109,7 @@ public class DeleteSecurityGroupCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.ssh;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
@ -26,6 +24,7 @@ import org.apache.cloudstack.api.response.CreateSSHKeyPairResponse;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.SSHKeyPair;
|
||||
|
||||
@ -80,7 +79,7 @@ public class CreateSSHKeyPairCmd extends BaseCmd {
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.ssh;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
@ -26,6 +24,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@ -91,7 +90,7 @@ public class DeleteSSHKeyPairCmd extends BaseCmd {
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((account == null) || _accountService.isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
|
||||
if (userAccount != null) {
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.ssh;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
@ -26,6 +24,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SSHKeyPairResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.SSHKeyPair;
|
||||
|
||||
@ -88,7 +87,7 @@ public class RegisterSSHKeyPairCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.template;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -27,6 +25,7 @@ import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
@ -101,7 +100,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
|
||||
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
// It is account specific if account is admin type and domainId and accountName are not null
|
||||
boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
|
||||
boolean isAccountSpecific = (account == null || _accountService.isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
|
||||
// Show only those that are downloaded.
|
||||
TemplateFilter templateFilter = TemplateFilter.valueOf(getTemplateFilter());
|
||||
boolean onlyReady =
|
||||
|
||||
@ -21,8 +21,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -37,6 +35,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
@ -252,7 +251,7 @@ public class RegisterTemplateCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -381,7 +381,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vmgroup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -28,6 +26,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
|
||||
@ -90,7 +89,7 @@ public class CreateVMGroupCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -29,6 +27,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
@ -149,7 +148,7 @@ public class UploadVolumeCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vpn;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -28,6 +26,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.VpnUsersResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.event.EventTypes;
|
||||
@ -97,7 +96,7 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vpn;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -27,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.network.Site2SiteCustomerGateway;
|
||||
@ -143,7 +142,7 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
|
||||
if (accountId == null) {
|
||||
accountId = CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vpn;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -28,6 +26,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.user.Account;
|
||||
@ -88,7 +87,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vpn;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -27,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
@ -82,7 +81,7 @@ public class ResetVpnConnectionCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vpn;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
@ -27,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.network.Site2SiteCustomerGateway;
|
||||
@ -146,7 +145,7 @@ public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
|
||||
if (accountId == null) {
|
||||
accountId = CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ public class CreateServiceInstanceCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||
if (accountId == null) {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
@ -23,8 +23,6 @@ import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
@ -33,6 +31,7 @@ import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
import com.cloud.configuration.ResourceLimit;
|
||||
@ -347,4 +346,10 @@ public class MockAccountManager extends ManagerBase implements AccountManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,12 +19,10 @@ package com.cloud.acl;
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.SecurityChecker;
|
||||
import org.apache.cloudstack.affinity.AffinityGroup;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DedicatedResourceVO;
|
||||
@ -104,7 +102,7 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
|
||||
Account owner = _accountDao.findById(template.getAccountId());
|
||||
// validate that the template is usable by the account
|
||||
if (!template.isPublicTemplate()) {
|
||||
if (BaseCmd.isRootAdmin(caller.getType()) || (owner.getId() == caller.getId())) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || (owner.getId() == caller.getId())) {
|
||||
return true;
|
||||
}
|
||||
//special handling for the project case
|
||||
@ -121,7 +119,7 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
|
||||
} else {
|
||||
// Domain admin and regular user can delete/modify only templates created by them
|
||||
if (accessType != null && accessType == AccessType.ModifyEntry) {
|
||||
if (!BaseCmd.isRootAdmin(caller.getType()) && owner.getId() != caller.getId()) {
|
||||
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && owner.getId() != caller.getId()) {
|
||||
// For projects check if the caller account can access the project account
|
||||
if (owner.getType() != Account.ACCOUNT_TYPE_PROJECT || !(_projectMgr.canAccessProjectAccount(caller, owner.getId()))) {
|
||||
throw new PermissionDeniedException("Domain Admin and regular users can modify only their own Public templates");
|
||||
|
||||
@ -53,37 +53,6 @@ import javax.naming.ConfigurationException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.ConnectionClosedException;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpServerConnection;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.impl.DefaultHttpResponseFactory;
|
||||
import org.apache.http.impl.DefaultHttpServerConnection;
|
||||
import org.apache.http.impl.NoConnectionReuseStrategy;
|
||||
import org.apache.http.impl.SocketHttpServerConnection;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.BasicHttpProcessor;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
import org.apache.http.protocol.HttpRequestHandlerRegistry;
|
||||
import org.apache.http.protocol.HttpService;
|
||||
import org.apache.http.protocol.ResponseConnControl;
|
||||
import org.apache.http.protocol.ResponseContent;
|
||||
import org.apache.http.protocol.ResponseDate;
|
||||
import org.apache.http.protocol.ResponseServer;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.acl.APIChecker;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -122,6 +91,36 @@ import org.apache.cloudstack.framework.jobs.AsyncJob;
|
||||
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
|
||||
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
|
||||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.ConnectionClosedException;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpServerConnection;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.impl.DefaultHttpResponseFactory;
|
||||
import org.apache.http.impl.DefaultHttpServerConnection;
|
||||
import org.apache.http.impl.NoConnectionReuseStrategy;
|
||||
import org.apache.http.impl.SocketHttpServerConnection;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.BasicHttpProcessor;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
import org.apache.http.protocol.HttpRequestHandlerRegistry;
|
||||
import org.apache.http.protocol.HttpService;
|
||||
import org.apache.http.protocol.ResponseConnControl;
|
||||
import org.apache.http.protocol.ResponseContent;
|
||||
import org.apache.http.protocol.ResponseDate;
|
||||
import org.apache.http.protocol.ResponseServer;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.dispatch.DispatchChainFactory;
|
||||
import com.cloud.api.dispatch.DispatchTask;
|
||||
|
||||
@ -24,15 +24,13 @@ import java.util.Map;
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseHelper;
|
||||
@ -44,6 +42,7 @@ import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
@ -59,6 +58,8 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
|
||||
@Inject
|
||||
private ConfigurationDao _configDao;
|
||||
@Inject
|
||||
private AccountService _accountService;
|
||||
|
||||
private final SearchBuilder<TemplateJoinVO> tmpltIdPairSearch;
|
||||
|
||||
@ -98,7 +99,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
private String getTemplateStatus(TemplateJoinVO template) {
|
||||
boolean isAdmin = false;
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
if ((caller == null) || _accountService.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
@ -307,7 +308,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
boolean isAdmin = false;
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
if ((caller == null) || _accountService.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
|
||||
@ -3300,16 +3300,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long saveStartedEvent(Long userId, Long accountId, String type, String description, boolean displayResourceEnabled, Long startEventId) {
|
||||
return ActionEventUtils.onStartedActionEvent(userId, accountId, type, description, displayResourceEnabled, startEventId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long saveCompletedEvent(Long userId, Long accountId, String level, String type, String description, boolean displayResourceEnabled, long startEventId) {
|
||||
return ActionEventUtils.onCompletedActionEvent(userId, accountId, level, type, displayResourceEnabled, description, startEventId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public String uploadCertificate(UploadCustomCertificateCmd cmd) {
|
||||
|
||||
@ -2326,4 +2326,52 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
public UserAccount getUserByApiKey(String apiKey) {
|
||||
return _userAccountDao.getUserByApiKey(apiKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long finalyzeAccountId(final String accountName, final Long domainId, final Long projectId, final boolean enabledOnly) {
|
||||
if (accountName != null) {
|
||||
if (domainId == null) {
|
||||
throw new InvalidParameterValueException("Account must be specified with domainId parameter");
|
||||
}
|
||||
|
||||
final Domain domain = _domainMgr.getDomain(domainId);
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("Unable to find domain by id");
|
||||
}
|
||||
|
||||
final Account account = getActiveAccountByName(accountName, domainId);
|
||||
if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
|
||||
if (!enabledOnly || account.getState() == Account.State.enabled) {
|
||||
return account.getId();
|
||||
} else {
|
||||
throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() +
|
||||
" as it's no longer active");
|
||||
}
|
||||
} else {
|
||||
// idList is not used anywhere, so removed it now
|
||||
// List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
// idList.add(new IdentityProxy("domain", domainId, "domainId"));
|
||||
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain with specified id");
|
||||
}
|
||||
}
|
||||
|
||||
if (projectId != null) {
|
||||
final Project project = _projectMgr.getProject(projectId);
|
||||
if (project != null) {
|
||||
if (!enabledOnly || project.getState() == Project.State.Active) {
|
||||
return project.getProjectAccountId();
|
||||
} else {
|
||||
final PermissionDeniedException ex =
|
||||
new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() +
|
||||
" as it's no longer active");
|
||||
ex.addProxyObject(project.getUuid(), "projectId");
|
||||
throw ex;
|
||||
}
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Unable to find project by id");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,16 +16,15 @@
|
||||
// under the License.
|
||||
package com.cloud.api.dispatch;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -33,6 +32,9 @@ import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
@ -40,8 +42,9 @@ import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserVO;
|
||||
|
||||
public class ParamGenericValidationWorkerTest {
|
||||
|
||||
@ -55,9 +58,9 @@ public class ParamGenericValidationWorkerTest {
|
||||
final ParamGenericValidationWorker genValidationWorker = new ParamGenericValidationWorker();
|
||||
|
||||
// We create a mock logger to verify the result
|
||||
ParamGenericValidationWorker.s_logger = new Logger(""){
|
||||
ParamGenericValidationWorker.s_logger = new Logger("") {
|
||||
@Override
|
||||
public void warn(final Object msg){
|
||||
public void warn(final Object msg) {
|
||||
loggerOutput = msg.toString();
|
||||
}
|
||||
};
|
||||
@ -74,8 +77,15 @@ public class ParamGenericValidationWorkerTest {
|
||||
params.put(ApiConstants.COMMAND, "");
|
||||
params.put("addedParam", "");
|
||||
|
||||
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
|
||||
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
|
||||
CallContext.register(user, account);
|
||||
// Execute
|
||||
driveTest(cmd, params);
|
||||
try {
|
||||
driveTest(cmd, params);
|
||||
} finally {
|
||||
CallContext.unregister();
|
||||
}
|
||||
|
||||
// Assert
|
||||
assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput);
|
||||
@ -91,8 +101,16 @@ public class ParamGenericValidationWorkerTest {
|
||||
params.put("addedParam", "");
|
||||
params.put(unknownParamKey, "");
|
||||
|
||||
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
|
||||
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
|
||||
CallContext.register(user, account);
|
||||
|
||||
// Execute
|
||||
driveTest(cmd, params);
|
||||
try {
|
||||
driveTest(cmd, params);
|
||||
} finally {
|
||||
CallContext.unregister();
|
||||
}
|
||||
|
||||
// Assert
|
||||
assertTrue("There should be error msg, since there is one unknown parameter", loggerOutput.contains(unknownParamKey));
|
||||
@ -102,6 +120,7 @@ public class ParamGenericValidationWorkerTest {
|
||||
@Test
|
||||
public void testHandleWithoutAuthorization() throws ResourceAllocationException {
|
||||
final short type = Account.ACCOUNT_TYPE_NORMAL;
|
||||
|
||||
driveAuthTest(type);
|
||||
|
||||
// Assert
|
||||
@ -112,25 +131,33 @@ public class ParamGenericValidationWorkerTest {
|
||||
@Test
|
||||
public void testHandleWithAuthorization() throws ResourceAllocationException {
|
||||
final short type = Account.ACCOUNT_TYPE_ADMIN;
|
||||
driveAuthTest(type);
|
||||
|
||||
driveAuthTest(type);
|
||||
// Assert
|
||||
assertEquals("There should be no errors since parameters have authorization", null, loggerOutput);
|
||||
}
|
||||
|
||||
protected void driveAuthTest(final short type) {
|
||||
|
||||
// Prepare
|
||||
final BaseCmd cmd = new FakeCmdWithRoleAdmin();
|
||||
final Account account = mock(Account.class);
|
||||
((FakeCmdWithRoleAdmin)cmd).account = account;
|
||||
when(account.getType()).thenReturn(type);
|
||||
User user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
|
||||
CallContext.register(user, account);
|
||||
|
||||
final Map<String, String> params = new HashMap<String, String>();
|
||||
params.put(ApiConstants.COMMAND, "");
|
||||
params.put("addedParam", "");
|
||||
params.put("paramWithRole", "");
|
||||
|
||||
// Execute
|
||||
driveTest(cmd, params);
|
||||
try {
|
||||
driveTest(cmd, params);
|
||||
} finally {
|
||||
CallContext.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,11 +170,6 @@ class FakeCmd extends BaseCmd {
|
||||
|
||||
public Account account;
|
||||
|
||||
@Override
|
||||
protected Account getCurrentContextAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
//
|
||||
// Dummy methods for mere correct compilation
|
||||
//
|
||||
|
||||
@ -22,8 +22,6 @@ import java.util.Map;
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
@ -31,6 +29,7 @@ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
import com.cloud.domain.Domain;
|
||||
@ -322,4 +321,10 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user