use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserServiceBeanDefinitionParserTests method disabledAndEmbeddedFlagsAreSupported.
@Test
public void disabledAndEmbeddedFlagsAreSupported() {
setContext("<user-service id='service'>" + " <user name='joe' password='joespassword' authorities='ROLE_A' locked='true'/>" + " <user name='Bob' password='bobspassword' authorities='ROLE_A' disabled='true'/>" + "</user-service>");
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
UserDetails joe = userService.loadUserByUsername("joe");
assertThat(joe.isAccountNonLocked()).isFalse();
// Check case-sensitive lookup SEC-1432
UserDetails bob = userService.loadUserByUsername("Bob");
assertThat(bob.isEnabled()).isFalse();
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserServiceBeanDefinitionParserTests method userWithBothPropertiesAndEmbeddedUsersThrowsException.
@Test(expected = FatalBeanException.class)
public void userWithBothPropertiesAndEmbeddedUsersThrowsException() {
setContext("<user-service id='service' properties='doesntmatter.props'>" + " <user name='joe' password='joespassword' authorities='ROLE_A'/>" + "</user-service>");
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
userService.loadUserByUsername("Joe");
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class GlobalMethodSecurityBeanDefinitionParserTests method worksWithAspectJAutoproxy.
@Test(expected = AccessDeniedException.class)
public void worksWithAspectJAutoproxy() {
setContext("<global-method-security>" + " <protect-pointcut expression='execution(* org.springframework.security.config.*Service.*(..))'" + " access='ROLE_SOMETHING' />" + "</global-method-security>" + "<b:bean id='myUserService' class='org.springframework.security.config.PostProcessedMockUserDetailsService'/>" + "<aop:aspectj-autoproxy />" + "<authentication-manager>" + " <authentication-provider user-service-ref='myUserService'/>" + "</authentication-manager>");
UserDetailsService service = (UserDetailsService) appContext.getBean("myUserService");
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password", AuthorityUtils.createAuthorityList("ROLE_SOMEOTHERROLE"));
SecurityContextHolder.getContext().setAuthentication(token);
service.loadUserByUsername("notused");
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserDetailsServiceLdapAuthoritiesPopulatorTests method delegationToUserDetailsServiceReturnsCorrectRoles.
@Test
public void delegationToUserDetailsServiceReturnsCorrectRoles() throws Exception {
UserDetailsService uds = mock(UserDetailsService.class);
UserDetails user = mock(UserDetails.class);
when(uds.loadUserByUsername("joe")).thenReturn(user);
List authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
when(user.getAuthorities()).thenReturn(authorities);
UserDetailsServiceLdapAuthoritiesPopulator populator = new UserDetailsServiceLdapAuthoritiesPopulator(uds);
Collection<? extends GrantedAuthority> auths = populator.getGrantedAuthorities(new DirContextAdapter(), "joe");
assertThat(auths).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(auths).contains("ROLE_USER")).isTrue();
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class DigestAuthenticationFilterTests method setUp.
@Before
public void setUp() {
SecurityContextHolder.clearContext();
// Create User Details Service
UserDetailsService uds = new UserDetailsService() {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return new User("rod,ok", "koala", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
}
};
DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint();
ep.setRealmName(REALM);
ep.setKey(KEY);
filter = new DigestAuthenticationFilter();
filter.setUserDetailsService(uds);
filter.setAuthenticationEntryPoint(ep);
request = new MockHttpServletRequest("GET", REQUEST_URI);
request.setServletPath(REQUEST_URI);
}
Aggregations