Search in sources :

Example 1 with ApplicationException

use of uk.gov.ida.exceptions.ApplicationException 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 responseDto;
    try {
        SamlMessageDto samlMessageDto = samlEngineProxy.generateHealthcheckAttributeQuery(matchingServiceHealthCheckerRequestDto);
        final Element matchingServiceHealthCheckRequest = XmlUtils.convertToElement(samlMessageDto.getSamlMessage());
        validateRequestSignature(matchingServiceHealthCheckRequest);
        responseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(matchingServiceHealthCheckRequest, configEntity.getUri());
        return buildMatchingServiceHealthCheckResult(configEntity, responseDto.getResponse());
    } 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);
    }
}
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)

Example 2 with ApplicationException

use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.

the class MatchingServiceResponseService method handleSuccessResponse.

public void handleSuccessResponse(SessionId sessionId, SamlResponseDto samlResponse) {
    getSessionIfItExists(sessionId);
    SamlResponseContainerDto samlResponseContainer = new SamlResponseContainerDto(samlResponse.getSamlResponse(), sessionRepository.getRequestIssuerEntityId(sessionId));
    try {
        InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = samlEngineProxy.translateMatchingServiceResponse(samlResponseContainer);
        updateSessionState(sessionId, inboundResponseFromMatchingServiceDto);
    } catch (ApplicationException e) {
        // this is not ideal but if the call to saml-proxy fails we want to log the failure
        // in the state and then process the exception
        logExceptionAndUpdateState("Error translating matching service response", sessionId, e);
    }
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) SamlResponseContainerDto(uk.gov.ida.hub.policy.contracts.SamlResponseContainerDto) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.policy.contracts.InboundResponseFromMatchingServiceDto)

Example 3 with ApplicationException

use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.

the class PolicyApplicationExceptionMapperTest method toResponse_shouldNotAuditIfEventIsAlreadyAudited.

@Test
public void toResponse_shouldNotAuditIfEventIsAlreadyAudited() {
    ApplicationException exception = createAuditedException(ExceptionType.IDP_DISABLED, UUID.randomUUID());
    mapper.toResponse(exception);
    verifyNoInteractions(eventLogger);
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationException

use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.

the class SamlEngineExceptionMapperTest method toResponse_shouldReturnAuditedErrorResponseWhenExceptionHasBeenAuditedAlready.

@Test
public void toResponse_shouldReturnAuditedErrorResponseWhenExceptionHasBeenAuditedAlready() throws Exception {
    ApplicationException applicationException = createAuditedException(ExceptionType.INVALID_SAML, UUID.randomUUID());
    final Response response = samlEngineExceptionMapper.toResponse(applicationException);
    final ErrorStatusDto entity = (ErrorStatusDto) response.getEntity();
    assertThat(entity.isAudited()).isTrue();
    checkLogLevel(applicationException.getExceptionType().getLevel());
}
Also used : Response(javax.ws.rs.core.Response) ApplicationException(uk.gov.ida.exceptions.ApplicationException) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 5 with ApplicationException

use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.

the class SamlEngineExceptionMapperTest method toResponse_shouldReturnUnauditedErrorResponseWhenExceptionHasNotBeenAudited.

@Test
public void toResponse_shouldReturnUnauditedErrorResponseWhenExceptionHasNotBeenAudited() throws Exception {
    ApplicationException applicationException = createUnauditedExceptionThatShouldNotBeAudited();
    final Response response = samlEngineExceptionMapper.toResponse(applicationException);
    final ErrorStatusDto entity = (ErrorStatusDto) response.getEntity();
    assertThat(entity.isAudited()).isEqualTo(false);
    checkLogLevel(applicationException.getExceptionType().getLevel());
}
Also used : Response(javax.ws.rs.core.Response) ApplicationException(uk.gov.ida.exceptions.ApplicationException) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationException (uk.gov.ida.exceptions.ApplicationException)27 Test (org.junit.jupiter.api.Test)20 UUID (java.util.UUID)8 Response (javax.ws.rs.core.Response)7 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)6 URI (java.net.URI)4 SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)4 EventDetails (uk.gov.ida.hub.shared.eventsink.EventDetails)4 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)3 SessionId (uk.gov.ida.common.SessionId)2 ApplicationException.createAuditedException (uk.gov.ida.exceptions.ApplicationException.createAuditedException)2 ApplicationException.createUnauditedException (uk.gov.ida.exceptions.ApplicationException.createUnauditedException)2 MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)2 Timer (com.codahale.metrics.Timer)1 Timed (com.codahale.metrics.annotation.Timed)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DateTime (org.joda.time.DateTime)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1