Search in sources :

Example 1 with AuthenticationEventPublisher

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

the class OAuth2AuthenticationProcessingFilterTests method testNoEventsPublishedWithNoToken.

@Test
public void testNoEventsPublishedWithNoToken() throws Exception {
    AuthenticationEventPublisher eventPublisher = Mockito.mock(AuthenticationEventPublisher.class);
    filter.setAuthenticationEventPublisher(eventPublisher);
    filter.doFilter(request, null, chain);
    Mockito.verify(eventPublisher, Mockito.never()).publishAuthenticationFailure(Mockito.any(AuthenticationException.class), Mockito.any(Authentication.class));
    Mockito.verify(eventPublisher, Mockito.never()).publishAuthenticationSuccess(Mockito.any(Authentication.class));
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) AuthenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher) Test(org.junit.Test)

Example 2 with AuthenticationEventPublisher

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

the class OAuth2AuthenticationProcessingFilterTests method testSuccessEventsPublishedWithToken.

@Test
public void testSuccessEventsPublishedWithToken() throws Exception {
    request.addHeader("Authorization", "Bearer FOO");
    AuthenticationEventPublisher eventPublisher = Mockito.mock(AuthenticationEventPublisher.class);
    filter.setAuthenticationEventPublisher(eventPublisher);
    filter.doFilter(request, null, chain);
    Mockito.verify(eventPublisher, Mockito.never()).publishAuthenticationFailure(Mockito.any(AuthenticationException.class), Mockito.any(Authentication.class));
    Mockito.verify(eventPublisher).publishAuthenticationSuccess(Mockito.any(Authentication.class));
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) AuthenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher) Test(org.junit.Test)

Example 3 with AuthenticationEventPublisher

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

the class OAuth2AuthenticationProcessingFilterTests method testFailureEventsPublishedWithBadToken.

@Test
public void testFailureEventsPublishedWithBadToken() throws Exception {
    request.addHeader("Authorization", "Bearer BAD");
    AuthenticationEventPublisher eventPublisher = Mockito.mock(AuthenticationEventPublisher.class);
    filter.setAuthenticationEventPublisher(eventPublisher);
    filter.doFilter(request, response, chain);
    Mockito.verify(eventPublisher).publishAuthenticationFailure(Mockito.any(AuthenticationException.class), Mockito.any(Authentication.class));
    Mockito.verify(eventPublisher, Mockito.never()).publishAuthenticationSuccess(Mockito.any(Authentication.class));
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) AuthenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 AuthenticationEventPublisher (org.springframework.security.authentication.AuthenticationEventPublisher)3 Authentication (org.springframework.security.core.Authentication)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)3