Skip to content

Commit 6d24217

Browse files
authored
server: Allow admins to disable the 2FA of users in subdomains (#7870)
1 parent ddc2a36 commit 6d24217

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,7 +3327,7 @@ protected UserTwoFactorAuthenticationSetupResponse enableTwoFactorAuthentication
33273327
protected UserTwoFactorAuthenticationSetupResponse disableTwoFactorAuthentication(Long userId, Account caller, Account owner) {
33283328
UserVO userVO = null;
33293329
if (userId != null) {
3330-
userVO = validateUser(userId, caller.getDomainId());
3330+
userVO = validateUser(userId);
33313331
owner = _accountService.getActiveAccountById(userVO.getAccountId());
33323332
} else {
33333333
userId = CallContext.current().getCallingUserId();
@@ -3349,16 +3349,13 @@ protected UserTwoFactorAuthenticationSetupResponse disableTwoFactorAuthenticatio
33493349
return response;
33503350
}
33513351

3352-
private UserVO validateUser(Long userId, Long domainId) {
3352+
private UserVO validateUser(Long userId) {
33533353
UserVO user = null;
33543354
if (userId != null) {
33553355
user = _userDao.findById(userId);
33563356
if (user == null) {
33573357
throw new InvalidParameterValueException("Invalid user ID provided");
33583358
}
3359-
if (_accountDao.findById(user.getAccountId()).getDomainId() != domainId) {
3360-
throw new InvalidParameterValueException("User doesn't belong to the specified account or domain");
3361-
}
33623359
}
33633360
return user;
33643361
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,28 +875,27 @@ public void testEnableUserTwoFactorAuthentication() {
875875
@Test
876876
public void testDisableUserTwoFactorAuthentication() {
877877
Long userId = 1L;
878+
Long accountId = 2L;
878879

879880
UserVO userVO = Mockito.mock(UserVO.class);
880881
Account caller = Mockito.mock(Account.class);
882+
Account owner = Mockito.mock(Account.class);
881883

882-
AccountVO accountMock = Mockito.mock(AccountVO.class);
883884
Mockito.doNothing().when(accountManagerImpl).checkAccess(nullable(Account.class), Mockito.isNull(), nullable(Boolean.class), nullable(Account.class));
884885

885-
Mockito.when(caller.getDomainId()).thenReturn(1L);
886886
Mockito.when(userDaoMock.findById(userId)).thenReturn(userVO);
887-
Mockito.when(userVO.getAccountId()).thenReturn(1L);
888-
Mockito.when(_accountDao.findById(1L)).thenReturn(accountMock);
889-
Mockito.when(accountMock.getDomainId()).thenReturn(1L);
890-
Mockito.when(_accountService.getActiveAccountById(1L)).thenReturn(caller);
887+
Mockito.when(userVO.getAccountId()).thenReturn(accountId);
888+
Mockito.when(_accountService.getActiveAccountById(accountId)).thenReturn(owner);
891889

892890
userVoMock.setKeyFor2fa("EUJEAEDVOURFZTE6OGWVTJZMI54QGMIL");
893891
userVoMock.setUser2faProvider("totp");
894892
userVoMock.setUser2faEnabled(true);
895893

896894
Mockito.when(userDaoMock.createForUpdate()).thenReturn(userVoMock);
897895

898-
UserTwoFactorAuthenticationSetupResponse response = accountManagerImpl.disableTwoFactorAuthentication(userId, caller, caller);
896+
UserTwoFactorAuthenticationSetupResponse response = accountManagerImpl.disableTwoFactorAuthentication(userId, caller, owner);
899897

898+
Mockito.verify(accountManagerImpl).checkAccess(caller, null, true, owner);
900899
Assert.assertNull(response.getSecretCode());
901900
Assert.assertNull(userVoMock.getKeyFor2fa());
902901
Assert.assertNull(userVoMock.getUser2faProvider());

0 commit comments

Comments
 (0)