Search in sources :

Example 1 with UserDetailsByNameServiceWrapper

use of org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper 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 = 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);
}
Also used : CachingUserDetailsService(org.springframework.security.config.authentication.CachingUserDetailsService) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) AuthenticationUserDetailsService(org.springframework.security.core.userdetails.AuthenticationUserDetailsService) AuthenticationUserDetailsService(org.springframework.security.core.userdetails.AuthenticationUserDetailsService) UserDetailsByNameServiceWrapper(org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper) ApplicationContextException(org.springframework.context.ApplicationContextException)

Aggregations

ApplicationContextException (org.springframework.context.ApplicationContextException)1 CachingUserDetailsService (org.springframework.security.config.authentication.CachingUserDetailsService)1 AuthenticationUserDetailsService (org.springframework.security.core.userdetails.AuthenticationUserDetailsService)1 UserDetailsByNameServiceWrapper (org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper)1 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)1