Search in sources :

Example 1 with MatchingServiceHealthCheckerResponseDto

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

the class MatchingServiceHealthCheckerTest method prepareForResponse.

private void prepareForResponse(MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto, MatchingServiceIdaStatus status, Optional<String> msaVersion) {
    when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("<saml/>"));
    final MatchingServiceHealthCheckerResponseDto inboundResponseFromMatchingServiceDto = anInboundResponseFromMatchingServiceDto().withStatus(status).build();
    when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of("<saml/>"), msaVersion));
    when(samlEngineProxy.translateHealthcheckMatchingServiceResponse(any())).thenReturn(inboundResponseFromMatchingServiceDto);
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) MatchingServiceHealthCheckerResponseDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)

Example 2 with MatchingServiceHealthCheckerResponseDto

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

the class MatchingServiceHealthChecker method isHealthyResponse.

private boolean isHealthyResponse(final MatchingServiceHealthCheckResponseDto responseDto, final URI matchingServiceUri) {
    if (!responseDto.getResponse().isPresent()) {
        return false;
    }
    String exceptionMessage = format("Matching service health check failed for URI {0}", matchingServiceUri);
    try {
        // Saml-engine expects the saml to be base64 encoded
        final SamlMessageDto samlMessageDto = new SamlMessageDto(Base64.encodeAsString(responseDto.getResponse().get()));
        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

MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)2 SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)2 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)1