Search in sources :

Example 1 with InboundResponseFromMatchingServiceDto

use of uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorService method translate.

public InboundResponseFromMatchingServiceDto translate(SamlResponseDto samlResponseDto) {
    final Response response = responseUnmarshaller.apply(samlResponseDto.getSamlResponse());
    MdcHelper.addContextToMdc(response);
    final InboundResponseFromMatchingService responseFromMatchingService = responseToInboundResponseFromMatchingServiceTransformer.transform(response);
    Optional<String> assertionBlob = Optional.empty();
    Optional<LevelOfAssurance> levelOfAssurance = Optional.empty();
    // FIXME?: transformer can return null
    if (responseFromMatchingService.getMatchingServiceAssertion() != null && responseFromMatchingService.getMatchingServiceAssertion().isPresent()) {
        assertionBlob = Optional.ofNullable(responseFromMatchingService.getMatchingServiceAssertion().get().getUnderlyingAssertionBlob());
        final Optional<AuthnContext> authnContext = responseFromMatchingService.getMatchingServiceAssertion().get().getAuthnContext();
        if (authnContext.isPresent()) {
            levelOfAssurance = Optional.of(LevelOfAssurance.valueOf(authnContext.get().name()));
        }
    }
    final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = new InboundResponseFromMatchingServiceDto(responseFromMatchingService.getStatus(), responseFromMatchingService.getInResponseTo(), responseFromMatchingService.getIssuer(), assertionBlob, levelOfAssurance);
    return inboundResponseFromMatchingServiceDto;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) LevelOfAssurance(uk.gov.ida.hub.samlengine.domain.LevelOfAssurance) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext)

Example 2 with InboundResponseFromMatchingServiceDto

use of uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorService method translate.

public InboundResponseFromMatchingServiceDto translate(SamlResponseContainerDto samlResponseContainerDto) {
    final Response response = responseUnmarshaller.apply(samlResponseContainerDto.getSamlResponse());
    MdcHelper.addContextToMdc(response);
    final InboundResponseFromMatchingService responseFromMatchingService = responseToInboundResponseFromMatchingServiceTransformer.transform(response);
    Optional<String> assertionBlob = Optional.empty();
    Optional<LevelOfAssurance> levelOfAssurance = Optional.empty();
    // FIXME?: transformer can return null
    if (responseFromMatchingService.getMatchingServiceAssertion() != null && responseFromMatchingService.getMatchingServiceAssertion().isPresent()) {
        assertionBlob = Optional.ofNullable(responseFromMatchingService.getMatchingServiceAssertion().get().getUnderlyingAssertionBlob());
        final Optional<AuthnContext> authnContext = responseFromMatchingService.getMatchingServiceAssertion().get().getAuthnContext();
        if (authnContext.isPresent()) {
            levelOfAssurance = Optional.of(LevelOfAssurance.valueOf(authnContext.get().name()));
        }
    }
    final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = new InboundResponseFromMatchingServiceDto(responseFromMatchingService.getStatus(), responseFromMatchingService.getInResponseTo(), responseFromMatchingService.getIssuer(), assertionBlob.map(ab -> assertionBlobEncrypter.encryptAssertionBlob(samlResponseContainerDto.getAuthnRequestIssuerId(), ab)), levelOfAssurance);
    return inboundResponseFromMatchingServiceDto;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) LevelOfAssurance(uk.gov.ida.hub.samlengine.domain.LevelOfAssurance) SamlResponseContainerDto(uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto) LevelOfAssurance(uk.gov.ida.hub.samlengine.domain.LevelOfAssurance) Inject(com.google.inject.Inject) StringToOpenSamlObjectTransformer(uk.gov.ida.saml.deserializers.StringToOpenSamlObjectTransformer) AssertionBlobEncrypter(uk.gov.ida.saml.core.transformers.outbound.decorators.AssertionBlobEncrypter) DecoratedSamlResponseToInboundResponseFromMatchingServiceTransformer(uk.gov.ida.saml.hub.transformers.inbound.providers.DecoratedSamlResponseToInboundResponseFromMatchingServiceTransformer) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) Optional(java.util.Optional) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext) MdcHelper(uk.gov.ida.hub.samlengine.logging.MdcHelper) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService) Response(org.opensaml.saml.saml2.core.Response) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext)

Example 3 with InboundResponseFromMatchingServiceDto

use of uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorResourceTest method shouldReturnADtoWhenResponseIs_NoMatch.

@Test
public void shouldReturnADtoWhenResponseIs_NoMatch() throws Exception {
    final String requestId = "requestId";
    final String msaStatusCode = SamlStatusCode.NO_MATCH;
    final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(RESPONDER).build()).build();
    final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(Base64.getEncoder().encodeToString(aValidNoMatchResponseFromMatchingService(requestId, status, TEST_RP_MS).getBytes()), TEST_RP);
    Response clientResponse = postToSamlEngine(samlResponseContainerDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
    assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
    assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
    assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.NoMatchingServiceMatchFromMatchingService.name());
    assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance()).isNotPresent();
    assertThat(inboundResponseFromMatchingServiceDto.getEncryptedMatchingServiceAssertion()).isNotPresent();
}
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) SamlResponseContainerDto(uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) Test(org.junit.jupiter.api.Test)

Example 4 with InboundResponseFromMatchingServiceDto

use of uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorServiceTest method populateReturnDtoCorrectly_handleRequesterError.

@Test
public void populateReturnDtoCorrectly_handleRequesterError() {
    final String inResponseTo = "inResponseTo";
    final String issuer = "issuer";
    final Optional<AuthnContext> authnContext = Optional.empty();
    final Optional<FraudDetectedDetails> fraudDetectedDetails = Optional.empty();
    final String underlyingAssertionBlob = null;
    final MatchingServiceIdaStatus status = MatchingServiceIdaStatus.RequesterError;
    final SamlResponseContainerDto samlResponse = new SamlResponseContainerDto("saml", TEST_RP);
    setUpForTranslate(authnContext, fraudDetectedDetails, underlyingAssertionBlob, inResponseTo, issuer, samlResponse.getSamlResponse(), status);
    final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = matchingServiceResponseTranslatorService.translate(samlResponse);
    assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(inResponseTo);
    assertThat(inboundResponseFromMatchingServiceDto.getEncryptedMatchingServiceAssertion()).isNotPresent();
    assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(issuer);
    assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance()).isNotPresent();
    assertThat(inboundResponseFromMatchingServiceDto.getStatus()).isEqualTo(status);
}
Also used : SamlResponseContainerDto(uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto) FraudDetectedDetails(uk.gov.ida.saml.core.domain.FraudDetectedDetails) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext) MatchingServiceIdaStatus(uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus) Test(org.junit.jupiter.api.Test)

Example 5 with InboundResponseFromMatchingServiceDto

use of uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorServiceTest method populateReturnDtoCorrectly_handleMatchResponse.

@Test
public void populateReturnDtoCorrectly_handleMatchResponse() {
    final String inResponseTo = "inResponseTo";
    final String issuer = "issuer";
    final Optional<AuthnContext> authnContext = Optional.of(AuthnContext.LEVEL_2);
    final Optional<FraudDetectedDetails> fraudDetectedDetails = Optional.empty();
    final String encryptedAssertion = "encryptedAssertion";
    final MatchingServiceIdaStatus status = MatchingServiceIdaStatus.MatchingServiceMatch;
    final SamlResponseContainerDto samlResponse = new SamlResponseContainerDto("saml", TEST_RP);
    setUpForTranslate(authnContext, fraudDetectedDetails, encryptedAssertion, inResponseTo, issuer, samlResponse.getSamlResponse(), status);
    final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = matchingServiceResponseTranslatorService.translate(samlResponse);
    assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(inResponseTo);
    assertThat(inboundResponseFromMatchingServiceDto.getEncryptedMatchingServiceAssertion().isPresent()).isTrue();
    assertThat(inboundResponseFromMatchingServiceDto.getEncryptedMatchingServiceAssertion().get()).isEqualTo(encryptedAssertion);
    assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(issuer);
    assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isTrue();
    assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().get().name()).isEqualTo(authnContext.get().name());
    assertThat(inboundResponseFromMatchingServiceDto.getStatus()).isEqualTo(status);
}
Also used : SamlResponseContainerDto(uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto) FraudDetectedDetails(uk.gov.ida.saml.core.domain.FraudDetectedDetails) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext) MatchingServiceIdaStatus(uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus) Test(org.junit.jupiter.api.Test)

Aggregations

InboundResponseFromMatchingServiceDto (uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto)10 SamlResponseContainerDto (uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto)9 Test (org.junit.jupiter.api.Test)8 MatchingServiceIdaStatus (uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus)8 AuthnContext (uk.gov.ida.saml.core.domain.AuthnContext)6 Response (javax.ws.rs.core.Response)4 Status (org.opensaml.saml.saml2.core.Status)4 FraudDetectedDetails (uk.gov.ida.saml.core.domain.FraudDetectedDetails)4 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)4 StatusBuilder.aStatus (uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus)4 Response (org.opensaml.saml.saml2.core.Response)2 LevelOfAssurance (uk.gov.ida.hub.samlengine.domain.LevelOfAssurance)2 InboundResponseFromMatchingService (uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService)2 Inject (com.google.inject.Inject)1 Optional (java.util.Optional)1 MdcHelper (uk.gov.ida.hub.samlengine.logging.MdcHelper)1 AssertionBlobEncrypter (uk.gov.ida.saml.core.transformers.outbound.decorators.AssertionBlobEncrypter)1 StringToOpenSamlObjectTransformer (uk.gov.ida.saml.deserializers.StringToOpenSamlObjectTransformer)1 DecoratedSamlResponseToInboundResponseFromMatchingServiceTransformer (uk.gov.ida.saml.hub.transformers.inbound.providers.DecoratedSamlResponseToInboundResponseFromMatchingServiceTransformer)1