Skip to content

Find mixed-case usernames in InMemoryUserDetailsManager#changePassword - #19337

Merged
jzheaux merged 1 commit into
spring-projects:7.0.xfrom
junhyeong9812:fix/inmemoryuserdetailsmanager-changepassword-case
Aug 13, 2026
Merged

Find mixed-case usernames in InMemoryUserDetailsManager#changePassword#19337
jzheaux merged 1 commit into
spring-projects:7.0.xfrom
junhyeong9812:fix/inmemoryuserdetailsmanager-changepassword-case

Conversation

@junhyeong9812

Copy link
Copy Markdown
Contributor

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2026
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>
@jzheaux
jzheaux force-pushed the fix/inmemoryuserdetailsmanager-changepassword-case branch from 02e7f15 to f467d3b Compare August 13, 2026 17:10
@jzheaux jzheaux removed the status: waiting-for-triage An issue we've not yet triaged label Aug 13, 2026
@jzheaux jzheaux self-assigned this Aug 13, 2026
@jzheaux jzheaux added type: bug A general bug in: core An issue in spring-security-core labels Aug 13, 2026
@jzheaux jzheaux added this to the 7.0.7 milestone Aug 13, 2026
@jzheaux
jzheaux changed the base branch from main to 7.0.x August 13, 2026 17:10
@jzheaux jzheaux changed the title Lowercase username in InMemoryUserDetailsManager.changePassword Find mixed-case usernames in InMemoryUserDetailsManager#changePassword Aug 13, 2026
@jzheaux
jzheaux merged commit 9fdd2dc into spring-projects:7.0.x Aug 13, 2026
7 checks passed
@jzheaux

jzheaux commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks, @junhyeong9812! This is now merged into 7.0.x and will go out in the next release.

@junhyeong9812

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, @jzheaux — and thank you for maintaining such a great framework. Happy to contribute back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core An issue in spring-security-core type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InMemoryUserDetailsManager.changePassword fails for non-lowercase usernames

3 participants