Skip to content

Commit 96eacbc

Browse files
fix users being able to delete keypairs by updating their keys
1 parent 607fe96 commit 96eacbc

File tree

4 files changed

+4
-44
lines changed

4 files changed

+4
-44
lines changed

engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ApiKeyPairDaoImpl.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,4 @@ public Pair<List<ApiKeyPairVO>, Integer> listByUserIdsPaginated(List<Long> userI
8585
}
8686
return apiKeyPairVOList;
8787
}
88-
89-
@Override
90-
public boolean update(Long id, ApiKeyPairVO apiKeyPair) {
91-
ApiKeyPairVO ub = createForUpdate();
92-
93-
ub.setUuid(apiKeyPair.getUuid());
94-
ub.setUserId(apiKeyPair.getUserId());
95-
ub.setName(apiKeyPair.getName());
96-
ub.setDomainId(apiKeyPair.getDomainId());
97-
ub.setAccountId(apiKeyPair.getAccountId());
98-
ub.setStartDate(apiKeyPair.getStartDate());
99-
ub.setEndDate(apiKeyPair.getEndDate());
100-
ub.setCreated(apiKeyPair.getCreated());
101-
ub.setDescription(apiKeyPair.getDescription());
102-
ub.setApiKey(apiKeyPair.getApiKey());
103-
ub.setSecretKey(apiKeyPair.getSecretKey());
104-
ub.setRemoved(apiKeyPair.getRemoved());
105-
106-
return super.update(id, ub);
107-
}
10888
}

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import com.cloud.user.UserVO;
4444
import org.apache.cloudstack.acl.RoleService;
4545
import org.apache.cloudstack.acl.RoleVO;
46-
import org.apache.cloudstack.acl.apikeypair.ApiKeyPairService;
4746
import org.apache.cloudstack.acl.dao.RoleDao;
4847
import com.cloud.dc.Pod;
4948
import com.cloud.dc.dao.DataCenterDao;
@@ -56,7 +55,6 @@
5655
import org.apache.cloudstack.acl.ControlledEntity;
5756
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
5857
import org.apache.cloudstack.acl.SecurityChecker;
59-
import org.apache.cloudstack.acl.dao.ApiKeyPairDao;
6058
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
6159
import org.apache.cloudstack.affinity.AffinityGroupResponse;
6260
import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
@@ -656,12 +654,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
656654
@Inject
657655
ExtensionHelper extensionHelper;
658656

659-
@Inject
660-
ApiKeyPairDao apiKeyPairDao;
661-
662-
@Inject
663-
ApiKeyPairService apiKeyPairService;
664-
665657
@Inject
666658
RoleDao roleDao;
667659

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.cloud.network.vpc.VpcVO;
4848
import org.apache.cloudstack.acl.ControlledEntity;
4949
import org.apache.cloudstack.acl.SecurityChecker;
50-
import org.apache.cloudstack.acl.dao.ApiKeyPairDao;
5150
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
5251
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
5352
import org.apache.cloudstack.annotation.AnnotationService;
@@ -984,8 +983,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
984983
@Inject
985984
protected SSHKeyPairDao _sshKeyPairDao;
986985
@Inject
987-
protected ApiKeyPairDao _apiKeyPairDao;
988-
@Inject
989986
private LoadBalancerDao _loadbalancerDao;
990987
@Inject
991988
private HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
16191619

16201620
logger.debug("Updating user {}", user);
16211621

1622-
ApiKeyPairVO keyPair = validateAndUpdateApiAndSecretKeyIfNeeded(updateUserCmd, user);
1622+
validateAndUpdateApiAndSecretKeyIfNeeded(updateUserCmd, user);
16231623
validateAndUpdateUserApiKeyAccess(updateUserCmd, user);
16241624

16251625
validateAndUpdateFirstNameIfNeeded(updateUserCmd, user);
@@ -1640,9 +1640,6 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
16401640
user.setUser2faEnabled(true);
16411641
}
16421642
validateAndUpdatePasswordChangeRequired(caller, updateUserCmd, user, account);
1643-
if (keyPair != null) {
1644-
apiKeyPairDao.update(keyPair.getId(), keyPair);
1645-
}
16461643
_userDao.update(user.getId(), user);
16471644
return userAccountDao.findById(user.getId());
16481645
}
@@ -1946,7 +1943,7 @@ protected Account getCurrentCallingAccount() {
19461943
* <li>If a pair of keys is provided, we validate to see if there is an user already using the provided API key. If there is someone else using, we throw an {@link InvalidParameterValueException} because two users cannot have the same API key.
19471944
* </ul>
19481945
*/
1949-
protected ApiKeyPairVO validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd updateUserCmd, UserVO user) {
1946+
protected void validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd updateUserCmd, UserVO user) {
19501947
String apiKey = updateUserCmd.getApiKey();
19511948
String secretKey = updateUserCmd.getSecretKey();
19521949

@@ -1956,7 +1953,7 @@ protected ApiKeyPairVO validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd up
19561953
throw new InvalidParameterValueException("Please provide a userApiKey/userSecretKey pair");
19571954
}
19581955
if (isApiKeyBlank && isSecretKeyBlank) {
1959-
return null;
1956+
return;
19601957
}
19611958
Ternary<User, Account, ApiKeyPair> keyPairTernary = findUserByApiKey(apiKey);
19621959
if (keyPairTernary == null) {
@@ -1969,15 +1966,9 @@ protected ApiKeyPairVO validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd up
19691966
}
19701967

19711968
ApiKeyPairVO keyPair = (ApiKeyPairVO) keyPairTernary.third();
1972-
1973-
Account account = _accountDao.findById(user.getAccountId());
19741969
keyPair.setApiKey(apiKey);
19751970
keyPair.setSecretKey(secretKey);
1976-
keyPair.setDomainId(account.getDomainId());
1977-
keyPair.setUserId(user.getId());
1978-
keyPair.setAccountId(account.getId());
1979-
keyPair.setName(keyPair.getUuid());
1980-
return keyPair;
1971+
apiKeyPairDao.update(keyPair.getId(), keyPair);
19811972
}
19821973

19831974
protected void validateAndUpdateUserApiKeyAccess(UpdateUserCmd updateUserCmd, UserVO user) {

0 commit comments

Comments
 (0)