Search in sources :

Example 11 with UserDetailsService

use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.

the class DaoAuthenticationProviderTests method testStartupSuccess.

@Test
public void testStartupSuccess() throws Exception {
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    UserDetailsService userDetailsService = new MockAuthenticationDaoUserrod();
    provider.setUserDetailsService(userDetailsService);
    provider.setUserCache(new MockUserCache());
    assertThat(provider.getUserDetailsService()).isEqualTo(userDetailsService);
    provider.afterPropertiesSet();
}
Also used : UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Test(org.junit.Test)

Example 12 with UserDetailsService

use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security-oauth by spring-projects.

the class AuthorizationServerSecurityConfiguration method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    AuthorizationServerSecurityConfigurer configurer = new AuthorizationServerSecurityConfigurer();
    FrameworkEndpointHandlerMapping handlerMapping = endpoints.oauth2EndpointHandlerMapping();
    http.setSharedObject(FrameworkEndpointHandlerMapping.class, handlerMapping);
    configure(configurer);
    http.apply(configurer);
    String tokenEndpointPath = handlerMapping.getServletPath("/oauth/token");
    String tokenKeyPath = handlerMapping.getServletPath("/oauth/token_key");
    String checkTokenPath = handlerMapping.getServletPath("/oauth/check_token");
    if (!endpoints.getEndpointsConfigurer().isUserDetailsServiceOverride()) {
        UserDetailsService userDetailsService = http.getSharedObject(UserDetailsService.class);
        endpoints.getEndpointsConfigurer().userDetailsService(userDetailsService);
    }
    // @formatter:off
    http.authorizeRequests().antMatchers(tokenEndpointPath).fullyAuthenticated().antMatchers(tokenKeyPath).access(configurer.getTokenKeyAccess()).antMatchers(checkTokenPath).access(configurer.getCheckTokenAccess()).and().requestMatchers().antMatchers(tokenEndpointPath, tokenKeyPath, checkTokenPath).and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
    // @formatter:on
    http.setSharedObject(ClientDetailsService.class, clientDetailsService);
}
Also used : AuthorizationServerSecurityConfigurer(org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer) FrameworkEndpointHandlerMapping(org.springframework.security.oauth2.provider.endpoint.FrameworkEndpointHandlerMapping) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService)

Example 13 with UserDetailsService

use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.

the class LdapUserServiceBeanDefinitionParserTests method inetOrgContextMapperIsSupported.

@Test
public void inetOrgContextMapperIsSupported() {
    setContext("<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>" + "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-details-class='inetOrgPerson'/>");
    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails ben = uds.loadUserByUsername("ben");
    assertThat(ben instanceof InetOrgPerson).isTrue();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) Test(org.junit.Test)

Example 14 with UserDetailsService

use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.

the class LdapUserServiceBeanDefinitionParserTests method differentGroupRoleAttributeWorksAsExpected.

@Test
public void differentGroupRoleAttributeWorksAsExpected() throws Exception {
    setContext("<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' group-role-attribute='ou' 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_DEVELOPER")).isTrue();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) Test(org.junit.Test)

Example 15 with UserDetailsService

use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.

the class LdapUserServiceBeanDefinitionParserTests method differentUserSearchBaseWorksAsExpected.

@Test
public void differentUserSearchBaseWorksAsExpected() throws Exception {
    setContext("<ldap-user-service id='ldapUDS' " + "       user-search-base='ou=otherpeople' " + "       user-search-filter='(cn={0})' " + "       group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");
    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails joe = uds.loadUserByUsername("Joe Smeth");
    assertThat(joe.getUsername()).isEqualTo("Joe Smeth");
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) Test(org.junit.Test)

Aggregations

UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)26 Test (org.junit.Test)19 UserDetails (org.springframework.security.core.userdetails.UserDetails)14 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)7 User (org.springframework.security.core.userdetails.User)3 InetOrgPerson (org.springframework.security.ldap.userdetails.InetOrgPerson)3 Before (org.junit.Before)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 Authentication (org.springframework.security.core.Authentication)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Person (org.devgateway.toolkit.persistence.dao.Person)1 ApplicationContextException (org.springframework.context.ApplicationContextException)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 ProviderManager (org.springframework.security.authentication.ProviderManager)1 DaoAuthenticationProvider (org.springframework.security.authentication.dao.DaoAuthenticationProvider)1