Skip to content

Commit a099946

Browse files
committed
Fix events generated to set Username, Account and Domain of the caller correctly
1 parent 2fadea9 commit a099946

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,9 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
14701470
logger.debug("Updating user with Id: " + user.getUuid());
14711471

14721472
validateAndUpdateApiAndSecretKeyIfNeeded(updateUserCmd, user);
1473+
validateAndUpdateUserApiKeyAccess(updateUserCmd, user);
14731474
Account account = retrieveAndValidateAccount(user);
14741475

1475-
validateAndUpdateUserApiKeyAccess(updateUserCmd, user, account);
14761476
validateAndUpdateFirstNameIfNeeded(updateUserCmd, user);
14771477
validateAndUpdateLastNameIfNeeded(updateUserCmd, user);
14781478
validateAndUpdateUsernameIfNeeded(updateUserCmd, user, account);
@@ -1690,12 +1690,16 @@ protected void validateAndUpdateApiAndSecretKeyIfNeeded(UpdateUserCmd updateUser
16901690
user.setSecretKey(secretKey);
16911691
}
16921692

1693-
protected void validateAndUpdateUserApiKeyAccess(UpdateUserCmd updateUserCmd, UserVO user, Account account) {
1693+
protected void validateAndUpdateUserApiKeyAccess(UpdateUserCmd updateUserCmd, UserVO user) {
16941694
if (updateUserCmd.getApiKeyAccess() != null) {
16951695
try {
16961696
ApiConstants.ApiKeyAccess access = ApiConstants.ApiKeyAccess.valueOf(updateUserCmd.getApiKeyAccess().toUpperCase());
16971697
user.setApiKeyAccess(access.toBoolean());
1698-
ActionEventUtils.onActionEvent(user.getId(), account.getAccountId(), account.getDomainId(), EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the user to " + access.toString(), user.getId(), ApiCommandResourceType.User.toString());
1698+
Long callingUserId = CallContext.current().getCallingUserId();
1699+
Account callingAccount = CallContext.current().getCallingAccount();
1700+
ActionEventUtils.onActionEvent(callingUserId, callingAccount.getAccountId(), callingAccount.getDomainId(),
1701+
EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the User to " + access.toString(),
1702+
user.getId(), ApiCommandResourceType.User.toString());
16991703
} catch (IllegalArgumentException ex) {
17001704
throw new InvalidParameterValueException("ApiKeyAccess value can only be Enabled/Disabled/Inherit");
17011705
}
@@ -1707,7 +1711,11 @@ protected void validateAndUpdateAccountApiKeyAccess(UpdateAccountCmd updateAccou
17071711
try {
17081712
ApiConstants.ApiKeyAccess access = ApiConstants.ApiKeyAccess.valueOf(updateAccountCmd.getApiKeyAccess().toUpperCase());
17091713
account.setApiKeyAccess(access.toBoolean());
1710-
ActionEventUtils.onActionEvent(User.UID_ADMIN, account.getAccountId(), account.getDomainId(), EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the account to " + access.toString(), account.getId(), ApiCommandResourceType.Account.toString());
1714+
Long callingUserId = CallContext.current().getCallingUserId();
1715+
Account callingAccount = CallContext.current().getCallingAccount();
1716+
ActionEventUtils.onActionEvent(callingUserId, callingAccount.getAccountId(), callingAccount.getDomainId(),
1717+
EventTypes.API_KEY_ACCESS_UPDATE, "Api key access was changed for the Account to " + access.toString(),
1718+
account.getId(), ApiCommandResourceType.Account.toString());
17111719
} catch (IllegalArgumentException ex) {
17121720
throw new InvalidParameterValueException("ApiKeyAccess value can only be Enabled/Disabled/Inherit");
17131721
}

server/src/test/java/com/cloud/user/AccountManagerImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public void validateAndUpdatUserApiKeyAccess() {
520520
Mockito.anyLong(),
521521
Mockito.anyString(), Mockito.anyString(),
522522
Mockito.anyLong(), Mockito.anyString())).thenReturn(1L);
523-
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock, accountMock);
523+
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock);
524524
}
525525

526526
Mockito.verify(userVoMock).setApiKeyAccess(true);
@@ -529,7 +529,7 @@ public void validateAndUpdatUserApiKeyAccess() {
529529
@Test(expected = InvalidParameterValueException.class)
530530
public void validateAndUpdatUserApiKeyAccessInvalidParameter() {
531531
Mockito.doReturn("False").when(UpdateUserCmdMock).getApiKeyAccess();
532-
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock, accountMock);
532+
accountManagerImpl.validateAndUpdateUserApiKeyAccess(UpdateUserCmdMock, userVoMock);
533533
}
534534

535535
@Test

0 commit comments

Comments
 (0)