use of org.springframework.security.core.userdetails.UserDetailsService 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);
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserServiceBeanDefinitionParserTests method worksWithOpenIDUrlsAsNames.
@Test
public void worksWithOpenIDUrlsAsNames() {
setContext("<user-service id='service'>" + " <user name='http://joe.myopenid.com/' authorities='ROLE_A'/>" + " <user name='https://www.google.com/accounts/o8/id?id=MPtOaenBIk5yzW9n7n9' authorities='ROLE_A'/>" + "</user-service>");
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
assertThat(userService.loadUserByUsername("http://joe.myopenid.com/").getUsername()).isEqualTo("http://joe.myopenid.com/");
assertThat(userService.loadUserByUsername("https://www.google.com/accounts/o8/id?id=MPtOaenBIk5yzW9n7n9").getUsername()).isEqualTo("https://www.google.com/accounts/o8/id?id=MPtOaenBIk5yzW9n7n9");
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserServiceBeanDefinitionParserTests method userServiceWithValidPropertiesFileWorksSuccessfully.
@Test
public void userServiceWithValidPropertiesFileWorksSuccessfully() {
setContext("<user-service id='service' " + "properties='classpath:org/springframework/security/config/users.properties'/>");
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
userService.loadUserByUsername("bob");
userService.loadUserByUsername("joe");
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security-oauth by spring-projects.
the class DefaultUserAuthenticationConverterTests method shouldExtractAuthenticationWhenUserDetailsProvided.
@Test
public void shouldExtractAuthenticationWhenUserDetailsProvided() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(UserAuthenticationConverter.USERNAME, "test_user");
UserDetailsService userDetailsService = Mockito.mock(UserDetailsService.class);
Mockito.when(userDetailsService.loadUserByUsername("test_user")).thenReturn(new User("foo", "bar", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_SPAM")));
converter.setUserDetailsService(userDetailsService);
Authentication authentication = converter.extractAuthentication(map);
assertEquals("ROLE_SPAM", authentication.getAuthorities().iterator().next().toString());
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-boot by spring-projects.
the class ManagementWebSecurityAutoConfigurationTests method getUser.
private UserDetails getUser() {
ProviderManager parent = (ProviderManager) this.context.getBean(AuthenticationManager.class);
DaoAuthenticationProvider provider = (DaoAuthenticationProvider) parent.getProviders().get(0);
UserDetailsService service = (UserDetailsService) ReflectionTestUtils.getField(provider, "userDetailsService");
UserDetails user = service.loadUserByUsername("user");
return user;
}
Aggregations