Skip to content

Lowercase username in InMemoryUserDetailsManager.changePassword#19337

Open
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/inmemoryuserdetailsmanager-changepassword-case
Open

Lowercase username in InMemoryUserDetailsManager.changePassword#19337
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/inmemoryuserdetailsmanager-changepassword-case

Conversation

@junhyeong9812

Copy link
Copy Markdown

Overview

InMemoryUserDetailsManager.changePassword(...) fails for users whose username contains uppercase letters.

Problem

The manager keys its Map<String, MutableUserDetails> users on the lower-cased username in createUser, updateUser, deleteUser, userExists, loadUserByUsername, and updatePassword. Only changePassword(...) looked the current user up with the raw name:

String username = currentUser.getName();
...
MutableUserDetails user = this.users.get(username); // not lower-cased
Assert.state(user != null, "Current user doesn't exist in database.");

So a user created as e.g. User.withUsername("User")... (stored under the key "user") cannot change its password: users.get("User") is null and IllegalStateException("Current user doesn't exist in database.") is thrown, even though authentication and every other operation on that user succeed.

Fix

Lower-case the lookup key, matching the rest of the class:

MutableUserDetails user = this.users.get(username.toLowerCase(Locale.ROOT));

A regression test creates the manager with an uppercase username, authenticates as that user, and asserts changePassword(...) updates the password (observed through loadUserByUsername).

Closes gh-19336

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 spring-projectsgh-19336

Signed-off-by: junhyeong9812 <pickjog@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InMemoryUserDetailsManager.changePassword fails for non-lowercase usernames

2 participants