Search in sources :

Example 1 with InboundResponseFromIdpDto

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

the class IdpAuthnResponseTranslatorServiceTest method translateAndCheckCommonFields.

private InboundResponseFromIdpDto translateAndCheckCommonFields() {
    InboundResponseFromIdpDto result = service.translate(responseContainer);
    checkAlwaysPresentFields(result);
    return result;
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto)

Example 2 with InboundResponseFromIdpDto

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

the class IdpAuthnResponseTranslatorResourceTest method shouldTranslateAFraudResponseFromIdp.

@Test
public void shouldTranslateAFraudResponseFromIdp() throws Exception {
    String persistentId = UUID.randomUUID().toString();
    final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aFraudResponseFromIdpBuilder(STUB_IDP_ONE, persistentId).withDestination(IDP_RESPONSE_ENDPOINT).build();
    String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
    SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId(TEST_RP_MS).build();
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    InboundResponseFromIdpDto inboundResponseFromIdpDto = clientResponse.readEntity(InboundResponseFromIdpDto.class);
    assertThat(inboundResponseFromIdpDto.getStatus()).isEqualTo(IdpIdaStatus.Status.Success);
    assertThat(inboundResponseFromIdpDto.getIssuer()).isEqualTo(samlAuthnResponse.getIssuer().getValue());
    // TODO consider checking the values of the ones we've checked presence of below
    assertThat(inboundResponseFromIdpDto.getAuthnStatementAssertionBlob().isPresent()).isTrue();
    assertThat(inboundResponseFromIdpDto.getEncryptedMatchingDatasetAssertion().isPresent()).isTrue();
    assertThat(inboundResponseFromIdpDto.getPersistentId().get()).isEqualTo(persistentId);
    assertThat(inboundResponseFromIdpDto.getLevelOfAssurance().get()).isEqualTo(LevelOfAssurance.LEVEL_X);
    assertThat(inboundResponseFromIdpDto.getPrincipalIpAddressAsSeenByIdp().isPresent()).isTrue();
    assertThat(inboundResponseFromIdpDto.getFraudIndicator().isPresent()).isTrue();
    assertThat(inboundResponseFromIdpDto.getIdpFraudEventId().isPresent()).isTrue();
}
Also used : Response(javax.ws.rs.core.Response) InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) Test(org.junit.Test)

Example 3 with InboundResponseFromIdpDto

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

the class IdpAuthnResponseTranslatorResourceTest method shouldTranslateARequesterErrorResponseFromIdp.

@Test
public void shouldTranslateARequesterErrorResponseFromIdp() throws Exception {
    final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.anAuthnFailedResponseFromIdpBuilder(STUB_IDP_ONE).withDestination(IDP_RESPONSE_ENDPOINT).withStatus(REQUESTER_ERROR_STATUS).build();
    String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
    SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId("IGNOREME").build();
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    InboundResponseFromIdpDto inboundResponseFromIdpDto = clientResponse.readEntity(InboundResponseFromIdpDto.class);
    assertThat(inboundResponseFromIdpDto.getStatus()).isEqualTo(IdpIdaStatus.Status.RequesterError);
    assertThat(inboundResponseFromIdpDto.getIssuer()).isEqualTo(samlAuthnResponse.getIssuer().getValue());
    checkFieldsForUnsuccessfulResponseDTO(inboundResponseFromIdpDto);
}
Also used : Response(javax.ws.rs.core.Response) InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) Test(org.junit.Test)

Example 4 with InboundResponseFromIdpDto

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

the class IdpAuthnResponseTranslatorResourceTest method shouldTranslateAnAuthenticationFailedResponseFromIdp.

@Test
public void shouldTranslateAnAuthenticationFailedResponseFromIdp() throws Exception {
    final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.anAuthnFailedResponseFromIdpBuilder(STUB_IDP_ONE).withDestination(IDP_RESPONSE_ENDPOINT).withStatus(AUTHN_FAILED_STATUS).build();
    String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
    SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId("IGNOREME").build();
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    InboundResponseFromIdpDto inboundResponseFromIdpDto = clientResponse.readEntity(InboundResponseFromIdpDto.class);
    assertThat(inboundResponseFromIdpDto.getStatus()).isEqualTo(IdpIdaStatus.Status.AuthenticationFailed);
    assertThat(inboundResponseFromIdpDto.getIssuer()).isEqualTo(samlAuthnResponse.getIssuer().getValue());
    checkFieldsForUnsuccessfulResponseDTO(inboundResponseFromIdpDto);
}
Also used : Response(javax.ws.rs.core.Response) InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) Test(org.junit.Test)

Example 5 with InboundResponseFromIdpDto

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

the class IdpAuthnResponseTranslatorResourceTest method shouldPreserveStatusMessageForRequesterError.

@Test
public void shouldPreserveStatusMessageForRequesterError() throws Exception {
    final String statusMessage = "status-message";
    final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.anAuthnFailedResponseFromIdpBuilder(STUB_IDP_ONE).withDestination(IDP_RESPONSE_ENDPOINT).withStatus(StatusBuilder.aStatus().withMessage(StatusMessageBuilder.aStatusMessage().withMessage(statusMessage).build()).withStatusCode(StatusCodeBuilder.aStatusCode().withValue(StatusCode.REQUESTER).build()).build()).build();
    String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
    SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId(TEST_RP_MS).build();
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    InboundResponseFromIdpDto inboundResponseFromIdpDto = clientResponse.readEntity(InboundResponseFromIdpDto.class);
    assertThat(inboundResponseFromIdpDto.getStatus()).isEqualTo(IdpIdaStatus.Status.RequesterError);
    assertThat(inboundResponseFromIdpDto.getStatusMessage().get()).isEqualTo(statusMessage);
}
Also used : Response(javax.ws.rs.core.Response) InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) Test(org.junit.Test)

Aggregations

InboundResponseFromIdpDto (uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto)15 Test (org.junit.Test)13 Response (javax.ws.rs.core.Response)8 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto)8 SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto (uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto)8 Assertion (org.opensaml.saml.saml2.core.Assertion)1 Response (org.opensaml.saml.saml2.core.Response)1 BasicCredential (org.opensaml.security.credential.BasicCredential)1 LevelOfAssurance (uk.gov.ida.hub.samlengine.domain.LevelOfAssurance)1 SamlContextException (uk.gov.ida.hub.samlengine.exceptions.SamlContextException)1 AuthnContext (uk.gov.ida.saml.core.domain.AuthnContext)1 FraudDetectedDetails (uk.gov.ida.saml.core.domain.FraudDetectedDetails)1 InboundResponseFromIdpData (uk.gov.ida.saml.core.domain.InboundResponseFromIdpData)1 PassthroughAssertion (uk.gov.ida.saml.core.domain.PassthroughAssertion)1 HardCodedKeyStore (uk.gov.ida.saml.core.test.HardCodedKeyStore)1 SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)1 InboundResponseFromIdp (uk.gov.ida.saml.hub.domain.InboundResponseFromIdp)1