Search in sources :

Example 1 with ProviderManager

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

the class AuthenticationManagerBeanDefinitionParserTests method clearCredentialsPropertyIsRespected.

@Test
public void clearCredentialsPropertyIsRespected() throws Exception {
    setContext("<authentication-manager erase-credentials='false'/>");
    ProviderManager pm = (ProviderManager) appContext.getBeansOfType(ProviderManager.class).values().toArray()[0];
    assertThat(pm.isEraseCredentialsAfterAuthentication()).isFalse();
}
Also used : ProviderManager(org.springframework.security.authentication.ProviderManager) Test(org.junit.Test)

Example 2 with ProviderManager

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

the class AuthenticationManagerBeanDefinitionParserTests method eventsArePublishedByDefault.

@Test
public void eventsArePublishedByDefault() throws Exception {
    setContext(CONTEXT);
    AuthListener listener = new AuthListener();
    appContext.addApplicationListener(listener);
    ProviderManager pm = (ProviderManager) appContext.getBeansOfType(ProviderManager.class).values().toArray()[0];
    Object eventPublisher = FieldUtils.getFieldValue(pm, "eventPublisher");
    assertThat(eventPublisher).isNotNull();
    assertThat(eventPublisher instanceof DefaultAuthenticationEventPublisher).isTrue();
    pm.authenticate(new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
    assertThat(listener.events).hasSize(1);
}
Also used : DefaultAuthenticationEventPublisher(org.springframework.security.authentication.DefaultAuthenticationEventPublisher) ProviderManager(org.springframework.security.authentication.ProviderManager) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 3 with ProviderManager

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

the class AuthenticationManagerBeanDefinitionParserTests method credentialsAreClearedByDefault.

@Test
public void credentialsAreClearedByDefault() throws Exception {
    setContext(CONTEXT);
    ProviderManager pm = (ProviderManager) appContext.getBeansOfType(ProviderManager.class).values().toArray()[0];
    assertThat(pm.isEraseCredentialsAfterAuthentication()).isTrue();
}
Also used : ProviderManager(org.springframework.security.authentication.ProviderManager) Test(org.junit.Test)

Example 4 with ProviderManager

use of org.springframework.security.authentication.ProviderManager 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 5 with ProviderManager

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

the class AuthenticationManagerBuilder method performBuild.

@Override
protected ProviderManager performBuild() throws Exception {
    if (!isConfigured()) {
        logger.debug("No authenticationProviders and no parentAuthenticationManager defined. Returning null.");
        return null;
    }
    ProviderManager providerManager = new ProviderManager(authenticationProviders, parentAuthenticationManager);
    if (eraseCredentials != null) {
        providerManager.setEraseCredentialsAfterAuthentication(eraseCredentials);
    }
    if (eventPublisher != null) {
        providerManager.setAuthenticationEventPublisher(eventPublisher);
    }
    providerManager = postProcess(providerManager);
    return providerManager;
}
Also used : ProviderManager(org.springframework.security.authentication.ProviderManager)

Aggregations

ProviderManager (org.springframework.security.authentication.ProviderManager)7 Test (org.junit.Test)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 DaoAuthenticationProvider (org.springframework.security.authentication.dao.DaoAuthenticationProvider)2 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)1 DefaultAuthenticationEventPublisher (org.springframework.security.authentication.DefaultAuthenticationEventPublisher)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)1 PreAuthenticatedAuthenticationProvider (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1