Skip to content

Commit e09f97a

Browse files
author
Prachi Damle
committed
Adding support for 'readOnly' access. AccessType.ListEntry introduced.
1 parent 289ac04 commit e09f97a

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public interface SecurityChecker extends Adapter {
3333
public enum AccessType {
3434
ModifyProject,
3535
OperateEntry,
36-
UseEntry
36+
UseEntry,
37+
ListEntry
3738
}
3839

3940
/**

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ public class ApiConstants {
591591
public static final String VGPUTYPE = "vgputype";
592592
public static final String REMAININGCAPACITY = "remainingcapacity";
593593
public static final String DISTRIBUTED_VPC_ROUTER = "distributedvpcrouter";
594+
public static final String READ_ONLY = "readOnly";
594595

595596

596597
public enum HostDetails {

services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.cloudstack.api.BaseAsyncCmd;
3030
import org.apache.cloudstack.api.Parameter;
3131
import org.apache.cloudstack.api.ServerApiException;
32+
import org.apache.cloudstack.api.BaseCmd.CommandType;
3233
import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
3334
import org.apache.cloudstack.context.CallContext;
3435
import org.apache.cloudstack.iam.IAMApiService;
@@ -72,6 +73,9 @@ public class AddIAMPermissionToIAMPolicyCmd extends BaseAsyncCmd {
7273
@Parameter(name = ApiConstants.IAM_SCOPE_ID, type = CommandType.STRING, required = false, description = "The UUID of the permission scope id")
7374
private String scopeId;
7475

76+
@Parameter(name = ApiConstants.READ_ONLY, type = CommandType.BOOLEAN, required = false, description = "Read Only access is added; Only applicable when action = List/Read api name")
77+
private Boolean readOnly;
78+
7579

7680
/////////////////////////////////////////////////////
7781
/////////////////// Accessors ///////////////////////
@@ -100,6 +104,10 @@ public Long getScopeId() {
100104
return _iamApiSrv.getPermissionScopeId(scope, entityType, scopeId);
101105
}
102106

107+
public Boolean isReadOnly() {
108+
return (readOnly != null) ? readOnly : false;
109+
}
110+
103111
/////////////////////////////////////////////////////
104112
/////////////// API Implementation///////////////////
105113
/////////////////////////////////////////////////////
@@ -123,7 +131,7 @@ public void execute() throws ResourceUnavailableException,
123131
CallContext.current().setEventDetails("IAM policy Id: " + getId());
124132
// Only explicit ALLOW is supported for this release, no explicit deny
125133
IAMPolicy result = _iamApiSrv.addIAMPermissionToIAMPolicy(id, entityType, PermissionScope.valueOf(scope),
126-
getScopeId(), action, Permission.Allow, false);
134+
getScopeId(), action, Permission.Allow, false, isReadOnly());
127135
if (result != null) {
128136
IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(result);
129137
response.setResponseName(getCommandName());

services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public interface IAMApiService extends PluggableService {
6060
void removeIAMPolicyFromAccounts(Long policyId, List<Long> accountIds);
6161

6262
IAMPolicy addIAMPermissionToIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope, Long scopeId,
63-
String action, Permission perm, Boolean recursive);
63+
String action, Permission perm, Boolean recursive, Boolean readOnly);
6464

6565
IAMPolicy removeIAMPermissionFromIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope, Long scopeId, String action);
6666

services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
4141
import org.apache.cloudstack.affinity.AffinityGroup;
4242
import org.apache.cloudstack.api.ApiConstants;
43+
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
4344
import org.apache.cloudstack.api.BaseListCmd;
4445
import org.apache.cloudstack.api.InternalIdentity;
4546
import org.apache.cloudstack.api.command.iam.AddAccountToIAMGroupCmd;
@@ -506,11 +507,17 @@ public void removeIAMPolicyFromAccounts(final Long policyId, final List<Long> ac
506507
@Override
507508
@ActionEvent(eventType = EventTypes.EVENT_IAM_POLICY_GRANT, eventDescription = "Granting acl permission to IAM Policy")
508509
public IAMPolicy addIAMPermissionToIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope,
509-
Long scopeId, String action, Permission perm, Boolean recursive) {
510+
Long scopeId, String action, Permission perm, Boolean recursive, Boolean readOnly) {
510511
Class<?> cmdClass = _apiServer.getCmdClass(action);
511512
AccessType accessType = null;
512513
if (BaseListCmd.class.isAssignableFrom(cmdClass)) {
513-
accessType = AccessType.UseEntry;
514+
if (readOnly) {
515+
accessType = AccessType.ListEntry;
516+
} else {
517+
accessType = AccessType.UseEntry;
518+
}
519+
} else if (!(BaseAsyncCreateCmd.class.isAssignableFrom(cmdClass))) {
520+
accessType = AccessType.OperateEntry;
514521
}
515522
String accessTypeStr = (accessType != null) ? accessType.toString() : null;
516523
return _iamSrv.addIAMPermissionToIAMPolicy(iamPolicyId, entityType, scope.toString(), scopeId, action,

0 commit comments

Comments
 (0)