-
Notifications
You must be signed in to change notification settings - Fork 6.1k
SEC-2983: InMemoryUserDetailsManager#loadUserByUsername should preserve custom UserDetails types #3192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe one benefit is that
Things have obviously changed a lot since the 3.x days. Today publishing a That said, one thing I think we could do is store any public void createUser(UserDetails user) {
if (user instanceof MutableUserDetails mutable) {
this.users.put(user.getUsername().toLowerCase(), mutable);
} else {
this.users.put(user.getUsername().toLowerCase(), new MutableUser(user));
}
}
// ...
public UserDetails loadUserByUsername(String username) ...
UserDetails user = this.users.get(username.toLowerCase());
if (user == null ) ...
if (user instanceof CredentialsContainer container) {
return container;
}
return new User(...);
} In this way, I believe the credential-clearing functionality would be preserved, |
Tests added: createUserWhenUserAlreadyExistsThenException updateUserWhenUserDoesNotExistThenException loadUserByUsernameWhenUserNullThenException Issue spring-projectsgh-3192
Tests added: createUserWhenUserAlreadyExistsThenException updateUserWhenUserDoesNotExistThenException loadUserByUsernameWhenUserNullThenException Issue gh-3192
William Gorder (Migrated from SEC-2983) said:
Is there a good reason for not returning MutableUser.delegate in the InMemoryUserDetailsManager.loadUserByUsername() method? What I have run into is I want to provide my own user details, so I pass them to the create() method but when I get them back from authentication.getPrincipal() its been replaced with the vanilla spring security User object since apparently rather then just returning the UserDetails that we already have it takes the delegate and creates a new org.springframework.security.core.userdetails.User.
What I am proposing is a something different then the MutableUserDetails interface. The MutableUser object would need to expose its delegate so that it could be returned if it exists. Currently the only way to get what I want is to create my own version of InMemoryUserDetailsManager and InMemoryUserDetailsManagerConfigurer unless I am missing something. It just seems that by exposing a create(UserDetails) method it is implied that we would get the UserDetails provided and not something different. I see this bit of the API as confusing and bit misleading. There is nothing in the Java Doc implying that that underlying implementation will be changed.
The text was updated successfully, but these errors were encountered: