Search in sources :

Example 11 with SamlMessageDto

use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.

the class SamlEngineStubRule method prepareForHealthCheckSamlGeneration.

public void prepareForHealthCheckSamlGeneration() throws JsonProcessingException {
    AttributeQuery attributeQuery = AttributeQueryBuilder.anAttributeQuery().withSignature(SignatureBuilder.aSignature().withSigningCredential(signingCredential).build()).withIssuer(IssuerBuilder.anIssuer().withIssuerId(HUB_ENTITY_ID).build()).build();
    SamlMessageDto samlMessageDto = new SamlMessageDto(XmlUtils.writeToString(attributeQuery.getDOM()));
    register(Urls.SamlEngineUrls.GENERATE_MSA_HEALTHCHECK_ATTRIBUTE_QUERY_RESOURCE, Response.Status.OK.getStatusCode(), samlMessageDto);
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery)

Example 12 with SamlMessageDto

use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.

the class SamlEngineStubExtension method prepareForHealthCheckSamlGeneration.

public void prepareForHealthCheckSamlGeneration() throws JsonProcessingException {
    AttributeQuery attributeQuery = anAttributeQuery().withSignature(aSignature().withSigningCredential(signingCredential).build()).withIssuer(anIssuer().withIssuerId(HUB_ENTITY_ID).build()).build();
    SamlMessageDto samlMessageDto = new SamlMessageDto(XmlUtils.writeToString(attributeQuery.getDOM()));
    register(GENERATE_MSA_HEALTHCHECK_ATTRIBUTE_QUERY_RESOURCE, OK.getStatusCode(), samlMessageDto);
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) AttributeQueryBuilder.anAttributeQuery(uk.gov.ida.saml.core.test.builders.AttributeQueryBuilder.anAttributeQuery)

Example 13 with SamlMessageDto

use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.

the class SamlEngineStubExtension method prepareForHealthCheckSamlGeneration.

public void prepareForHealthCheckSamlGeneration(final MatchingServiceHealthCheckerRequestDto msaHealthCheckerRequest) throws JsonProcessingException {
    final AttributeQuery attributeQuery = anAttributeQuery().withSignature(aSignature().withSigningCredential(signingCredential).build()).withIssuer(anIssuer().withIssuerId(HUB_ENTITY_ID).build()).build();
    final SamlMessageDto samlMessage = new SamlMessageDto(XmlUtils.writeToString(attributeQuery.getDOM()));
    final RequestAndResponse requestAndResponse = expectRequest().withPath(GENERATE_MSA_HEALTHCHECK_ATTRIBUTE_QUERY_RESOURCE).withMethod("POST").withBody(msaHealthCheckerRequest).andWillRespondWith().withStatus(OK.getStatusCode()).withContentType(MediaType.APPLICATION_JSON).withBody(samlMessage).build();
    register(requestAndResponse);
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) AttributeQueryBuilder.anAttributeQuery(uk.gov.ida.saml.core.test.builders.AttributeQueryBuilder.anAttributeQuery) RequestAndResponse(httpstub.RequestAndResponse)

Example 14 with SamlMessageDto

use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.

the class PrometheusMetricsIntegrationTest method setUp.

@BeforeEach
public void setUp() throws JsonProcessingException {
    client = samlSoapProxyApp.getClient();
    final MatchingServiceDetails msaOneDetails = new MatchingServiceDetails(msaStubOne.getAttributeQueryRequestUri(), MSA_ONE_ENTITY_ID, RP_ONE_ENTITY_ID);
    final MatchingServiceDetails msaTwoDetails = new MatchingServiceDetails(msaStubTwo.getAttributeQueryRequestUri(), MSA_TWO_ENTITY_ID, RP_TWO_ENTITY_ID);
    final MatchingServiceDetails msaThreeDetails = new MatchingServiceDetails(msaStubThree.getAttributeQueryRequestUri(), MSA_THREE_ENTITY_ID, RP_THREE_ENTITY_ID);
    final MatchingServiceDetails msaFourDetails = new MatchingServiceDetails(msaStubFour.getAttributeQueryRequestUri(), MSA_FOUR_ENTITY_ID, RP_FOUR_ENTITY_ID);
    Set<MatchingServiceDetails> msaDetailsSet = new HashSet<>(Set.of(msaOneDetails, msaTwoDetails, msaThreeDetails, msaFourDetails));
    final Element msaOneResponse = aHealthyHealthCheckResponse(MSA_ONE_ENTITY_ID, MSA_ONE_RESPONSE_ID, MSA_ONE_VERSION);
    final Element msaTwoResponse = aHealthyHealthCheckResponse(MSA_TWO_ENTITY_ID, MSA_TWO_RESPONSE_ID, MSA_TWO_VERSION);
    final Element msaFourResponse = aHealthyHealthCheckResponse(MSA_FOUR_ENTITY_ID, MSA_FOUR_RESPONSE_ID, MSA_FOUR_VERSION);
    final SamlMessageDto msaOneSamlMessage = new SamlMessageDto(Base64.getEncoder().encodeToString(XmlUtils.writeToString(msaOneResponse).getBytes()));
    final SamlMessageDto msaTwoSamlMessage = new SamlMessageDto(Base64.getEncoder().encodeToString(XmlUtils.writeToString(msaTwoResponse).getBytes()));
    final SamlMessageDto msaFourSamlMessage = new SamlMessageDto(Base64.getEncoder().encodeToString(XmlUtils.writeToString(msaFourResponse).getBytes()));
    final MatchingServiceHealthCheckerRequestDto msaOneHealthCheckerRequest = new MatchingServiceHealthCheckerRequestDto(RP_ONE_ENTITY_ID, MSA_ONE_ENTITY_ID);
    final MatchingServiceHealthCheckerRequestDto msaTwoHealthCheckerRequest = new MatchingServiceHealthCheckerRequestDto(RP_TWO_ENTITY_ID, MSA_TWO_ENTITY_ID);
    final MatchingServiceHealthCheckerRequestDto msaThreeHealthCheckerRequest = new MatchingServiceHealthCheckerRequestDto(RP_THREE_ENTITY_ID, MSA_THREE_ENTITY_ID);
    final MatchingServiceHealthCheckerRequestDto msaFourHealthCheckerRequest = new MatchingServiceHealthCheckerRequestDto(RP_FOUR_ENTITY_ID, MSA_FOUR_ENTITY_ID);
    eventSinkStub.setupStubForLogging();
    configStub.setUpStubForMatchingServiceHealthCheckRequests(msaDetailsSet);
    configStub.setupStubForCertificates(MSA_ONE_ENTITY_ID, TEST_RP_MS_PUBLIC_SIGNING_CERT, TEST_RP_MS_PUBLIC_ENCRYPTION_CERT);
    configStub.setupStubForCertificates(MSA_TWO_ENTITY_ID, TEST_RP_MS_PUBLIC_SIGNING_CERT, TEST_RP_MS_PUBLIC_ENCRYPTION_CERT);
    configStub.setupStubForCertificates(MSA_FOUR_ENTITY_ID, TEST_RP_MS_PUBLIC_SIGNING_CERT, TEST_RP_MS_PUBLIC_ENCRYPTION_CERT);
    msaStubOne.prepareForHealthCheckRequest(XmlUtils.writeToString(SOAP_MESSAGE_MANAGER.wrapWithSoapEnvelope(msaOneResponse)));
    msaStubTwo.prepareForHealthCheckRequest(XmlUtils.writeToString(SOAP_MESSAGE_MANAGER.wrapWithSoapEnvelope(msaTwoResponse)));
    msaStubFour.prepareForHealthCheckRequest(XmlUtils.writeToString(SOAP_MESSAGE_MANAGER.wrapWithSoapEnvelope(msaFourResponse)));
    samlEngineStub.prepareForHealthCheckSamlGeneration(msaOneHealthCheckerRequest);
    samlEngineStub.prepareForHealthCheckSamlGeneration(msaTwoHealthCheckerRequest);
    samlEngineStub.prepareForHealthCheckSamlGeneration(msaThreeHealthCheckerRequest);
    samlEngineStub.prepareForHealthCheckSamlGeneration(msaFourHealthCheckerRequest);
    samlEngineStub.setupStubForAttributeResponseTranslate(msaOneSamlMessage, anInboundResponseFromMatchingServiceDto().withIssuer(MSA_ONE_ENTITY_ID).withStatus(Healthy).build());
    samlEngineStub.setupStubForAttributeResponseTranslate(msaTwoSamlMessage, anInboundResponseFromMatchingServiceDto().withIssuer(MSA_TWO_ENTITY_ID).withStatus(Healthy).build());
    samlEngineStub.setupStubForAttributeResponseTranslate(msaFourSamlMessage, anInboundResponseFromMatchingServiceDto().withIssuer(MSA_FOUR_ENTITY_ID).withStatus(Healthy).build());
}
Also used : MatchingServiceDetails(uk.gov.ida.integrationtest.hub.samlsoapproxy.apprule.support.MatchingServiceDetails) MatchingServiceHealthCheckerRequestDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto) SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) Element(org.w3c.dom.Element) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with SamlMessageDto

use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.

the class MatchingServiceHealthChecker method isHealthyResponse.

private boolean isHealthyResponse(final URI matchingServiceUri, Optional<String> response) {
    if (response.isEmpty()) {
        return false;
    }
    String exceptionMessage = format("Matching service health check failed for URI {0}", matchingServiceUri);
    try {
        // Saml-engine expects the saml to be base64 encoded
        String base64Response = Base64.getEncoder().encodeToString(response.get().getBytes(Charset.defaultCharset()));
        final SamlMessageDto samlMessageDto = new SamlMessageDto(base64Response);
        final MatchingServiceHealthCheckerResponseDto responseFromMatchingService = samlEngineProxy.translateHealthcheckMatchingServiceResponse(samlMessageDto);
        if (responseFromMatchingService.getStatus() != MatchingServiceIdaStatus.Healthy) {
            return false;
        }
    } catch (ApplicationException e) {
        eventLogger.logException(e, exceptionMessage);
        return false;
    } catch (RuntimeException e) {
        LOG.warn(format("Matching service health check failed for URI {0}", matchingServiceUri), e);
        return false;
    }
    return true;
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) ApplicationException(uk.gov.ida.exceptions.ApplicationException) MatchingServiceHealthCheckerResponseDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)

Aggregations

SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)18 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)11 MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto (uk.gov.ida.hub.samlsoapproxy.builders.MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto)9 MatchingServiceConfigEntityDataDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceConfigEntityDataDto)9 Test (org.junit.jupiter.api.Test)5 Test (org.junit.Test)4 ApplicationException (uk.gov.ida.exceptions.ApplicationException)4 MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)4 AttributeQuery (org.opensaml.saml.saml2.core.AttributeQuery)3 Element (org.w3c.dom.Element)2 MatchingServiceHealthCheckerRequestDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto)2 AttributeQueryBuilder.anAttributeQuery (uk.gov.ida.saml.core.test.builders.AttributeQueryBuilder.anAttributeQuery)2 RequestAndResponse (httpstub.RequestAndResponse)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SAXException (org.xml.sax.SAXException)1 MatchingServiceDetails (uk.gov.ida.integrationtest.hub.samlsoapproxy.apprule.support.MatchingServiceDetails)1