mirror of https://github.com/apache/cloudstack.git
Clean up SecurityChecker.AccessType and modify code to use them
consistently.
This commit is contained in:
parent
4b75fa806a
commit
586ee74000
|
|
@ -31,11 +31,8 @@ import com.cloud.utils.component.Adapter;
|
|||
public interface SecurityChecker extends Adapter {
|
||||
|
||||
public enum AccessType {
|
||||
ListEntry,
|
||||
ModifyEntry,
|
||||
ModifyProject,
|
||||
UseNetwork,
|
||||
DeleteEntry,
|
||||
OperateEntry,
|
||||
UseEntry
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class AffinityGroupAccessChecker extends DomainChecker {
|
|||
AffinityGroup group = (AffinityGroup)entity;
|
||||
|
||||
if (_affinityGroupService.isAdminControlledGroup(group)) {
|
||||
if (accessType != null && accessType == AccessType.ModifyEntry
|
||||
if (accessType != null && accessType == AccessType.OperateEntry
|
||||
&& !_accountMgr.isRootAdmin(caller.getId())) {
|
||||
throw new PermissionDeniedException(caller + " does not have permission to operate with resource "
|
||||
+ entity);
|
||||
|
|
|
|||
|
|
@ -123,7 +123,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 (accessType != null && accessType == AccessType.OperateEntry) {
|
||||
if (!_accountService.isRootAdmin(caller.getId()) && 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()))) {
|
||||
|
|
|
|||
|
|
@ -1815,7 +1815,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
}
|
||||
|
||||
// do a permission check
|
||||
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
|
||||
_accountMgr.checkAccess(account, AccessType.OperateEntry, true, template);
|
||||
|
||||
if(cmd.isRoutingType() != null){
|
||||
if (!_accountService.isRootAdmin(account.getId())) {
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
throw new InvalidParameterValueException("Unable to find template id=" + templateId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.ModifyEntry, true, vmTemplate);
|
||||
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.OperateEntry, true, vmTemplate);
|
||||
|
||||
prepareTemplateInAllStoragePools(vmTemplate, zoneId);
|
||||
return vmTemplate;
|
||||
|
|
@ -413,7 +413,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
throw new InvalidParameterValueException("Unable to extract template id=" + templateId + " as it's not extractable");
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
|
||||
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
|
||||
|
||||
List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||
|
||||
|
|
@ -689,7 +689,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
return template;
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
|
||||
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
|
||||
|
||||
boolean success = copy(userId, template, srcSecStore, dstZone);
|
||||
|
||||
|
|
@ -1028,7 +1028,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
throw new InvalidParameterValueException("unable to find template with id " + templateId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
|
||||
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
|
||||
|
||||
if (template.getFormat() == ImageFormat.ISO) {
|
||||
throw new InvalidParameterValueException("Please specify a valid template.");
|
||||
|
|
@ -1051,7 +1051,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
throw new InvalidParameterValueException("unable to find iso with id " + templateId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
|
||||
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
|
||||
|
||||
if (template.getFormat() != ImageFormat.ISO) {
|
||||
throw new InvalidParameterValueException("Please specify a valid iso.");
|
||||
|
|
@ -1752,7 +1752,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
}
|
||||
|
||||
// do a permission check
|
||||
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
|
||||
_accountMgr.checkAccess(account, AccessType.OperateEntry, true, template);
|
||||
if (cmd.isRoutingType() != null) {
|
||||
if (!_accountService.isRootAdmin(account.getId())) {
|
||||
throw new PermissionDeniedException("Parameter isrouting can only be specified by a Root Admin, permission denied");
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import javax.ejb.Local;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.AclEntityType;
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
|
|
@ -263,7 +263,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
|
|||
affinityGroupId = group.getId();
|
||||
}
|
||||
// check permissions
|
||||
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, group);
|
||||
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, group);
|
||||
|
||||
final Long affinityGroupIdFinal = affinityGroupId;
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
|
|
|
|||
|
|
@ -53,17 +53,18 @@ import javax.crypto.NoSuchPaddingException;
|
|||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.openssl.PEMReader;
|
||||
import org.bouncycastle.openssl.PasswordFinder;
|
||||
|
||||
import org.apache.cloudstack.acl.SecurityChecker;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.DeleteSslCertCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.ListSslCertsCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd;
|
||||
import org.apache.cloudstack.api.response.SslCertResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.openssl.PEMReader;
|
||||
import org.bouncycastle.openssl.PasswordFinder;
|
||||
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.EventTypes;
|
||||
|
|
@ -146,7 +147,7 @@ public class CertServiceImpl implements CertService {
|
|||
if (certVO == null) {
|
||||
throw new InvalidParameterValueException("Invalid certificate id: " + certId);
|
||||
}
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, certVO);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, certVO);
|
||||
|
||||
List<LoadBalancerCertMapVO> lbCertRule = _lbCertDao.listByCertId(certId);
|
||||
|
||||
|
|
@ -190,7 +191,7 @@ public class CertServiceImpl implements CertService {
|
|||
throw new InvalidParameterValueException("Invalid certificate id: " + certId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ListEntry, true, certVO);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVO);
|
||||
|
||||
certLbMap = _lbCertDao.listByCertId(certId);
|
||||
|
||||
|
|
@ -205,7 +206,7 @@ public class CertServiceImpl implements CertService {
|
|||
throw new InvalidParameterValueException("found no loadbalancer wth id: " + lbRuleId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ListEntry, true, lb);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, lb);
|
||||
|
||||
// get the cert id
|
||||
LoadBalancerCertMapVO lbCertMapRule;
|
||||
|
|
@ -228,7 +229,7 @@ public class CertServiceImpl implements CertService {
|
|||
List<SslCertVO> certVOList = _sslCertDao.listByAccountId(accountId);
|
||||
if (certVOList == null || certVOList.isEmpty())
|
||||
return certResponseList;
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ListEntry, true, certVOList.get(0));
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVOList.get(0));
|
||||
|
||||
for (SslCertVO cert : certVOList) {
|
||||
certLbMap = _lbCertDao.listByCertId(cert.getId());
|
||||
|
|
@ -486,7 +487,7 @@ public class CertServiceImpl implements CertService {
|
|||
char[] password;
|
||||
|
||||
KeyPassword(char[] word) {
|
||||
this.password = word;
|
||||
password = word;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
protected GslbServiceProvider _gslbProvider = null;
|
||||
|
||||
public void setGslbServiceProvider(GslbServiceProvider provider) {
|
||||
this._gslbProvider = provider;
|
||||
_gslbProvider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -183,7 +183,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
|
||||
|
||||
if (gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke) {
|
||||
throw new InvalidParameterValueException("global load balancer rule id: " + gslbRule.getUuid() + " is in revoked state");
|
||||
|
|
@ -319,7 +319,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
|
||||
|
||||
if (gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke) {
|
||||
throw new InvalidParameterValueException("global load balancer rule id: " + gslbRuleId + " is already in revoked state");
|
||||
|
|
@ -445,7 +445,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
|
||||
|
||||
if (gslbRule.getState() == com.cloud.region.ha.GlobalLoadBalancerRule.State.Staged) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -523,7 +523,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
CallContext ctx = CallContext.current();
|
||||
Account caller = ctx.getCallingAccount();
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
|
||||
|
||||
if (algorithm != null && !GlobalLoadBalancerRule.Algorithm.isValidAlgorithm(algorithm)) {
|
||||
throw new InvalidParameterValueException("Invalid Algorithm: " + algorithm);
|
||||
|
|
@ -583,7 +583,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
if (gslbRule == null) {
|
||||
throw new InvalidParameterValueException("Invalid gslb rule id specified");
|
||||
}
|
||||
_accountMgr.checkAccess(caller, org.apache.cloudstack.acl.SecurityChecker.AccessType.ListEntry, false, gslbRule);
|
||||
_accountMgr.checkAccess(caller, org.apache.cloudstack.acl.SecurityChecker.AccessType.UseEntry, false, gslbRule);
|
||||
|
||||
response.add(gslbRule);
|
||||
return response;
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ public class AclApiServiceImpl extends ManagerBase implements AclApiService, Man
|
|||
Class<?> cmdClass = _apiServer.getCmdClass(action);
|
||||
AccessType accessType = null;
|
||||
if (BaseListCmd.class.isAssignableFrom(cmdClass)) {
|
||||
accessType = AccessType.ListEntry;
|
||||
accessType = AccessType.UseEntry;
|
||||
}
|
||||
return _iamSrv.addAclPermissionToAclPolicy(aclPolicyId, entityType, scope.toString(), scopeId, action,
|
||||
accessType.toString(), perm, recursive);
|
||||
|
|
|
|||
|
|
@ -274,11 +274,11 @@ public class AclApiServiceTest {
|
|||
when(_apiServer.getCmdClass("listVirtualMachines")).thenReturn(clz);
|
||||
when(
|
||||
_iamSrv.addAclPermissionToAclPolicy(policyId, AclEntityType.VirtualMachine.toString(), PermissionScope.RESOURCE.toString(), resId, "listVirtualMachines",
|
||||
AccessType.ListEntry.toString(), Permission.Allow, false)).thenReturn(policy);
|
||||
AccessType.UseEntry.toString(), Permission.Allow, false)).thenReturn(policy);
|
||||
_aclSrv.addAclPermissionToAclPolicy(policyId, AclEntityType.VirtualMachine.toString(), PermissionScope.RESOURCE, resId, "listVirtualMachines", Permission.Allow, false);
|
||||
Pair<List<AclPolicy>, Integer> policyList = new Pair<List<AclPolicy>, Integer>(policies, 1);
|
||||
List<AclPolicyPermission> policyPerms = new ArrayList<AclPolicyPermission>();
|
||||
AclPolicyPermission perm = new AclPolicyPermissionVO(policyId, "listVirtualMachines", AclEntityType.VirtualMachine.toString(), AccessType.ListEntry.toString(),
|
||||
AclPolicyPermission perm = new AclPolicyPermissionVO(policyId, "listVirtualMachines", AclEntityType.VirtualMachine.toString(), AccessType.UseEntry.toString(),
|
||||
PermissionScope.RESOURCE.toString(),
|
||||
resId, Permission.Allow, false);
|
||||
policyPerms.add(perm);
|
||||
|
|
|
|||
Loading…
Reference in New Issue