Search in sources :

Example 1 with SamlMessageDto

use of uk.gov.ida.hub.samlengine.domain.SamlMessageDto in project verify-hub by alphagov.

the class RpErrorResponseGeneratorService method generate.

public SamlMessageDto generate(RequestForErrorResponseFromHubDto requestForErrorResponseFromHubDto) {
    try {
        final OutboundResponseFromHub response = new OutboundResponseFromHub(requestForErrorResponseFromHubDto.getResponseId(), requestForErrorResponseFromHubDto.getInResponseTo(), hubEntityId, DateTime.now(), TransactionIdaStatus.valueOf(requestForErrorResponseFromHubDto.getStatus().name()), empty(), requestForErrorResponseFromHubDto.getAssertionConsumerServiceUri());
        final String errorResponse = outboundResponseFromHubToResponseTransformerFactory.get(requestForErrorResponseFromHubDto.getAuthnRequestIssuerEntityId()).apply(response);
        return new SamlMessageDto(errorResponse);
    } catch (Exception e) {
        throw new UnableToGenerateSamlException("Unable to generate RP error response", e, Level.ERROR);
    }
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlengine.domain.SamlMessageDto) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub) UnableToGenerateSamlException(uk.gov.ida.hub.samlengine.exceptions.UnableToGenerateSamlException) UnableToGenerateSamlException(uk.gov.ida.hub.samlengine.exceptions.UnableToGenerateSamlException)

Example 2 with SamlMessageDto

use of uk.gov.ida.hub.samlengine.domain.SamlMessageDto in project verify-hub by alphagov.

the class MatchingServiceHealthcheckResponseTranslatorResourceTest method should_shouldReturnErrorStatusDtoWhenThereIsAProblem.

@Test
public void should_shouldReturnErrorStatusDtoWhenThereIsAProblem() throws Exception {
    Response response = postResponseForTranslation(new SamlMessageDto(Base64.encodeAsString("<saml/>")));
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
    assertThat(entity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlMessageDto(uk.gov.ida.hub.samlengine.domain.SamlMessageDto) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.Test)

Example 3 with SamlMessageDto

use of uk.gov.ida.hub.samlengine.domain.SamlMessageDto in project verify-hub by alphagov.

the class MatchingServiceHealthcheckRequestGeneratorResourceTest method should_createHealthcheckAttributeQueryRequest.

@Test
public void should_createHealthcheckAttributeQueryRequest() throws Exception {
    configStub.setupCertificatesForEntity(TEST_RP_MS);
    Response response = getAttributeQuery(new MatchingServiceHealthCheckerRequestDto(TEST_RP, TEST_RP_MS));
    SamlMessageDto entity = response.readEntity(SamlMessageDto.class);
    assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    assertThat(entity.getSamlMessage()).isNotNull();
}
Also used : Response(javax.ws.rs.core.Response) MatchingServiceHealthCheckerRequestDto(uk.gov.ida.hub.samlengine.contracts.MatchingServiceHealthCheckerRequestDto) SamlMessageDto(uk.gov.ida.hub.samlengine.domain.SamlMessageDto) Test(org.junit.Test)

Example 4 with SamlMessageDto

use of uk.gov.ida.hub.samlengine.domain.SamlMessageDto in project verify-hub by alphagov.

the class MatchingServiceHealthcheckResponseTranslatorResourceTest method should_translateHealthcheckAttributeQueryResponse.

@Test
public void should_translateHealthcheckAttributeQueryResponse() throws Exception {
    final String msaStatusCode = SamlStatusCode.HEALTHY;
    final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(StatusCode.SUCCESS).build()).build();
    final String requestId = "requestId";
    final String saml = aValidMatchResponseFromMatchingService(requestId, status, DateTime.now().plusHours(1));
    Response response = postResponseForTranslation(new SamlMessageDto(Base64.encodeAsString(saml)));
    MatchingServiceHealthCheckerResponseDto entity = response.readEntity(MatchingServiceHealthCheckerResponseDto.class);
    assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    assertThat(entity.getStatus()).isEqualTo(MatchingServiceIdaStatus.Healthy);
    assertThat(entity.getInResponseTo()).isEqualTo(requestId);
    assertThat(entity.getIssuer()).isEqualTo(TEST_RP_MS);
}
Also used : Status(org.opensaml.saml.saml2.core.Status) MatchingServiceIdaStatus(uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus) StatusBuilder.aStatus(uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus) Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlMessageDto(uk.gov.ida.hub.samlengine.domain.SamlMessageDto) MatchingServiceHealthCheckerResponseDto(uk.gov.ida.hub.samlengine.contracts.MatchingServiceHealthCheckerResponseDto) Test(org.junit.Test)

Example 5 with SamlMessageDto

use of uk.gov.ida.hub.samlengine.domain.SamlMessageDto in project verify-hub by alphagov.

the class RpErrorResponseGeneratorResourceTest method shouldGenerateAnErrorResponseForAnRp.

@Test
public void shouldGenerateAnErrorResponseForAnRp() throws JsonProcessingException {
    RequestForErrorResponseFromHubDto requestForErrorResponseFromHubDto = aRequestForErrorResponseFromHubDto().build();
    configStub.signResponsesAndUseSamlStandard(requestForErrorResponseFromHubDto.getAuthnRequestIssuerEntityId());
    final URI uri = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_ERROR_RESPONSE_RESOURCE);
    Response rpAuthnResponse = post(requestForErrorResponseFromHubDto, uri);
    assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    SamlMessageDto samlMessageDto = rpAuthnResponse.readEntity(SamlMessageDto.class);
    assertThat(samlMessageDto.getSamlMessage()).isNotNull();
}
Also used : Response(javax.ws.rs.core.Response) SamlMessageDto(uk.gov.ida.hub.samlengine.domain.SamlMessageDto) RequestForErrorResponseFromHubDtoBuilder.aRequestForErrorResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.RequestForErrorResponseFromHubDtoBuilder.aRequestForErrorResponseFromHubDto) RequestForErrorResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.RequestForErrorResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Aggregations

SamlMessageDto (uk.gov.ida.hub.samlengine.domain.SamlMessageDto)5 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)2 URI (java.net.URI)1 Status (org.opensaml.saml.saml2.core.Status)1 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)1 MatchingServiceHealthCheckerRequestDto (uk.gov.ida.hub.samlengine.contracts.MatchingServiceHealthCheckerRequestDto)1 MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlengine.contracts.MatchingServiceHealthCheckerResponseDto)1 RequestForErrorResponseFromHubDto (uk.gov.ida.hub.samlengine.contracts.RequestForErrorResponseFromHubDto)1 UnableToGenerateSamlException (uk.gov.ida.hub.samlengine.exceptions.UnableToGenerateSamlException)1 RequestForErrorResponseFromHubDtoBuilder.aRequestForErrorResponseFromHubDto (uk.gov.ida.integrationtest.hub.samlengine.builders.RequestForErrorResponseFromHubDtoBuilder.aRequestForErrorResponseFromHubDto)1 OutboundResponseFromHub (uk.gov.ida.saml.core.domain.OutboundResponseFromHub)1 StatusBuilder.aStatus (uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus)1 MatchingServiceIdaStatus (uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus)1