Search in sources :

Example 1 with ForwardAuthenticationSuccessHandler

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

the class AbstractPreAuthenticatedProcessingFilterTests method callsAuthenticationSuccessHandlerOnSuccessfulAuthentication.

@Test
public void callsAuthenticationSuccessHandlerOnSuccessfulAuthentication() throws Exception {
    Object currentPrincipal = "currentUser";
    TestingAuthenticationToken authRequest = new TestingAuthenticationToken(currentPrincipal, "something", "ROLE_USER");
    SecurityContextHolder.getContext().setAuthentication(authRequest);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
    filter.setAuthenticationSuccessHandler(new ForwardAuthenticationSuccessHandler("/forwardUrl"));
    filter.setCheckForPrincipalChanges(true);
    filter.principal = "newUser";
    AuthenticationManager am = mock(AuthenticationManager.class);
    filter.setAuthenticationManager(am);
    filter.afterPropertiesSet();
    filter.doFilter(request, response, chain);
    verify(am).authenticate(any(PreAuthenticatedAuthenticationToken.class));
    assertThat(response.getForwardedUrl()).isEqualTo("/forwardUrl");
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) ForwardAuthenticationSuccessHandler(org.springframework.security.web.authentication.ForwardAuthenticationSuccessHandler) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockFilterChain (org.springframework.mock.web.MockFilterChain)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 ForwardAuthenticationSuccessHandler (org.springframework.security.web.authentication.ForwardAuthenticationSuccessHandler)1