use of org.springframework.security.authentication.CachingUserDetailsService in project spring-security by spring-projects.
the class JdbcUserServiceBeanDefinitionParserTests method cacheRefIsparsedCorrectly.
@Test
public void cacheRefIsparsedCorrectly() {
setContext("<jdbc-user-service id='myUserService' cache-ref='userCache' data-source-ref='dataSource'/>" + DATA_SOURCE + USER_CACHE_XML);
CachingUserDetailsService cachingUserService = (CachingUserDetailsService) this.appContext.getBean("myUserService" + AbstractUserDetailsServiceBeanDefinitionParser.CACHING_SUFFIX);
assertThat(this.appContext.getBean("userCache")).isSameAs(cachingUserService.getUserCache());
assertThat(cachingUserService.loadUserByUsername("rod")).isNotNull();
assertThat(cachingUserService.loadUserByUsername("rod")).isNotNull();
}
use of org.springframework.security.authentication.CachingUserDetailsService in project spring-security by spring-projects.
the class UserDetailsServiceFactoryBean method authenticationUserDetailsService.
@SuppressWarnings("unchecked")
AuthenticationUserDetailsService authenticationUserDetailsService(String name) {
UserDetailsService uds;
if (!StringUtils.hasText(name)) {
Map<String, ?> beans = getBeansOfType(AuthenticationUserDetailsService.class);
if (!beans.isEmpty()) {
if (beans.size() > 1) {
throw new ApplicationContextException("More than one AuthenticationUserDetailsService registered." + " Please use a specific Id reference.");
}
return (AuthenticationUserDetailsService) beans.values().toArray()[0];
}
uds = getUserDetailsService();
} else {
Object bean = this.beanFactory.getBean(name);
if (bean instanceof AuthenticationUserDetailsService) {
return (AuthenticationUserDetailsService) bean;
} else if (bean instanceof UserDetailsService) {
uds = cachingUserDetailsService(name);
if (uds == null) {
uds = (UserDetailsService) bean;
}
} else {
throw new ApplicationContextException("Bean '" + name + "' must be a UserDetailsService or an" + " AuthenticationUserDetailsService");
}
}
return new UserDetailsByNameServiceWrapper(uds);
}
Aggregations