Search in sources :

Example 66 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class SessionCreationFailureExceptionMapper method handleException.

@Override
public Response handleException(SessionCreationFailureException exception) {
    UUID errorId = UUID.randomUUID();
    levelLogger.log(exception.getLogLevel(), exception);
    eventLogger.logErrorEvent(errorId, getSessionId().orElse(SessionId.SESSION_ID_DOES_NOT_EXIST_YET), exception.getMessage());
    final ErrorStatusDto entity = ErrorStatusDto.createAuditedErrorStatus(errorId, exception.getExceptionType(), exception.getMessage());
    return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(entity).build();
}
Also used : ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) UUID(java.util.UUID)

Example 67 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class SessionNotFoundExceptionMapper method handleException.

@Override
public Response handleException(SessionNotFoundException exception) {
    UUID errorId = UUID.randomUUID();
    LOG.info(MessageFormat.format("{0} - Exception while processing request.", errorId), exception);
    eventLogger.logErrorEvent(errorId, getSessionId().orElse(SessionId.SESSION_ID_DOES_NOT_EXIST_YET), exception.getMessage());
    ErrorStatusDto entity = createUnauditedErrorStatus(errorId, SESSION_NOT_FOUND);
    return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(entity).build();
}
Also used : ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) UUID(java.util.UUID)

Example 68 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class IdaJsonProcessingExceptionMapperTest method toResponse_shouldReturnBadRequestAndErrorStatusDtoWhenErrorDeemedToBeFromClient.

@Test
public void toResponse_shouldReturnBadRequestAndErrorStatusDtoWhenErrorDeemedToBeFromClient() {
    String clientErrorMessage = "This is a client error";
    Response response = mapper.toResponse(new JsonMappingException(null, clientErrorMessage));
    ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(errorStatus.isAudited()).isEqualTo(false);
    assertThat(errorStatus.getClientMessage()).isEqualTo(clientErrorMessage);
    assertThat(errorStatus.getExceptionType()).isEqualTo(ExceptionType.JSON_PARSING);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Test(org.junit.jupiter.api.Test)

Example 69 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldReturnBadRequestWhenLevelOfAssuranceIsNotMet.

@Test
public void responsePost_shouldReturnBadRequestWhenLevelOfAssuranceIsNotMet() throws JsonProcessingException {
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.successResponse(idpEntityId, LevelOfAssurance.LEVEL_3));
    Response response = postIdpResponse(sessionId, samlResponseDto);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto responseEntity = response.readEntity(ErrorStatusDto.class);
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.STATE_PROCESSING_VALIDATION);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 70 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldReturnBadRequestWhenIdpIsDifferentThanSelectedIdp.

@Test
public void responsePost_shouldReturnBadRequestWhenIdpIsDifferentThanSelectedIdp() throws JsonProcessingException {
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.successResponse("differentIdp", LevelOfAssurance.LEVEL_2));
    Response response = postIdpResponse(sessionId, samlResponseDto);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto responseEntity = response.readEntity(ErrorStatusDto.class);
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.STATE_PROCESSING_VALIDATION);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Aggregations

ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)78 Response (javax.ws.rs.core.Response)69 Test (org.junit.jupiter.api.Test)66 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto)17 SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto (uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto)17 UUID (java.util.UUID)13 SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)7 ApplicationException (uk.gov.ida.exceptions.ApplicationException)6 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)6 SamlResponseContainerDto (uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3 Status (org.opensaml.saml.saml2.core.Status)3 SamlRequestWithAuthnRequestInformationDto (uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto)3 StatusBuilder.aStatus (uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus)3 SamlDuplicateRequestIdException (uk.gov.ida.saml.hub.exception.SamlDuplicateRequestIdException)3 MatchingServiceIdaStatus (uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 ExceptionType (uk.gov.ida.common.ExceptionType)2 IdpSelected (uk.gov.ida.hub.policy.domain.IdpSelected)2 SamlRequestTooOldException (uk.gov.ida.saml.hub.exception.SamlRequestTooOldException)2