Skip to content

Commit 695d689

Browse files
author
Prachi Damle
committed
Adding annotations for more admin APIs
1 parent 690c5d4 commit 695d689

10 files changed

Lines changed: 44 additions & 21 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.log4j.Logger;
2323

24+
import org.apache.cloudstack.acl.IAMEntityType;
2425
import org.apache.cloudstack.api.APICommand;
2526
import org.apache.cloudstack.api.ApiConstants;
2627
import org.apache.cloudstack.api.ApiErrorCode;
@@ -35,7 +36,7 @@
3536
import com.cloud.user.Account;
3637
import com.cloud.user.UserAccount;
3738

38-
@APICommand(name = "createAccount", description = "Creates an account", responseObject = AccountResponse.class)
39+
@APICommand(name = "createAccount", description = "Creates an account", responseObject = AccountResponse.class, entityType = { IAMEntityType.Account })
3940
public class CreateAccountCmd extends BaseCmd {
4041
public static final Logger s_logger = Logger.getLogger(CreateAccountCmd.class.getName());
4142

api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import org.apache.log4j.Logger;
2222

23+
import org.apache.cloudstack.acl.IAMEntityType;
24+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
25+
import org.apache.cloudstack.api.ACL;
2326
import org.apache.cloudstack.api.APICommand;
2427
import org.apache.cloudstack.api.ApiCommandJobType;
2528
import org.apache.cloudstack.api.ApiConstants;
@@ -36,15 +39,15 @@
3639
import com.cloud.user.Account;
3740
import com.cloud.user.User;
3841

39-
@APICommand(name = "deleteAccount", description = "Deletes a account, and all users associated with this account", responseObject = SuccessResponse.class)
42+
@APICommand(name = "deleteAccount", description = "Deletes a account, and all users associated with this account", responseObject = SuccessResponse.class, entityType = { IAMEntityType.Account })
4043
public class DeleteAccountCmd extends BaseAsyncCmd {
4144
public static final Logger s_logger = Logger.getLogger(DeleteAccountCmd.class.getName());
4245
private static final String s_name = "deleteaccountresponse";
4346

4447
/////////////////////////////////////////////////////
4548
//////////////// API parameters /////////////////////
4649
/////////////////////////////////////////////////////
47-
50+
@ACL(accessType = AccessType.OperateEntry)
4851
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AccountResponse.class, required = true, description = "Account id")
4952
private Long id;
5053

api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import org.apache.log4j.Logger;
2222

23+
import org.apache.cloudstack.acl.IAMEntityType;
24+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
25+
import org.apache.cloudstack.api.ACL;
2326
import org.apache.cloudstack.api.APICommand;
2427
import org.apache.cloudstack.api.ApiCommandJobType;
2528
import org.apache.cloudstack.api.ApiConstants;
@@ -38,14 +41,15 @@
3841
import com.cloud.exception.ResourceUnavailableException;
3942
import com.cloud.user.Account;
4043

41-
@APICommand(name = "disableAccount", description = "Disables an account", responseObject = AccountResponse.class)
44+
@APICommand(name = "disableAccount", description = "Disables an account", responseObject = AccountResponse.class, entityType = { IAMEntityType.Account })
4245
public class DisableAccountCmd extends BaseAsyncCmd {
4346
public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName());
4447
private static final String s_name = "disableaccountresponse";
4548

4649
/////////////////////////////////////////////////////
4750
//////////////// API parameters /////////////////////
4851
/////////////////////////////////////////////////////
52+
@ACL(accessType = AccessType.OperateEntry)
4953
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "Account id")
5054
private Long id;
5155

api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import org.apache.log4j.Logger;
2222

23+
import org.apache.cloudstack.acl.IAMEntityType;
24+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
25+
import org.apache.cloudstack.api.ACL;
2326
import org.apache.cloudstack.api.APICommand;
2427
import org.apache.cloudstack.api.ApiConstants;
2528
import org.apache.cloudstack.api.ApiErrorCode;
@@ -33,14 +36,15 @@
3336

3437
import com.cloud.user.Account;
3538

36-
@APICommand(name = "enableAccount", description = "Enables an account", responseObject = AccountResponse.class)
39+
@APICommand(name = "enableAccount", description = "Enables an account", responseObject = AccountResponse.class, entityType = { IAMEntityType.Account })
3740
public class EnableAccountCmd extends BaseCmd {
3841
public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName());
3942
private static final String s_name = "enableaccountresponse";
4043

4144
/////////////////////////////////////////////////////
4245
//////////////// API parameters /////////////////////
4346
/////////////////////////////////////////////////////
47+
@ACL(accessType = AccessType.OperateEntry)
4448
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "Account id")
4549
private Long id;
4650

api/src/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.log4j.Logger;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
2122
import org.apache.cloudstack.api.APICommand;
2223
import org.apache.cloudstack.api.ApiConstants;
2324
import org.apache.cloudstack.api.BaseCmd;
@@ -27,7 +28,7 @@
2728

2829
import com.cloud.user.Account;
2930

30-
@APICommand(name = "lockAccount", description = "Locks an account", responseObject = AccountResponse.class)
31+
@APICommand(name = "lockAccount", description = "Locks an account", responseObject = AccountResponse.class, entityType = { IAMEntityType.Account })
3132
public class LockAccountCmd extends BaseCmd {
3233
public static final Logger s_logger = Logger.getLogger(LockAccountCmd.class.getName());
3334

api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
import org.apache.log4j.Logger;
2525

26+
import org.apache.cloudstack.acl.IAMEntityType;
27+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
28+
import org.apache.cloudstack.api.ACL;
2629
import org.apache.cloudstack.api.APICommand;
2730
import org.apache.cloudstack.api.ApiConstants;
2831
import org.apache.cloudstack.api.ApiErrorCode;
@@ -36,15 +39,15 @@
3639

3740
import com.cloud.user.Account;
3841

39-
@APICommand(name = "updateAccount", description = "Updates account information for the authenticated user", responseObject = AccountResponse.class)
42+
@APICommand(name = "updateAccount", description = "Updates account information for the authenticated user", responseObject = AccountResponse.class, entityType = { IAMEntityType.Account })
4043
public class UpdateAccountCmd extends BaseCmd {
4144
public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName());
4245
private static final String s_name = "updateaccountresponse";
4346

4447
/////////////////////////////////////////////////////
4548
//////////////// API parameters /////////////////////
4649
/////////////////////////////////////////////////////
47-
50+
@ACL(accessType = AccessType.OperateEntry)
4851
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "Account id")
4952
private Long id;
5053

api/src/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.log4j.Logger;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
2122
import org.apache.cloudstack.api.APICommand;
2223
import org.apache.cloudstack.api.ApiCommandJobType;
2324
import org.apache.cloudstack.api.ApiConstants;
@@ -34,7 +35,7 @@
3435

3536
import com.cloud.network.router.VirtualRouter.Role;
3637

37-
@APICommand(name = "listInternalLoadBalancerVMs", description = "List internal LB VMs.", responseObject = DomainRouterResponse.class)
38+
@APICommand(name = "listInternalLoadBalancerVMs", description = "List internal LB VMs.", responseObject = DomainRouterResponse.class, entityType = { IAMEntityType.VirtualMachine })
3839
public class ListInternalLBVMsCmd extends BaseListProjectAndAccountResourcesCmd {
3940
public static final Logger s_logger = Logger.getLogger(ListInternalLBVMsCmd.class.getName());
4041

api/src/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.apache.log4j.Logger;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
22+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
23+
import org.apache.cloudstack.api.ACL;
2124
import org.apache.cloudstack.api.APICommand;
2225
import org.apache.cloudstack.api.ApiCommandJobType;
2326
import org.apache.cloudstack.api.ApiConstants;
@@ -36,15 +39,15 @@
3639
import com.cloud.network.router.VirtualRouter;
3740
import com.cloud.network.router.VirtualRouter.Role;
3841

39-
@APICommand(name = "startInternalLoadBalancerVM", responseObject = DomainRouterResponse.class, description = "Starts an existing internal lb vm.")
42+
@APICommand(name = "startInternalLoadBalancerVM", responseObject = DomainRouterResponse.class, description = "Starts an existing internal lb vm.", entityType = { IAMEntityType.VirtualMachine })
4043
public class StartInternalLBVMCmd extends BaseAsyncCmd {
4144
public static final Logger s_logger = Logger.getLogger(StartInternalLBVMCmd.class.getName());
4245
private static final String s_name = "startinternallbvmresponse";
4346

4447
/////////////////////////////////////////////////////
4548
//////////////// API parameters /////////////////////
4649
/////////////////////////////////////////////////////
47-
50+
@ACL(accessType = AccessType.OperateEntry)
4851
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DomainRouterResponse.class, required = true, description = "the ID of the internal lb vm")
4952
private Long id;
5053

api/src/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.apache.log4j.Logger;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
22+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
23+
import org.apache.cloudstack.api.ACL;
2124
import org.apache.cloudstack.api.APICommand;
2225
import org.apache.cloudstack.api.ApiCommandJobType;
2326
import org.apache.cloudstack.api.ApiConstants;
@@ -35,15 +38,15 @@
3538
import com.cloud.network.router.VirtualRouter;
3639
import com.cloud.network.router.VirtualRouter.Role;
3740

38-
@APICommand(name = "stopInternalLoadBalancerVM", description = "Stops an Internal LB vm.", responseObject = DomainRouterResponse.class)
41+
@APICommand(name = "stopInternalLoadBalancerVM", description = "Stops an Internal LB vm.", responseObject = DomainRouterResponse.class, entityType = { IAMEntityType.VirtualMachine })
3942
public class StopInternalLBVMCmd extends BaseAsyncCmd {
4043
public static final Logger s_logger = Logger.getLogger(StopInternalLBVMCmd.class.getName());
4144
private static final String s_name = "stopinternallbvmresponse";
4245

4346
// ///////////////////////////////////////////////////
4447
// ////////////// API parameters /////////////////////
4548
// ///////////////////////////////////////////////////
46-
49+
@ACL(accessType = AccessType.OperateEntry)
4750
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DomainRouterResponse.class, required = true, description = "the ID of the internal lb vm")
4851
private Long id;
4952

server/src/com/cloud/user/AccountManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ public UserAccount updateUser(UpdateUserCmd cmd) {
11061106
throw new PermissionDeniedException("user id : " + id + " is system account, update is not allowed");
11071107
}
11081108

1109-
checkAccess(CallContext.current().getCallingAccount(), null, true, account);
1109+
checkAccess(CallContext.current().getCallingAccount(), AccessType.OperateEntry, true, account);
11101110

11111111
if (firstName != null) {
11121112
if (firstName.isEmpty()) {
@@ -1220,7 +1220,7 @@ public UserAccount disableUser(long userId) {
12201220
throw new InvalidParameterValueException("User id : " + userId + " is a system user, disabling is not allowed");
12211221
}
12221222

1223-
checkAccess(caller, null, true, account);
1223+
checkAccess(caller, AccessType.OperateEntry, true, account);
12241224

12251225
boolean success = doSetUserStatus(userId, State.disabled);
12261226
if (success) {
@@ -1258,7 +1258,7 @@ public UserAccount enableUser(final long userId) {
12581258
throw new InvalidParameterValueException("User id : " + userId + " is a system user, enabling is not allowed");
12591259
}
12601260

1261-
checkAccess(caller, null, true, account);
1261+
checkAccess(caller, AccessType.OperateEntry, true, account);
12621262

12631263
boolean success = Transaction.execute(new TransactionCallback<Boolean>() {
12641264
@Override
@@ -1307,7 +1307,7 @@ public UserAccount lockUser(long userId) {
13071307
throw new PermissionDeniedException("user id : " + userId + " is a system user, locking is not allowed");
13081308
}
13091309

1310-
checkAccess(caller, null, true, account);
1310+
checkAccess(caller, AccessType.OperateEntry, true, account);
13111311

13121312
// make sure the account is enabled too
13131313
// if the user is either locked already or disabled already, don't change state...only lock currently enabled
@@ -1416,7 +1416,7 @@ public AccountVO enableAccount(String accountName, Long domainId, Long accountId
14161416

14171417
// Check if user performing the action is allowed to modify this account
14181418
Account caller = CallContext.current().getCallingAccount();
1419-
checkAccess(caller, null, true, account);
1419+
checkAccess(caller, AccessType.OperateEntry, true, account);
14201420

14211421
boolean success = enableAccount(account.getId());
14221422
if (success) {
@@ -1450,7 +1450,7 @@ public AccountVO lockAccount(String accountName, Long domainId, Long accountId)
14501450
throw new PermissionDeniedException("Account id : " + accountId + " is a system account, lock is not allowed");
14511451
}
14521452

1453-
checkAccess(caller, null, true, account);
1453+
checkAccess(caller, AccessType.OperateEntry, true, account);
14541454

14551455
if (lockAccount(account.getId())) {
14561456
CallContext.current().putContextParameter(Account.class, account.getUuid());
@@ -1480,7 +1480,7 @@ public AccountVO disableAccount(String accountName, Long domainId, Long accountI
14801480
throw new PermissionDeniedException("Account id : " + accountId + " is a system account, disable is not allowed");
14811481
}
14821482

1483-
checkAccess(caller, null, true, account);
1483+
checkAccess(caller, AccessType.OperateEntry, true, account);
14841484

14851485
if (disableAccount(account.getId())) {
14861486
CallContext.current().putContextParameter(Account.class, account.getUuid());
@@ -1599,7 +1599,7 @@ public boolean deleteUser(DeleteUserCmd deleteUserCmd) {
15991599
throw new InvalidParameterValueException("The user is default and can't be removed");
16001600
}
16011601

1602-
checkAccess(CallContext.current().getCallingAccount(), null, true, account);
1602+
checkAccess(CallContext.current().getCallingAccount(), AccessType.OperateEntry, true, account);
16031603
CallContext.current().putContextParameter(User.class, user.getUuid());
16041604
return _userDao.remove(id);
16051605
}

0 commit comments

Comments
 (0)