Skip to content

Handle null UserDetails in TokenBasedRememberMeServices - #19672

Closed
GangEunzzang wants to merge 1 commit into
spring-projects:mainfrom
GangEunzzang:gh-19535
Closed

Handle null UserDetails in TokenBasedRememberMeServices#19672
GangEunzzang wants to merge 1 commit into
spring-projects:mainfrom
GangEunzzang:gh-19535

Conversation

@GangEunzzang

Copy link
Copy Markdown

TokenBasedRememberMeServices#onLoginSuccess falls back to UserDetailsService#loadUserByUsername when the Authentication carries no password, and then reads getPassword() on the result without checking it. A UserDetailsService that returns null for a user (the reporter's case: only some users support remember-me) therefore throws a NullPointerException on login.

The method already returns without setting a cookie when the password cannot be obtained, so a null UserDetails now takes the same path, with its own debug message.

Adds loginSuccessWhenUserDetailsServiceReturnsNullThenNoCookieIsSet, built on the existing udsWillReturnNull() setup; it throws on main and passes here.

Closes gh-19535

onLoginSuccess reads getPassword() on the UserDetails returned by
the UserDetailsService without checking it, so a service that
returns null throws a NullPointerException. Return without setting
a cookie instead, as is already done when the password is missing.

Closes spring-projectsgh-19535

Signed-off-by: 이강은 <rkddms123456@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 7, 2026
@GangEunzzang

Copy link
Copy Markdown
Author

Closing — #19552 already has this exact change, with the reporter's feedback folded in, and I missed it before opening this one. Sorry for the noise.

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.

TokenBasedRememberMeServices::onLoginSuccess can throw a NPE when UserDetailsService::loadUserByUsername returns null.

2 participants