Search in sources :

Example 1 with DaoAuthenticationProvider

use of org.springframework.security.authentication.dao.DaoAuthenticationProvider in project spring-security by spring-projects.

the class JdbcUserServiceBeanDefinitionParserTests method cacheIsInjectedIntoAuthenticationProvider.

@Test
public void cacheIsInjectedIntoAuthenticationProvider() {
    setContext("<authentication-manager>" + "  <authentication-provider>" + "    <jdbc-user-service cache-ref='userCache' data-source-ref='dataSource'/>" + "  </authentication-provider>" + "</authentication-manager>" + DATA_SOURCE + USER_CACHE_XML);
    ProviderManager mgr = (ProviderManager) appContext.getBean(BeanIds.AUTHENTICATION_MANAGER);
    DaoAuthenticationProvider provider = (DaoAuthenticationProvider) mgr.getProviders().get(0);
    assertThat(appContext.getBean("userCache")).isSameAs(provider.getUserCache());
    provider.authenticate(new UsernamePasswordAuthenticationToken("rod", "koala"));
    assertThat(provider.getUserCache().getUserFromCache("rod")).isNotNull().withFailMessage("Cache should contain user after authentication");
}
Also used : DaoAuthenticationProvider(org.springframework.security.authentication.dao.DaoAuthenticationProvider) ProviderManager(org.springframework.security.authentication.ProviderManager) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 2 with DaoAuthenticationProvider

use of org.springframework.security.authentication.dao.DaoAuthenticationProvider 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;
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) UserDetails(org.springframework.security.core.userdetails.UserDetails) DaoAuthenticationProvider(org.springframework.security.authentication.dao.DaoAuthenticationProvider) ProviderManager(org.springframework.security.authentication.ProviderManager) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService)

Aggregations

ProviderManager (org.springframework.security.authentication.ProviderManager)2 DaoAuthenticationProvider (org.springframework.security.authentication.dao.DaoAuthenticationProvider)2 Test (org.junit.Test)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)1