Search in sources :

Example 81 with Response

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

the class HealthCheckResponseFromMatchingServiceValidatorTest method validate_shouldThrowInvalidSamlExceptionIfIssuerElementIsMissing.

@Test
public void validate_shouldThrowInvalidSamlExceptionIfIssuerElementIsMissing() throws Exception {
    Response response = aResponse().withIssuer(null).build();
    assertValidationFailureSamlExceptionMessage(SamlTransformationErrorFactory.missingIssuer(), response);
}
Also used : ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) Response(org.opensaml.saml.saml2.core.Response) Test(org.junit.jupiter.api.Test)

Example 82 with Response

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

the class MatchingServiceResponseTranslatorService method translate.

public InboundResponseFromMatchingServiceDto translate(SamlResponseContainerDto samlResponseContainerDto) {
    final Response response = responseUnmarshaller.apply(samlResponseContainerDto.getSamlResponse());
    MdcHelper.addContextToMdc(response);
    final InboundResponseFromMatchingService responseFromMatchingService = responseToInboundResponseFromMatchingServiceTransformer.transform(response);
    Optional<String> assertionBlob = Optional.empty();
    Optional<LevelOfAssurance> levelOfAssurance = Optional.empty();
    // FIXME?: transformer can return null
    if (responseFromMatchingService.getMatchingServiceAssertion() != null && responseFromMatchingService.getMatchingServiceAssertion().isPresent()) {
        assertionBlob = Optional.ofNullable(responseFromMatchingService.getMatchingServiceAssertion().get().getUnderlyingAssertionBlob());
        final Optional<AuthnContext> authnContext = responseFromMatchingService.getMatchingServiceAssertion().get().getAuthnContext();
        if (authnContext.isPresent()) {
            levelOfAssurance = Optional.of(LevelOfAssurance.valueOf(authnContext.get().name()));
        }
    }
    final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = new InboundResponseFromMatchingServiceDto(responseFromMatchingService.getStatus(), responseFromMatchingService.getInResponseTo(), responseFromMatchingService.getIssuer(), assertionBlob.map(ab -> assertionBlobEncrypter.encryptAssertionBlob(samlResponseContainerDto.getAuthnRequestIssuerId(), ab)), levelOfAssurance);
    return inboundResponseFromMatchingServiceDto;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) LevelOfAssurance(uk.gov.ida.hub.samlengine.domain.LevelOfAssurance) SamlResponseContainerDto(uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto) LevelOfAssurance(uk.gov.ida.hub.samlengine.domain.LevelOfAssurance) Inject(com.google.inject.Inject) StringToOpenSamlObjectTransformer(uk.gov.ida.saml.deserializers.StringToOpenSamlObjectTransformer) AssertionBlobEncrypter(uk.gov.ida.saml.core.transformers.outbound.decorators.AssertionBlobEncrypter) DecoratedSamlResponseToInboundResponseFromMatchingServiceTransformer(uk.gov.ida.saml.hub.transformers.inbound.providers.DecoratedSamlResponseToInboundResponseFromMatchingServiceTransformer) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) Optional(java.util.Optional) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext) MdcHelper(uk.gov.ida.hub.samlengine.logging.MdcHelper) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService) Response(org.opensaml.saml.saml2.core.Response) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext)

Example 83 with Response

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

the class SamlMessageSenderHandler method generateErrorResponseFromHub.

public SamlMessage generateErrorResponseFromHub(final SessionId sessionId, String principalIpAddressAsSeenByHub) {
    AuthnResponseFromHubContainerDto authnResponseFromHub = sessionProxy.getErrorResponseFromHub(sessionId);
    Response samlResponse = responseTransformer.apply(authnResponseFromHub.getSamlResponse());
    validateAndLogSamlResponseSignature(samlResponse);
    SamlMessage samlMessage = new SamlMessage(authnResponseFromHub.getSamlResponse(), SamlMessageType.SAML_RESPONSE, authnResponseFromHub.getRelayState(), authnResponseFromHub.getPostEndpoint().toString(), Optional.empty());
    externalCommunicationEventLogger.logResponseFromHub(authnResponseFromHub.getResponseId(), sessionId, authnResponseFromHub.getPostEndpoint(), principalIpAddressAsSeenByHub);
    return samlMessage;
}
Also used : SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) Response(org.opensaml.saml.saml2.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto)

Example 84 with Response

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

the class IdpIdaStatusUnmarshallerTest method shouldRemainNoAuthnContextIfStatusDetailPresentButUnknown.

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

Example 85 with Response

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

the class IdpIdaStatusUnmarshallerTest method shouldThrowWhenNoMatch.

@Test
public void shouldThrowWhenNoMatch() throws Exception {
    Assertions.assertThrows(IllegalStateException.class, () -> {
        String xml = readXmlFile("status-unknown.xml");
        Response response = stringToOpenSamlObjectTransformer.apply(xml);
        getStatusFrom(response);
    });
}
Also used : Response(org.opensaml.saml.saml2.core.Response) Test(org.junit.jupiter.api.Test)

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