mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Fixed the bug in updateUser api - api/secretKey update didn't work correctly when request was signed using apiKey
This commit is contained in:
parent
0fefd9f2ae
commit
695041ad27
@ -1398,6 +1398,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
String secretKey = cmd.getSecretKey();
|
||||
String timeZone = cmd.getTimezone();
|
||||
String userName = cmd.getUsername();
|
||||
|
||||
long callerUserId = UserContext.current().getCallerUserId();
|
||||
|
||||
// Input validation
|
||||
UserVO user = _userDao.getUser(id);
|
||||
@ -1405,8 +1407,23 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (user == null) {
|
||||
throw new InvalidParameterValueException("unable to find user by id");
|
||||
}
|
||||
|
||||
if (apiKey != null) {
|
||||
Long apiKeyOwnerId = null;
|
||||
Pair<User, Account> apiKeyOwner = _accountDao.findUserAccountByApiKey(apiKey);
|
||||
if (apiKeyOwner != null) {
|
||||
apiKeyOwnerId = apiKeyOwner.first().getId();
|
||||
}
|
||||
|
||||
if ((apiKeyOwnerId == null || callerUserId != apiKeyOwnerId) && secretKey == null) {
|
||||
throw new InvalidParameterValueException("Please provide an api key/secret key pair");
|
||||
} else if (apiKeyOwnerId != null && callerUserId == apiKeyOwnerId && id != callerUserId) {
|
||||
// No need to update api key if provided api key belongs to the caller and caller updates api key for someone else
|
||||
apiKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ((apiKey == null && secretKey != null) || (apiKey != null && secretKey == null)) {
|
||||
if (apiKey == null && secretKey != null) {
|
||||
throw new InvalidParameterValueException("Please provide an api key/secret key pair");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user