Fail fast when UserDetailsService returns null in onLoginSuccess - #19552
Open
skdas20 wants to merge 1 commit into
Open
Fail fast when UserDetailsService returns null in onLoginSuccess#19552skdas20 wants to merge 1 commit into
skdas20 wants to merge 1 commit into
Conversation
onLoginSuccess dereferenced the result of loadUserByUsername without a null check, so a UserDetailsService returning null instead of throwing UsernameNotFoundException surfaced as a bare NullPointerException from inside the remember-me filter. processAutoLoginCookie already guards the same call and treats a null return as an interface contract violation. Apply the same guard to onLoginSuccess so both lookups report the misconfiguration consistently. Closes spring-projectsgh-19535 Signed-off-by: skdas20 <skdas5405@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the successful
Authenticationcarries no credentials,onLoginSuccessfalls back to looking the password up through the configuredUserDetailsService, but dereferences the result without checking it:A
UserDetailsServicethat returnsnullrather than throwingUsernameNotFoundExceptiontherefore shows up as a bareNullPointerExceptionfrom inside the remember-me filter, with nothing in the stack trace pointing at the service that is actually misconfigured.processAutoLoginCookiein this same class already guards the identical call, and is explicit about what anullreturn means:autoLoginClearsCookieIfUserServiceMisconfiguredpins that behaviour in the tests. This change applies the same guard toonLoginSuccessso both lookups report the misconfiguration the same way, and addsloginSuccessFailsIfUserServiceMisconfiguredalongside the existingloginSuccesstests. Without the production change that test fails with the reportedNullPointerException.One note on the approach: gh-19535 suggests skipping cookie generation instead, with
I went with the existing in-class precedent rather than that, because silently continuing would quietly swallow a misconfiguration that the class elsewhere treats as a contract violation — and the user would get no remember-me cookie with no indication why. Happy to switch to the lenient form if you'd rather keep
onLoginSuccesstolerant; it's a small change either way.Closes gh-19535