Skip to content
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

Preserve custom user type in InMemoryUserDetailsManager #15498

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

MrJovanovic13
Copy link
Contributor

This PR fixes issue gh-3192 by allowing MutableUserDetails to be stored and loaded inside the InMemoryUserDetailsManager instead of always wrapping it into MutableUser. The custom user type must implement CredentialsContainer in order to be returned by loadUserByUsername() and not transformed into User.

I wanted to write tests for the new cases, and I saw that methods were not previously covered so I wrote tests for all cases for createUser() and loadUserByUsername(). However, I have concerns about some tests:
createUserWhenNotInstanceOfMutableUserDetailsThenShouldWrapIntoMutableUser and
createUserWhenInstanceOfMutableUserDetailsThenShouldNotWrapIntoMutableUser can't directly access Map<String, MutableUserDetails> users to get the underlying user & type, so they are relying on loadUserByUsername to get the user and as such are not pure.
If you think this can be improved somehow, I am open to feedback.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 29, 2024
@jzheaux jzheaux changed the title InMemoryUserDetailsManager preserve user type Preserve custom user type in InMemoryUserDetailsManager Jul 29, 2024
Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @MrJovanovic13, for the PR! I've left some feedback inline.

@jzheaux jzheaux added in: core An issue in spring-security-core type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 29, 2024
@jzheaux jzheaux self-assigned this Jul 29, 2024
Tests added:
createUserWhenUserAlreadyExistsThenException
updateUserWhenUserDoesNotExistThenException
loadUserByUsernameWhenUserNullThenException

Issue spring-projectsgh-3192
@jzheaux
Copy link
Contributor

jzheaux commented Aug 9, 2024

Thanks again, @MrJovanovic13! This is now merged into main.

@jzheaux jzheaux merged commit 6d657ea into spring-projects:main Aug 9, 2024
4 checks passed
@jzheaux jzheaux added this to the 6.4.0-M2 milestone Aug 13, 2024
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: enhancement A general enhancement
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants