Skip to content

Commit 28691a5

Browse files
dont allow ldap and saml users to change their password
1 parent a2690e9 commit 28691a5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,8 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
14591459
* <ul>
14601460
* <li> If 'password' is blank, we throw an {@link InvalidParameterValueException};
14611461
* <li> If 'current password' is not provided and user is not an Admin, we throw an {@link InvalidParameterValueException};
1462+
* <li> If the user whose password is being changed has a source equal to {@link User.Source#SAML2}, {@link User.Source#SAML2DISABLED} or {@link User.Source#LDAP},
1463+
* we throw an {@link InvalidParameterValueException};
14621464
* <li> If a normal user is calling this method, we use {@link #validateCurrentPassword(UserVO, String)} to check if the provided old password matches the database one;
14631465
* </ul>
14641466
*
@@ -1473,6 +1475,11 @@ protected void validateUserPasswordAndUpdateIfNeeded(String newPassword, UserVO
14731475
throw new InvalidParameterValueException("Password cannot be empty or blank.");
14741476
}
14751477

1478+
User.Source userSource = user.getSource();
1479+
if (userSource == User.Source.SAML2 || userSource == User.Source.SAML2DISABLED || userSource == User.Source.LDAP) {
1480+
throw new InvalidParameterValueException("CloudStack does not support updating passwords for SAML or LDAP users. Please contact your cloud administrator for assistance.");
1481+
}
1482+
14761483
passwordPolicy.verifyIfPasswordCompliesWithPasswordPolicies(newPassword, user.getUsername(), getAccount(user.getAccountId()).getDomainId());
14771484

14781485
Account callingAccount = getCurrentCallingAccount();

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,36 @@ public void validateUserPasswordAndUpdateIfNeededTestIfVerifyIfPasswordCompliesW
745745
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword);
746746
}
747747

748+
@Test(expected = InvalidParameterValueException.class)
749+
public void validateUserPasswordAndUpdateIfNeededTestSaml2UserShouldNotBeAllowedToUpdateTheirPassword() {
750+
String newPassword = "newPassword";
751+
String currentPassword = "theCurrentPassword";
752+
753+
Mockito.when(userVoMock.getSource()).thenReturn(User.Source.SAML2);
754+
755+
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword);
756+
}
757+
758+
@Test(expected = InvalidParameterValueException.class)
759+
public void validateUserPasswordAndUpdateIfNeededTestSaml2DisabledUserShouldNotBeAllowedToUpdateTheirPassword() {
760+
String newPassword = "newPassword";
761+
String currentPassword = "theCurrentPassword";
762+
763+
Mockito.when(userVoMock.getSource()).thenReturn(User.Source.SAML2DISABLED);
764+
765+
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword);
766+
}
767+
768+
@Test(expected = InvalidParameterValueException.class)
769+
public void validateUserPasswordAndUpdateIfNeededTestLdapUserShouldNotBeAllowedToUpdateTheirPassword() {
770+
String newPassword = "newPassword";
771+
String currentPassword = "theCurrentPassword";
772+
773+
Mockito.when(userVoMock.getSource()).thenReturn(User.Source.LDAP);
774+
775+
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword);
776+
}
777+
748778
private String configureUserMockAuthenticators(String newPassword) {
749779
accountManagerImpl._userPasswordEncoders = new ArrayList<>();
750780
UserAuthenticator authenticatorMock1 = Mockito.mock(UserAuthenticator.class);

0 commit comments

Comments
 (0)