Skip to content

Commit 586ee74

Browse files
committed
Clean up SecurityChecker.AccessType and modify code to use them
consistently.
1 parent 4b75fa8 commit 586ee74

10 files changed

Lines changed: 32 additions & 34 deletions

File tree

‎api/src/org/apache/cloudstack/acl/SecurityChecker.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@
3131
public interface SecurityChecker extends Adapter {
3232

3333
public enum AccessType {
34-
ListEntry,
35-
ModifyEntry,
3634
ModifyProject,
3735
UseNetwork,
38-
DeleteEntry,
3936
OperateEntry,
4037
UseEntry
4138
}

‎server/src/com/cloud/acl/AffinityGroupAccessChecker.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
4949
AffinityGroup group = (AffinityGroup)entity;
5050

5151
if (_affinityGroupService.isAdminControlledGroup(group)) {
52-
if (accessType != null && accessType == AccessType.ModifyEntry
52+
if (accessType != null && accessType == AccessType.OperateEntry
5353
&& !_accountMgr.isRootAdmin(caller.getId())) {
5454
throw new PermissionDeniedException(caller + " does not have permission to operate with resource "
5555
+ entity);

‎server/src/com/cloud/acl/DomainChecker.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
123123
}
124124
} else {
125125
// Domain admin and regular user can delete/modify only templates created by them
126-
if (accessType != null && accessType == AccessType.ModifyEntry) {
126+
if (accessType != null && accessType == AccessType.OperateEntry) {
127127
if (!_accountService.isRootAdmin(caller.getId()) && owner.getId() != caller.getId()) {
128128
// For projects check if the caller account can access the project account
129129
if (owner.getType() != Account.ACCOUNT_TYPE_PROJECT || !(_projectMgr.canAccessProjectAccount(caller, owner.getId()))) {

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
18151815
}
18161816

18171817
// do a permission check
1818-
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
1818+
_accountMgr.checkAccess(account, AccessType.OperateEntry, true, template);
18191819

18201820
if(cmd.isRoutingType() != null){
18211821
if (!_accountService.isRootAdmin(account.getId())) {

‎server/src/com/cloud/template/TemplateManagerImpl.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public VirtualMachineTemplate prepareTemplate(long templateId, long zoneId) {
367367
throw new InvalidParameterValueException("Unable to find template id=" + templateId);
368368
}
369369

370-
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.ModifyEntry, true, vmTemplate);
370+
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.OperateEntry, true, vmTemplate);
371371

372372
prepareTemplateInAllStoragePools(vmTemplate, zoneId);
373373
return vmTemplate;
@@ -413,7 +413,7 @@ private String extract(Account caller, Long templateId, String url, Long zoneId,
413413
throw new InvalidParameterValueException("Unable to extract template id=" + templateId + " as it's not extractable");
414414
}
415415

416-
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
416+
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
417417

418418
List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
419419

@@ -689,7 +689,7 @@ public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUn
689689
return template;
690690
}
691691

692-
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
692+
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
693693

694694
boolean success = copy(userId, template, srcSecStore, dstZone);
695695

@@ -1028,7 +1028,7 @@ public boolean deleteTemplate(DeleteTemplateCmd cmd) {
10281028
throw new InvalidParameterValueException("unable to find template with id " + templateId);
10291029
}
10301030

1031-
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
1031+
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
10321032

10331033
if (template.getFormat() == ImageFormat.ISO) {
10341034
throw new InvalidParameterValueException("Please specify a valid template.");
@@ -1051,7 +1051,7 @@ public boolean deleteIso(DeleteIsoCmd cmd) {
10511051
throw new InvalidParameterValueException("unable to find iso with id " + templateId);
10521052
}
10531053

1054-
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
1054+
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
10551055

10561056
if (template.getFormat() != ImageFormat.ISO) {
10571057
throw new InvalidParameterValueException("Please specify a valid iso.");
@@ -1752,7 +1752,7 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
17521752
}
17531753

17541754
// do a permission check
1755-
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
1755+
_accountMgr.checkAccess(account, AccessType.OperateEntry, true, template);
17561756
if (cmd.isRoutingType() != null) {
17571757
if (!_accountService.isRootAdmin(account.getId())) {
17581758
throw new PermissionDeniedException("Parameter isrouting can only be specified by a Root Admin, permission denied");

‎server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import javax.inject.Inject;
2727
import javax.naming.ConfigurationException;
2828

29-
import org.apache.log4j.Logger;
30-
29+
import org.apache.log4j.Logger;
30+
3131
import org.apache.cloudstack.acl.AclEntityType;
3232
import org.apache.cloudstack.acl.ControlledEntity;
3333
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
@@ -263,7 +263,7 @@ public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long do
263263
affinityGroupId = group.getId();
264264
}
265265
// check permissions
266-
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, group);
266+
_accountMgr.checkAccess(caller, AccessType.OperateEntry, true, group);
267267

268268
final Long affinityGroupIdFinal = affinityGroupId;
269269
Transaction.execute(new TransactionCallbackNoReturn() {

‎server/src/org/apache/cloudstack/network/lb/CertServiceImpl.java‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@
5353
import javax.ejb.Local;
5454
import javax.inject.Inject;
5555

56+
import org.apache.commons.io.IOUtils;
57+
import org.apache.log4j.Logger;
58+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
59+
import org.bouncycastle.openssl.PEMReader;
60+
import org.bouncycastle.openssl.PasswordFinder;
61+
5662
import org.apache.cloudstack.acl.SecurityChecker;
5763
import org.apache.cloudstack.api.command.user.loadbalancer.DeleteSslCertCmd;
5864
import org.apache.cloudstack.api.command.user.loadbalancer.ListSslCertsCmd;
5965
import org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd;
6066
import org.apache.cloudstack.api.response.SslCertResponse;
6167
import org.apache.cloudstack.context.CallContext;
62-
import org.apache.commons.io.IOUtils;
63-
import org.apache.log4j.Logger;
64-
import org.bouncycastle.jce.provider.BouncyCastleProvider;
65-
import org.bouncycastle.openssl.PEMReader;
66-
import org.bouncycastle.openssl.PasswordFinder;
6768

6869
import com.cloud.event.ActionEvent;
6970
import com.cloud.event.EventTypes;
@@ -146,7 +147,7 @@ public void deleteSslCert(DeleteSslCertCmd deleteSslCertCmd) {
146147
if (certVO == null) {
147148
throw new InvalidParameterValueException("Invalid certificate id: " + certId);
148149
}
149-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, certVO);
150+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, certVO);
150151

151152
List<LoadBalancerCertMapVO> lbCertRule = _lbCertDao.listByCertId(certId);
152153

@@ -190,7 +191,7 @@ public List<SslCertResponse> listSslCerts(ListSslCertsCmd listSslCertCmd) {
190191
throw new InvalidParameterValueException("Invalid certificate id: " + certId);
191192
}
192193

193-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ListEntry, true, certVO);
194+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVO);
194195

195196
certLbMap = _lbCertDao.listByCertId(certId);
196197

@@ -205,7 +206,7 @@ public List<SslCertResponse> listSslCerts(ListSslCertsCmd listSslCertCmd) {
205206
throw new InvalidParameterValueException("found no loadbalancer wth id: " + lbRuleId);
206207
}
207208

208-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ListEntry, true, lb);
209+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, lb);
209210

210211
// get the cert id
211212
LoadBalancerCertMapVO lbCertMapRule;
@@ -228,7 +229,7 @@ public List<SslCertResponse> listSslCerts(ListSslCertsCmd listSslCertCmd) {
228229
List<SslCertVO> certVOList = _sslCertDao.listByAccountId(accountId);
229230
if (certVOList == null || certVOList.isEmpty())
230231
return certResponseList;
231-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ListEntry, true, certVOList.get(0));
232+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVOList.get(0));
232233

233234
for (SslCertVO cert : certVOList) {
234235
certLbMap = _lbCertDao.listByCertId(cert.getId());
@@ -486,7 +487,7 @@ public static class KeyPassword implements PasswordFinder {
486487
char[] password;
487488

488489
KeyPassword(char[] word) {
489-
this.password = word;
490+
password = word;
490491
}
491492

492493
@Override

‎server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
9898
protected GslbServiceProvider _gslbProvider = null;
9999

100100
public void setGslbServiceProvider(GslbServiceProvider provider) {
101-
this._gslbProvider = provider;
101+
_gslbProvider = provider;
102102
}
103103

104104
@Override
@@ -183,7 +183,7 @@ public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd
183183
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
184184
}
185185

186-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
186+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
187187

188188
if (gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke) {
189189
throw new InvalidParameterValueException("global load balancer rule id: " + gslbRule.getUuid() + " is in revoked state");
@@ -319,7 +319,7 @@ public boolean removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRule
319319
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
320320
}
321321

322-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
322+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
323323

324324
if (gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke) {
325325
throw new InvalidParameterValueException("global load balancer rule id: " + gslbRuleId + " is already in revoked state");
@@ -445,7 +445,7 @@ private void revokeGslbRule(final long gslbRuleId, Account caller) {
445445
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
446446
}
447447

448-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
448+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
449449

450450
if (gslbRule.getState() == com.cloud.region.ha.GlobalLoadBalancerRule.State.Staged) {
451451
if (s_logger.isDebugEnabled()) {
@@ -523,7 +523,7 @@ public GlobalLoadBalancerRule updateGlobalLoadBalancerRule(UpdateGlobalLoadBalan
523523
CallContext ctx = CallContext.current();
524524
Account caller = ctx.getCallingAccount();
525525

526-
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
526+
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, gslbRule);
527527

528528
if (algorithm != null && !GlobalLoadBalancerRule.Algorithm.isValidAlgorithm(algorithm)) {
529529
throw new InvalidParameterValueException("Invalid Algorithm: " + algorithm);
@@ -583,7 +583,7 @@ public List<GlobalLoadBalancerRule> listGlobalLoadBalancerRule(ListGlobalLoadBal
583583
if (gslbRule == null) {
584584
throw new InvalidParameterValueException("Invalid gslb rule id specified");
585585
}
586-
_accountMgr.checkAccess(caller, org.apache.cloudstack.acl.SecurityChecker.AccessType.ListEntry, false, gslbRule);
586+
_accountMgr.checkAccess(caller, org.apache.cloudstack.acl.SecurityChecker.AccessType.UseEntry, false, gslbRule);
587587

588588
response.add(gslbRule);
589589
return response;

‎services/iam/plugin/src/org/apache/cloudstack/acl/api/AclApiServiceImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public AclPolicy addAclPermissionToAclPolicy(long aclPolicyId, String entityType
409409
Class<?> cmdClass = _apiServer.getCmdClass(action);
410410
AccessType accessType = null;
411411
if (BaseListCmd.class.isAssignableFrom(cmdClass)) {
412-
accessType = AccessType.ListEntry;
412+
accessType = AccessType.UseEntry;
413413
}
414414
return _iamSrv.addAclPermissionToAclPolicy(aclPolicyId, entityType, scope.toString(), scopeId, action,
415415
accessType.toString(), perm, recursive);

‎services/iam/plugin/test/org/apache/cloudstack/acl/AclApiServiceTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ public void addRemovePermissionToPolicyTest() {
274274
when(_apiServer.getCmdClass("listVirtualMachines")).thenReturn(clz);
275275
when(
276276
_iamSrv.addAclPermissionToAclPolicy(policyId, AclEntityType.VirtualMachine.toString(), PermissionScope.RESOURCE.toString(), resId, "listVirtualMachines",
277-
AccessType.ListEntry.toString(), Permission.Allow, false)).thenReturn(policy);
277+
AccessType.UseEntry.toString(), Permission.Allow, false)).thenReturn(policy);
278278
_aclSrv.addAclPermissionToAclPolicy(policyId, AclEntityType.VirtualMachine.toString(), PermissionScope.RESOURCE, resId, "listVirtualMachines", Permission.Allow, false);
279279
Pair<List<AclPolicy>, Integer> policyList = new Pair<List<AclPolicy>, Integer>(policies, 1);
280280
List<AclPolicyPermission> policyPerms = new ArrayList<AclPolicyPermission>();
281-
AclPolicyPermission perm = new AclPolicyPermissionVO(policyId, "listVirtualMachines", AclEntityType.VirtualMachine.toString(), AccessType.ListEntry.toString(),
281+
AclPolicyPermission perm = new AclPolicyPermissionVO(policyId, "listVirtualMachines", AclEntityType.VirtualMachine.toString(), AccessType.UseEntry.toString(),
282282
PermissionScope.RESOURCE.toString(),
283283
resId, Permission.Allow, false);
284284
policyPerms.add(perm);

0 commit comments

Comments
 (0)