Search in sources :

Example 86 with Response

use of org.opensaml.saml2.core.Response in project verify-hub by alphagov.

the class IdpIdaStatusUnmarshallerTest method shouldMapSamlStatusDetailOfLoaPendingToAuthenticationPending.

@Test
public void shouldMapSamlStatusDetailOfLoaPendingToAuthenticationPending() throws Exception {
    String pendingXml = readXmlFile("status-pending.xml");
    Response pendingResponse = stringToOpenSamlObjectTransformer.apply(pendingXml);
    IdpIdaStatus idpIdaStatus = getStatusFrom(pendingResponse);
    assertThat(idpIdaStatus.getStatusCode()).isEqualTo(IdpIdaStatus.Status.AuthenticationPending);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) IdpIdaStatus(uk.gov.ida.saml.hub.domain.IdpIdaStatus) Test(org.junit.jupiter.api.Test)

Example 87 with Response

use of org.opensaml.saml2.core.Response in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method generateAuthnResponseFromHub_shouldAddExternalCommunicationEvent.

@Test
public void generateAuthnResponseFromHub_shouldAddExternalCommunicationEvent() throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    String expectedSamlMessageId = UUID.randomUUID().toString();
    Response openSamlResponse = setUpAuthnResponseFromHub(sessionId, expectedSamlMessageId);
    SamlMessage authnResponse = samlMessageSenderHandler.generateAuthnResponseFromHub(sessionId, principalIpAddressAsSeenByHub);
    assertThat(authnResponse.getSamlMessage()).isEqualTo(samlRequest);
    assertThat(authnResponse.getPostEndpoint()).isEqualTo(postEndPoint.toString());
    assertThat(authnResponse.getRegistration()).isNotPresent();
    assertThat(authnResponse.getRelayState().isPresent()).isTrue();
    assertThat(authnResponse.getRelayState().get()).isEqualTo(relayState.get());
    assertThat(authnResponse.getSamlMessageType()).isEqualTo(SamlMessageType.SAML_RESPONSE);
    verify(externalCommunicationEventLogger).logResponseFromHub(expectedSamlMessageId, sessionId, postEndPoint, principalIpAddressAsSeenByHub);
    verify(protectiveMonitoringLogger).logAuthnResponse(openSamlResponse, Direction.OUTBOUND, SignatureStatus.VALID_SIGNATURE);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) SamlMessage(uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.jupiter.api.Test)

Example 88 with Response

use of org.opensaml.saml2.core.Response in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method generateErrorResponseFromHub_shouldThrowSamlTransformationException.

@Test
public void generateErrorResponseFromHub_shouldThrowSamlTransformationException() {
    Assertions.assertThrows(SamlTransformationErrorException.class, () -> {
        SessionId sessionId = SessionId.createNewSessionId();
        String expectedSamlMessageId = UUID.randomUUID().toString();
        Response openSamlResponse = setUpErrorResponseFromHub(sessionId, expectedSamlMessageId);
        when(samlMessageSignatureValidator.validate(openSamlResponse, SPSSODescriptor.DEFAULT_ELEMENT_NAME)).thenReturn(SamlValidationResponse.anInvalidResponse(new SamlValidationSpecification("bad", true)));
        samlMessageSenderHandler.generateErrorResponseFromHub(sessionId, principalIpAddressAsSeenByHub);
    });
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SessionId(uk.gov.ida.common.SessionId) SamlValidationSpecification(uk.gov.ida.saml.core.validation.errors.SamlValidationSpecification) Test(org.junit.jupiter.api.Test)

Example 89 with Response

use of org.opensaml.saml2.core.Response in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method generateAuthResponseFromHub_shouldThrowSamlTransformationException.

@Test
public void generateAuthResponseFromHub_shouldThrowSamlTransformationException() {
    Assertions.assertThrows(SamlTransformationErrorException.class, () -> {
        SessionId sessionId = SessionId.createNewSessionId();
        String expectedSamlMessageId = UUID.randomUUID().toString();
        Response openSamlResponse = setUpAuthnResponseFromHub(sessionId, expectedSamlMessageId);
        when(samlMessageSignatureValidator.validate(openSamlResponse, SPSSODescriptor.DEFAULT_ELEMENT_NAME)).thenReturn(SamlValidationResponse.anInvalidResponse(new SamlValidationSpecification("bad", true)));
        samlMessageSenderHandler.generateAuthnResponseFromHub(sessionId, principalIpAddressAsSeenByHub);
    });
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SessionId(uk.gov.ida.common.SessionId) SamlValidationSpecification(uk.gov.ida.saml.core.validation.errors.SamlValidationSpecification) Test(org.junit.jupiter.api.Test)

Example 90 with Response

use of org.opensaml.saml2.core.Response in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method setUpErrorResponseFromHub.

private Response setUpErrorResponseFromHub(SessionId sessionId, String expectedSamlMessageId) throws MarshallingException, SignatureException {
    AuthnResponseFromHubContainerDto hubContainerDto = new AuthnResponseFromHubContainerDto(samlRequest, postEndPoint, relayState, expectedSamlMessageId);
    when(sessionProxy.getErrorResponseFromHub(sessionId)).thenReturn(hubContainerDto);
    Response openSamlResponse = aResponse().withId(expectedSamlMessageId).build();
    when(responseTransformer.apply(anyString())).thenReturn(openSamlResponse);
    return openSamlResponse;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto)

Aggregations

Response (org.opensaml.saml.saml2.core.Response)245 Test (org.junit.jupiter.api.Test)148 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)84 Assertion (org.opensaml.saml.saml2.core.Assertion)62 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)51 Element (org.w3c.dom.Element)44 Status (org.opensaml.saml.saml2.core.Status)37 DateTime (org.joda.time.DateTime)36 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)31 Document (org.w3c.dom.Document)31 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)26 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)19 SubjectConfirmationDataBean (org.apache.wss4j.common.saml.bean.SubjectConfirmationDataBean)19 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)19 IdpIdaStatus (uk.gov.ida.saml.hub.domain.IdpIdaStatus)18 Authentication (org.springframework.security.core.Authentication)16 ResponseValidatorTestHelper.createStatus (uk.gov.ida.saml.hub.validators.response.helpers.ResponseValidatorTestHelper.createStatus)16 Crypto (org.apache.wss4j.common.crypto.Crypto)15 NameID (org.opensaml.saml.saml2.core.NameID)14 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)13