org.springframework.security.saml.context.SAMLMessageContext Java Examples

The following examples show how to use org.springframework.security.saml.context.SAMLMessageContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthenticationEventManager.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
public void sendAuthenticationEvent(Authentication authentication, AuthenticationType authenticationType) {
    String username;
    String emailAddress = null;
    try {
        if (authentication instanceof SAMLAuthenticationToken) {
            SAMLAuthenticationToken samlAuthenticationToken = (SAMLAuthenticationToken) authentication;
            SAMLMessageContext credentials = samlAuthenticationToken.getCredentials();
            NameIDImpl subjectNameIdentifier = (NameIDImpl) credentials.getSubjectNameIdentifier();
            username = subjectNameIdentifier.getValue();
            emailAddress = username;
        } else {
            username = authentication.getName();
        }
        sendAuthenticationEvent(username, emailAddress, authenticationType, authentication.getAuthorities());
    } catch (Exception e) {
        logger.warn("Unable to send authentication event");
        logger.debug("Authentication event failure", e);
    }
}
 
Example #2
Source File: SAMLConfigurerProfileConsumerTests.java    From spring-security-saml-dsl with MIT License 6 votes vote down vote up
@Test
public void webSSOProfileConsumerIsInjectedViaDSL() throws Exception {
	ArgumentCaptor<SAMLMessageContext> samlMessageContextCaptor = ArgumentCaptor.forClass(SAMLMessageContext.class);

	when(webSSOProfileConsumer.processAuthenticationResponse(samlMessageContextCaptor.capture()))
			.thenReturn(stubSAMLCredential());

	String samlResponse = StreamUtils.copyToString(
			new ClassPathResource("saml/SAMLResponse.xml").getInputStream(),
			StandardCharsets.UTF_8);

	mockMvc.perform(post("/saml/SSO").param("SAMLResponse", samlResponse));

	verify(webSSOProfileConsumer).processAuthenticationResponse(samlMessageContextCaptor.capture());

	SAMLMessageContext samlMessageContext = samlMessageContextCaptor.getValue();

	assertThat(samlMessageContext).isNotNull();
	assertThat(samlMessageContext.getInboundSAMLMessageId()).isEqualTo("id61844979402263501352984461");
	assertThat(samlMessageContext.getPeerEntityId()).isEqualTo("http://www.okta.com/exkb5v2p0pp35JFKa0h7");
}