use of org.springframework.security.authentication.DefaultAuthenticationEventPublisher in project spring-security by spring-projects.
the class AuthenticationManagerBeanDefinitionParserTests method eventsArePublishedByDefault.
@Test
public void eventsArePublishedByDefault() throws Exception {
ConfigurableApplicationContext appContext = this.spring.context(CONTEXT).getContext();
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.DefaultAuthenticationEventPublisher in project spring-security by spring-projects.
the class DefaultAuthenticationEventPublisherBearerTokenTests method publishAuthenticationFailureWhenInvalidBearerTokenExceptionThenMaps.
@Test
public void publishAuthenticationFailureWhenInvalidBearerTokenExceptionThenMaps() {
ApplicationEventPublisher appPublisher = mock(ApplicationEventPublisher.class);
Authentication authentication = new JwtAuthenticationToken(TestJwts.jwt().build());
Exception cause = new Exception();
this.publisher = new DefaultAuthenticationEventPublisher(appPublisher);
this.publisher.publishAuthenticationFailure(new InvalidBearerTokenException("invalid"), authentication);
this.publisher.publishAuthenticationFailure(new InvalidBearerTokenException("invalid", cause), authentication);
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureBadCredentialsEvent.class));
}
use of org.springframework.security.authentication.DefaultAuthenticationEventPublisher in project dhis2-core by dhis2.
the class WebTestConfiguration method authenticationEventPublisher.
@Bean
public DefaultAuthenticationEventPublisher authenticationEventPublisher() {
DefaultAuthenticationEventPublisher defaultAuthenticationEventPublisher = new DefaultAuthenticationEventPublisher();
defaultAuthenticationEventPublisher.setAdditionalExceptionMappings(ImmutableMap.of(OAuth2AuthenticationException.class, AuthenticationFailureBadCredentialsEvent.class));
return defaultAuthenticationEventPublisher;
}
use of org.springframework.security.authentication.DefaultAuthenticationEventPublisher in project spring-security by spring-projects.
the class GlobalMethodSecurityConfiguration method authenticationManager.
/**
* Allows providing a custom {@link AuthenticationManager}. The default is to use any
* authentication mechanisms registered by
* {@link #configure(AuthenticationManagerBuilder)}. If
* {@link #configure(AuthenticationManagerBuilder)} was not overridden, then an
* {@link AuthenticationManager} is attempted to be autowired by type.
* @return the {@link AuthenticationManager} to use
*/
protected AuthenticationManager authenticationManager() throws Exception {
if (this.authenticationManager == null) {
DefaultAuthenticationEventPublisher eventPublisher = this.objectPostProcessor.postProcess(new DefaultAuthenticationEventPublisher());
this.auth = new AuthenticationManagerBuilder(this.objectPostProcessor);
this.auth.authenticationEventPublisher(eventPublisher);
configure(this.auth);
this.authenticationManager = (this.disableAuthenticationRegistry) ? getAuthenticationConfiguration().getAuthenticationManager() : this.auth.build();
}
return this.authenticationManager;
}
use of org.springframework.security.authentication.DefaultAuthenticationEventPublisher in project dhis2-core by dhis2.
the class AuthenticationProviderConfig method authenticationEventPublisher.
@Bean
public DefaultAuthenticationEventPublisher authenticationEventPublisher() {
DefaultAuthenticationEventPublisher defaultAuthenticationEventPublisher = new DefaultAuthenticationEventPublisher();
defaultAuthenticationEventPublisher.setAdditionalExceptionMappings(ImmutableMap.of(OAuth2AuthenticationException.class, AuthenticationFailureBadCredentialsEvent.class));
return defaultAuthenticationEventPublisher;
}
Aggregations