SAMLRelayStateSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { Object credentials = authentication.getCredentials(); if (credentials instanceof SAMLCredential) { SAMLCredential samlCredential = (SAMLCredential) credentials; String relayStateURL = getTargetURL(samlCredential.getRelayState()); if (relayStateURL != null) { log.debug("Redirecting to RelayState Url: " + relayStateURL); getRedirectStrategy().sendRedirect(request, response, relayStateURL); return; } } super.onAuthenticationSuccess(request, response, authentication); }  @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication);  }
@Test public void testSuccessWithSAMLCredential() throws Exception { expect(authentication.getCredentials()).andReturn(credential); redirectStrategy.sendRedirect(request, response, credential.getRelayState()); expectLastCall(); replayMock(); successHandler.onAuthenticationSuccess(request, response, authentication); verifyMock(); }