use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class PolicyApplicationExceptionMapperTest method toResponse_shouldReturnAnUnauditedErrorStatusIfExceptionIsNotAudited.
@Test
public void toResponse_shouldReturnAnUnauditedErrorStatusIfExceptionIsNotAudited() {
ApplicationException exception = createUnauditedExceptionThatShouldNotBeAudited();
final Response response = mapper.toResponse(exception);
final ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
assertThat(errorStatus.isAudited()).isEqualTo(false);
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class PolicyApplicationExceptionMapperTest method toResponse_shouldReturnAnAuditedErrorStatusIfExceptionIsAudited.
@Test
public void toResponse_shouldReturnAnAuditedErrorStatusIfExceptionIsAudited() {
ApplicationException exception = createAuditedException(ExceptionType.IDP_DISABLED, UUID.randomUUID());
final Response response = mapper.toResponse(exception);
final ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
assertThat(errorStatus.isAudited()).isEqualTo(true);
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class SamlEngineExceptionMapper method toResponse.
@Override
public Response toResponse(Exception exception) {
final UUID errorId = UUID.randomUUID();
Response.ResponseBuilder response = Response.status(Response.Status.BAD_REQUEST);
if (exception instanceof ApplicationException) {
ApplicationException applicationException = (ApplicationException) exception;
response.entity(logAndGetErrorStatusDto(applicationException.getExceptionType().getLevel(), applicationException.getExceptionType(), applicationException, applicationException.getErrorId(), applicationException.isAudited()));
} else if (exception instanceof SamlContextException) {
SamlContextException contextException = (SamlContextException) exception;
response.entity(logAndGetErrorStatusDto(contextException.getLogLevel(), contextException.getExceptionType(), exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else if (exception instanceof SamlFailedToDecryptException) {
response.entity(logAndGetErrorStatusDto(((SamlFailedToDecryptException) exception).getLogLevel(), ExceptionType.INVALID_SAML_FAILED_TO_DECRYPT, exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else if (exception instanceof SamlDuplicateRequestIdException) {
response.entity(logAndGetErrorStatusDto(((SamlDuplicateRequestIdException) exception).getLogLevel(), ExceptionType.INVALID_SAML_DUPLICATE_REQUEST_ID, exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else if (exception instanceof SamlRequestTooOldException) {
response.entity(logAndGetErrorStatusDto(((SamlTransformationErrorException) exception).getLogLevel(), ExceptionType.INVALID_SAML_REQUEST_TOO_OLD, exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else if (exception instanceof SamlTransformationErrorException) {
response.entity(logAndGetErrorStatusDto(((SamlTransformationErrorException) exception).getLogLevel(), ExceptionType.INVALID_SAML, exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else if (exception instanceof UnableToGenerateSamlException) {
response.entity(logAndGetErrorStatusDto(((UnableToGenerateSamlException) exception).getLogLevel(), ExceptionType.INVALID_INPUT, exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else if (exception instanceof NoKeyConfiguredForEntityException) {
response.entity(logAndGetErrorStatusDto(ERROR, ExceptionType.NO_KEY_CONFIGURED_FOR_ENTITY, exception, errorId, HAS_NOT_BEEN_AUDITED_YET));
} else {
levelLogger.log(WARN, exception, errorId);
}
return response.build();
}
use of uk.gov.ida.exceptions.ApplicationException 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;
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class MatchingServiceHealthCheckClient method sendHealthCheckRequest.
public MatchingServiceHealthCheckResponseDto sendHealthCheckRequest(final Element matchingServiceHealthCheckRequest, final URI matchingServiceUri) {
// Use a custom timer so that we get separate metrics for each matching service
final String scope = matchingServiceUri.toString().replace(':', '_').replace('/', '_');
final Timer timer = metricsRegistry.timer(MetricRegistry.name(MatchingServiceHealthCheckClient.class, "sendHealthCheckRequest", scope));
final Timer.Context context = timer.time();
HealthCheckResponse healthCheckResponse;
try {
healthCheckResponse = client.makeSoapRequestForHealthCheck(matchingServiceHealthCheckRequest, matchingServiceUri);
} catch (ApplicationException ex) {
final String errorMessage = MessageFormat.format("Failed to complete matching service health check to {0}.", matchingServiceUri);
LOG.warn(errorMessage, ex);
return new MatchingServiceHealthCheckResponseDto(Optional.empty());
} finally {
context.stop();
}
return new MatchingServiceHealthCheckResponseDto(Optional.of(XmlUtils.writeToString(healthCheckResponse.getResponseElement())));
}
Aggregations