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();
}
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);
}
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();
}
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");
}
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;
}
Aggregations