IdpSamlAuthenticationSuccessHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException { SAMLMessageContext context = ((UaaAuthentication) authentication).getSamlMessageContext(); IdpExtendedMetadata extendedMetadata = null; try { extendedMetadata = (IdpExtendedMetadata) metadataManager.getExtendedMetadata(context.getLocalEntityId()); } catch (MetadataProviderException e) { throw new ServletException("Failed to obtain local SAML IdP extended metadata.", e); } try { populatePeerContext(context); } catch (MetadataProviderException e) { throw new ServletException("Failed to populate peer SAML SP context.", e); } try { IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions(); options.setAssertionsSigned(extendedMetadata.isAssertionsSigned()); options.setAssertionTimeToLiveSeconds(extendedMetadata.getAssertionTimeToLiveSeconds()); idpWebSsoProfile.sendResponse(authentication, context, options); } catch (SAMLException e) { LOGGER.debug("Incoming SAML message is invalid.", e); throw new AuthenticationServiceException("Incoming SAML message is invalid.", e); } catch (MetadataProviderException e) { LOGGER.debug("Error determining metadata contracts.", e); throw new AuthenticationServiceException("Error determining metadata contracts.", e); } catch (MessageEncodingException e) { LOGGER.debug("Error decoding incoming SAML message.", e); throw new AuthenticationServiceException("Error encoding outgoing SAML message.", e); } catch (MarshallingException | SecurityException | SignatureException e) { LOGGER.debug("Error signing SAML assertion.", e); throw new AuthenticationServiceException("Error signing SAML assertion.", e); } } IdpSamlAuthenticationSuccessHandler(); @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
            Authentication authentication); @Autowired void setIdpWebSsoProfile(IdpWebSsoProfile idpWebSsoProfile); @Autowired void setMetadataManager(MetadataManager metadataManager);  }
@Test public void testOnAuthenticationSuccess() throws ServletException, MetadataProviderException, MessageEncodingException, SAMLException, SecurityException, MarshallingException, SignatureException { IdpSamlAuthenticationSuccessHandler successHandler = new IdpSamlAuthenticationSuccessHandler(); SAMLMessageContext context = samlTestUtils.mockSamlMessageContext(); Authentication authentication = samlTestUtils.mockUaaAuthenticationWithSamlMessageContext(context); IdpExtendedMetadata idpExtendedMetaData = new IdpExtendedMetadata(); idpExtendedMetaData.setAssertionsSigned(true); MetadataManager metadataManager = mock(MetadataManager.class); when(metadataManager.getExtendedMetadata(context.getLocalEntityId())).thenReturn(idpExtendedMetaData); when(metadataManager.getEntityDescriptor(context.getPeerEntityId())) .thenReturn(context.getPeerEntityMetadata()); when(metadataManager.getRole(context.getPeerEntityId(), context.getPeerEntityRole(), SAMLConstants.SAML20P_NS)) .thenReturn(context.getPeerEntityRoleMetadata()); successHandler.setMetadataManager(metadataManager); IdpWebSsoProfile profile = mock(IdpWebSsoProfile.class); doNothing().when(profile).sendResponse(any(), any(), any()); successHandler.setIdpWebSsoProfile(profile); HttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); successHandler.onAuthenticationSuccess(request, response, authentication); }