How to configure Spring UserCache with EhCacheBasedUserCache?

1.2k views Asked by At

The goal is to configure Spring to use UserCache interface for retrieving user details from cache.

Spring configures default

public class DaoAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider

when we use standard security configuration. Nothing exceptional. By default the cache logic in the AbstractUserDetailsAuthenticationProvider uses `NullUserCache' implementation.

Another implementation(wrapper?) for the interface provided is: org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache

with setter setCache(Ehcache ehcache)

Questions:

A. How to configure this ehcache instance, do I need full blown cache manager for my scenario?

B. How to override Spring default bean(DaoAuthenticationProvider) ? Just declare my own with the same name and then set the cache on it or autowire and then set the cache on it?

1

There are 1 answers

0
Louis Jacomet On

With regards to point A, yes you need a CacheManagerin order to get hold of an Cache instance with Ehcache.