use of org.springframework.security.core.userdetails.UserDetails 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;
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-boot by spring-projects.
the class ManagementWebSecurityAutoConfigurationTests method testWebConfigurationWithExtraRole.
@Test
public void testWebConfigurationWithExtraRole() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(WebConfiguration.class);
this.context.refresh();
UserDetails user = getUser();
ArrayList<GrantedAuthority> authorities = new ArrayList<>(user.getAuthorities());
assertThat(authorities).containsAll(AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ACTUATOR"));
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class LdapUserServiceBeanDefinitionParserTests method externalContextMapperIsSupported.
@Test
public void externalContextMapperIsSupported() {
setContext("<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>" + "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-context-mapper-ref='mapper'/>" + "<b:bean id='mapper' class='" + InetOrgPersonContextMapper.class.getName() + "'/>");
UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
UserDetails ben = uds.loadUserByUsername("ben");
assertThat(ben instanceof InetOrgPerson).isTrue();
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class LdapUserServiceBeanDefinitionParserTests method userServiceReturnsExpectedData.
@Test
public void userServiceReturnsExpectedData() throws Exception {
setContext("<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");
UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
UserDetails ben = uds.loadUserByUsername("ben");
Set<String> authorities = AuthorityUtils.authorityListToSet(ben.getAuthorities());
assertThat(authorities).hasSize(3);
assertThat(authorities.contains("ROLE_DEVELOPERS")).isTrue();
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class LdapUserServiceBeanDefinitionParserTests method personContextMapperIsSupported.
@Test
public void personContextMapperIsSupported() {
setContext("<ldap-server ldif='classpath:test-server.ldif'/>" + "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-details-class='person'/>");
UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
UserDetails ben = uds.loadUserByUsername("ben");
assertThat(ben instanceof Person).isTrue();
}
Aggregations