RedirectAuthenticationHandler extends
                                           SavedRequestAwareAuthenticationSuccessHandler implements InitializingBean { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String targetUrlParameter = getTargetUrlParameter(); if (targetUrlParameter != null && targetUrlParameterRedirectStrategy != null) { String redirectUrl = request.getParameter(targetUrlParameter); if (StringUtils.hasText(redirectUrl)) { clearAuthenticationAttributes(request); targetUrlParameterRedirectStrategy.sendRedirect(request, response, redirectUrl); return; } } super.onAuthenticationSuccess(request, response, authentication); } RedirectAuthenticationHandler(); void setRedirectToRedirectStrategy(
            RedirectStrategy redirectToRedirectStrategy); @Override void onAuthenticationSuccess(HttpServletRequest request,
            HttpServletResponse response,
            Authentication authentication); @Override void afterPropertiesSet();  }
@Test public void testOnAuthenticationSuccess_SetNullRedirectToRedirectStrategy() throws Exception { RedirectAuthenticationHandler redireHandler = new RedirectAuthenticationHandler(); String redirectURI = "http: request.setParameter("redirectTo", redirectURI); String expectedRedirectURL = "http: redireHandler.onAuthenticationSuccess(request, response, auth); assertThat(response.getRedirectedUrl(), is(expectedRedirectURL)); }
@Test public void testOnAuthenticationSuccess_SetNullRedirectToRedirectStrategyAndSetContextRelative() throws Exception { RedirectAuthenticationHandler redireHandler = new RedirectAuthenticationHandler(); DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); redirectStrategy.setContextRelative(true); redireHandler.setRedirectStrategy(redirectStrategy); String redirectURI = "http: request.setParameter("redirectTo", redirectURI); String expectedRedirectURL = "bar"; redireHandler.onAuthenticationSuccess(request, response, auth); assertThat(response.getRedirectedUrl(), is(expectedRedirectURL)); }
@Test public void testOnAuthenticationSuccess_SetIllegalUrlWhenUseDefaultRedirectToRedirectStrategy() throws Exception { RedirectAuthenticationHandler redireHandler = new RedirectAuthenticationHandler(); String redirectURI = "http: request.setParameter("redirectTo", redirectURI); String expectedRedirectURL = "http: redireHandler.onAuthenticationSuccess(request, response, auth); assertThat(response.getRedirectedUrl(), is(expectedRedirectURL)); }