InMemoryUserDetailsManager.updatePassword case-insenstive
Previously updatePassword was case sensitive which was inconsistent with the rest of the class. This commit updates updatePassword to be case insensitive. Fixes: gh-6039
This commit is contained in:
parent
3a6582d2a6
commit
898d005a53
|
@ -143,7 +143,7 @@ public class InMemoryUserDetailsManager implements UserDetailsManager,
|
|||
@Override
|
||||
public UserDetails updatePassword(UserDetails user, String newPassword) {
|
||||
String username = user.getUsername();
|
||||
MutableUserDetails mutableUser = this.users.get(username);
|
||||
MutableUserDetails mutableUser = this.users.get(username.toLowerCase());
|
||||
mutableUser.setPassword(newPassword);
|
||||
return mutableUser;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.security.provisioning;
|
|||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
@ -37,4 +38,15 @@ public class InMemoryUserDetailsManagerTests {
|
|||
this.manager.updatePassword(this.user, newPassword);
|
||||
assertThat(this.manager.loadUserByUsername(this.user.getUsername()).getPassword()).isEqualTo(newPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePasswordWhenUsernameIsNotInLowercase() {
|
||||
UserDetails userNotLowerCase = User.withUserDetails(PasswordEncodedUser.user())
|
||||
.username("User")
|
||||
.build();
|
||||
|
||||
String newPassword = "newPassword";
|
||||
this.manager.updatePassword(userNotLowerCase, newPassword);
|
||||
assertThat(this.manager.loadUserByUsername(userNotLowerCase.getUsername()).getPassword()).isEqualTo(newPassword);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue