Skip to content

Commit 29e6dae

Browse files
author
Alena Prokharchyk
committed
CLOUDSTACK-287: don't allow API call against system account (adding users to system account is prohibited; can't delete/update System account)
Conflicts: server/src/com/cloud/user/AccountManagerImpl.java
1 parent cfd2091 commit 29e6dae

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ public UserVO createUser(String userName, String password, String firstName, Str
834834
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
835835
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain id=" + domainId + " to create user");
836836
}
837+
838+
if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
839+
throw new PermissionDeniedException("Account id : " + account.getId() + " is a system account, can't add a user to it");
840+
}
837841

838842
if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) {
839843
throw new CloudRuntimeException("The user " + userName + " already exists in domain " + domainId);
@@ -1155,9 +1159,8 @@ public AccountVO enableAccount(String accountName, Long domainId, Long accountId
11551159
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
11561160
}
11571161

1158-
// Don't allow to modify system account
11591162
if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
1160-
throw new InvalidParameterValueException("Can not modify system account");
1163+
throw new PermissionDeniedException("Account id : " + accountId + " is a system account, enable is not allowed");
11611164
}
11621165

11631166
// Check if user performing the action is allowed to modify this account
@@ -1187,14 +1190,13 @@ public AccountVO lockAccount(String accountName, Long domainId, Long accountId)
11871190
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
11881191
throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
11891192
}
1190-
1191-
checkAccess(caller, null, true, account);
1192-
1193-
// don't allow modify system account
1193+
11941194
if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
1195-
throw new InvalidParameterValueException("can not lock system account");
1195+
throw new PermissionDeniedException("Account id : " + accountId + " is a system account, lock is not allowed");
11961196
}
11971197

1198+
checkAccess(caller, null, true, account);
1199+
11981200
if (lockAccount(account.getId())) {
11991201
return _accountDao.findById(account.getId());
12001202
} else {
@@ -1217,6 +1219,10 @@ public AccountVO disableAccount(String accountName, Long domainId, Long accountI
12171219
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
12181220
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
12191221
}
1222+
1223+
if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
1224+
throw new PermissionDeniedException("Account id : " + accountId + " is a system account, disable is not allowed");
1225+
}
12201226

12211227
checkAccess(caller, null, true, account);
12221228

0 commit comments

Comments
 (0)