Skip to content

Commit 305a0a8

Browse files
author
Daan Hoogland
committed
replace some AccountDoa.findUserAccountByApiKey(apiKey) by UserAccountDao.getUserByApiKey(encodedKey)
1 parent 9f0443a commit 305a0a8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,9 @@ protected void validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd updateUser
18611861
if (isApiKeyBlank && isSecretKeyBlank) {
18621862
return;
18631863
}
1864-
Pair<User, Account> apiKeyOwner = _accountDao.findUserAccountByApiKey(apiKey);
1864+
UserAccount apiKeyOwner = _userAccountDao.getUserByApiKey(apiKey);
18651865
if (apiKeyOwner != null) {
1866-
User userThatHasTheProvidedApiKey = apiKeyOwner.first();
1867-
if (userThatHasTheProvidedApiKey.getId() != user.getId()) {
1866+
if (apiKeyOwner.getId() != user.getId()) {
18681867
throw new InvalidParameterValueException(String.format("The API key [%s] already exists in the system. Please provide a unique key.", apiKey));
18691868
}
18701869
}
@@ -3184,14 +3183,14 @@ private String createUserApiKey(long userId) {
31843183
UserVO updatedUser = _userDao.createForUpdate();
31853184

31863185
String encodedKey;
3187-
Pair<User, Account> userAcct;
3186+
UserAccount userAcct;
31883187
int retryLimit = 10;
31893188
do {
31903189
// FIXME: what algorithm should we use for API keys?
31913190
KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1");
31923191
SecretKey key = generator.generateKey();
31933192
encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded());
3194-
userAcct = _accountDao.findUserAccountByApiKey(encodedKey);
3193+
userAcct = _userAccountDao.getUserByApiKey(encodedKey);
31953194
retryLimit--;
31963195
} while ((userAcct != null) && (retryLimit >= 0));
31973196

0 commit comments

Comments
 (0)