1
0
mirror of synced 2026-08-23 10:37:39 +00:00

Lowercase username in changePassword lookup

InMemoryUserDetailsManager keys its user map on the lower-cased
username everywhere except changePassword, which looked the current
user up with the raw name. A user whose username contains uppercase
letters could therefore not change its password. Lower-case the
lookup key to match the rest of the class.

Closes gh-19336

Signed-off-by: junhyeong9812 <pickjog@gmail.com>
This commit is contained in:
junhyeong9812
2026-06-14 18:39:24 +09:00
committed by Josh Cummings
parent 2aa3c1ab2e
commit 9fdd2dc675
2 changed files with 17 additions and 1 deletions
@@ -149,7 +149,7 @@ public class InMemoryUserDetailsManager implements UserDetailsManager, UserDetai
else {
this.logger.debug("No authentication manager set. Password won't be re-checked.");
}
MutableUserDetails user = this.users.get(username);
MutableUserDetails user = this.users.get(username.toLowerCase(Locale.ROOT));
Assert.state(user != null, "Current user doesn't exist in database.");
user.setPassword(newPassword);
}
@@ -123,6 +123,22 @@ public class InMemoryUserDetailsManagerTests {
verify(strategy).getContext();
}
@Test
public void changePasswordWhenCurrentUsernameIsNotInLowercaseThenChangesPassword() {
UserDetails userNotLowerCase = User.withUserDetails(PasswordEncodedUser.user()).username("User").build();
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(userNotLowerCase);
Authentication authentication = new UsernamePasswordAuthenticationToken("User", userNotLowerCase.getPassword(),
userNotLowerCase.getAuthorities());
SecurityContextHolderStrategy strategy = mock(SecurityContextHolderStrategy.class);
given(strategy.getContext()).willReturn(new SecurityContextImpl(authentication));
manager.setSecurityContextHolderStrategy(strategy);
String newPassword = "newPassword";
manager.changePassword(userNotLowerCase.getPassword(), newPassword);
assertThat(manager.loadUserByUsername("User").getPassword()).isEqualTo(newPassword);
}
@Test
public void createUserWhenUserAlreadyExistsThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.manager.createUser(this.user))