Skip to content

Make it easier to configure a UserCache for a UserDetailsService #4139

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

Closed
mdeinum opened this issue Nov 25, 2016 · 4 comments
Closed

Make it easier to configure a UserCache for a UserDetailsService #4139

mdeinum opened this issue Nov 25, 2016 · 4 comments
Assignees
Labels
in: core An issue in spring-security-core
Milestone

Comments

@mdeinum
Copy link
Contributor

mdeinum commented Nov 25, 2016

When using the XML namespace to configure a user-service it was pretty easy to make it a caching one by adding a reference using the cache-ref attribute and point it to a UserCache implementation.

With Java based configuration this option is only available for the jdbcAuthentication and not for a plain UserDetailsService or LdapUserDetailsService.

It would be nice if it was possible to specify a userCache for each option available and that that would wrap the UserDetailsService in a CachingUserDetailsService when needed.

Related: #2837

Stackoverflow: http://stackoverflow.com/questions/40766098/springcachebasedusercache-is-null/40782952?noredirect=1#comment68816495_40782952

@gpaul-idexx
Copy link

It looks to me like CachingUserDetailService is not intended for direct usage given the non-public constructor. I think the intent for caching is that we set a cache on a AbstractUserDetailsAuthenticationProvider. I believe the approach for java config would be for there to be a userCache method added to AbstractDaoAuthenticationConfigurer so that we can do:

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(myUserDetailsService).userCache(myUserCache);
}

I'd be willing to take a crack at issuing a PR for this trivial change if the spring folks would like.

@ir73
Copy link
Contributor

ir73 commented Nov 28, 2018

any updates on this? was this merged?

@rwinch
Copy link
Member

rwinch commented Nov 30, 2018

Thanks for the the ping @ir73!

This has not been implemented. We would welcome a PR for this.

I'd suggest that we move CachingUserDetailsService to org.springframework.security.core.userdetails in spring-security-core. Then make the constructor public.

User's can then construct CachingUserDetailsService directly.

Would you be interested in submitting a PR for this?

@rwinch rwinch added the in: core An issue in spring-security-core label Nov 30, 2018
@ir73
Copy link
Contributor

ir73 commented Nov 30, 2018

Sure, here we go #6196

ir73 added a commit to ir73/spring-security that referenced this issue Dec 5, 2018
Made CachingUserDetailsService constructor public and moved to spring-core to make it easier to configure caching in UserDetailsService

Fixes spring-projectsgh-4139
@rwinch rwinch closed this as completed in 9a357f8 Dec 11, 2018
@rwinch rwinch added this to the 5.2.0.M1 milestone Dec 11, 2018
@rwinch rwinch self-assigned this Dec 11, 2018
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
Projects
None yet
Development

No branches or pull requests

4 participants