Search in sources :

Example 1 with MatchingServiceHealthCheckerRequestDto

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

the class MatchingServiceHealthChecker method performHealthCheck.

public MatchingServiceHealthCheckResult performHealthCheck(final MatchingServiceConfigEntityDataDto configEntity) {
    MatchingServiceHealthCheckerRequestDto matchingServiceHealthCheckerRequestDto = new MatchingServiceHealthCheckerRequestDto(configEntity.getTransactionEntityId(), configEntity.getEntityId());
    MatchingServiceHealthCheckResponseDto response;
    try {
        SamlMessageDto samlMessageDto = samlEngineProxy.generateHealthcheckAttributeQuery(matchingServiceHealthCheckerRequestDto);
        final Element matchingServiceHealthCheckRequest = XmlUtils.convertToElement(samlMessageDto.getSamlMessage());
        validateRequestSignature(matchingServiceHealthCheckRequest);
        response = matchingServiceHealthCheckClient.sendHealthCheckRequest(matchingServiceHealthCheckRequest, configEntity.getUri());
        if (response.getResponse().isPresent()) {
            final Optional<String> msaVersion = extractVersionFromResponseId(response.getResponse().get());
            if (msaVersion.isPresent()) {
                // if we have conflicting return values, lets trust the one from the ID a little bit more
                response = new MatchingServiceHealthCheckResponseDto(response.getResponse(), msaVersion);
                if (!response.getVersionNumber().get().equals(msaVersion.get())) {
                    response = new MatchingServiceHealthCheckResponseDto(response.getResponse(), msaVersion);
                    LOG.warn("MSA healthcheck response with two version numbers: {0} & {1}", response.getVersionNumber().get(), msaVersion.get());
                }
            }
        }
    } catch (ApplicationException e) {
        final String message = format("Saml-engine was unable to generate saml to send to MSA: {0}", e);
        eventLogger.logException(e, message);
        return logAndCreateUnhealthyResponse(configEntity, message);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        final String message = format("Unable to convert saml request to XML element: {0}", e);
        return logAndCreateUnhealthyResponse(configEntity, message);
    }
    if (isHealthyResponse(response, configEntity.getUri())) {
        return healthy(generateHealthCheckDescription("responded successfully", configEntity.getUri(), response.getVersionNumber(), configEntity.isOnboarding()));
    } else {
        return unhealthy(generateHealthCheckFailureDescription(response, configEntity.getUri(), configEntity.isOnboarding()));
    }
}
Also used : MatchingServiceHealthCheckerRequestDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto) SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) ApplicationException(uk.gov.ida.exceptions.ApplicationException) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1 MatchingServiceHealthCheckerRequestDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto)1 SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)1 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)1