Search in sources :

Example 1 with FraudDetectedDetails

use of uk.gov.ida.saml.core.domain.FraudDetectedDetails 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 2 with FraudDetectedDetails

use of uk.gov.ida.saml.core.domain.FraudDetectedDetails 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)

Example 3 with FraudDetectedDetails

use of uk.gov.ida.saml.core.domain.FraudDetectedDetails in project verify-hub by alphagov.

the class PassthroughAssertionUnmarshallerTest method transform_shouldTransformTheGpg45StatusIt01ForAFraudAssertion.

@Test
public void transform_shouldTransformTheGpg45StatusIt01ForAFraudAssertion() {
    String gpg45Status = "IT01";
    Assertion theAssertion = givenAFraudEventAssertion(gpg45Status);
    PassthroughAssertion passthroughAssertion = unmarshaller.fromAssertion(theAssertion);
    FraudDetectedDetails fraudDetectedDetails = passthroughAssertion.getFraudDetectedDetails().get();
    assertThat(fraudDetectedDetails.getFraudIndicator()).isEqualTo(gpg45Status);
}
Also used : PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) FraudDetectedDetails(uk.gov.ida.saml.core.domain.FraudDetectedDetails) Test(org.junit.jupiter.api.Test)

Example 4 with FraudDetectedDetails

use of uk.gov.ida.saml.core.domain.FraudDetectedDetails in project verify-hub by alphagov.

the class PassthroughAssertionUnmarshaller method fromAssertion.

public PassthroughAssertion fromAssertion(Assertion assertion) {
    PersistentId persistentId = new PersistentId(assertion.getSubject().getNameID().getValue());
    Optional<AuthnContext> levelOfAssurance = Optional.empty();
    Optional<String> principalIpAddress = getPrincipalIpAddress(assertion.getAttributeStatements());
    if (!assertion.getAuthnStatements().isEmpty()) {
        String levelOfAssuranceAsString = assertion.getAuthnStatements().get(0).getAuthnContext().getAuthnContextClassRef().getAuthnContextClassRef();
        levelOfAssurance = Optional.ofNullable(authnContextFactory.authnContextForLevelOfAssurance(levelOfAssuranceAsString));
    }
    String underlyingAssertion = assertionStringTransformer.apply(assertion);
    Optional<FraudDetectedDetails> fraudDetectedDetails = Optional.empty();
    if (levelOfAssurance.isPresent() && levelOfAssurance.get().equals(AuthnContext.LEVEL_X)) {
        String idpFraudEventId = getIdpFraudEventId(assertion.getAttributeStatements());
        fraudDetectedDetails = Optional.of(new FraudDetectedDetails(idpFraudEventId, gpg45Status(assertion.getAttributeStatements())));
    }
    return new PassthroughAssertion(persistentId, levelOfAssurance, underlyingAssertion, fraudDetectedDetails, principalIpAddress);
}
Also used : PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) FraudDetectedDetails(uk.gov.ida.saml.core.domain.FraudDetectedDetails) PersistentId(uk.gov.ida.saml.core.domain.PersistentId) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext)

Example 5 with FraudDetectedDetails

use of uk.gov.ida.saml.core.domain.FraudDetectedDetails in project verify-hub by alphagov.

the class IdpAuthnResponseTranslatorServiceTest method shouldExtractFraudDetails.

@Test
public void shouldExtractFraudDetails() {
    String fraudIndicator = "fraud indicator";
    String fraudEventId = "fraud event id";
    FraudDetectedDetails fraudDetectedDetails = Mockito.mock(FraudDetectedDetails.class);
    when(fraudDetectedDetails.getFraudIndicator()).thenReturn(fraudIndicator);
    when(fraudDetectedDetails.getIdpFraudEventId()).thenReturn(fraudEventId);
    when(authStatementAssertion.getFraudDetectedDetails()).thenReturn(Optional.of(fraudDetectedDetails));
    when(responseFromIdp.getAuthnStatementAssertion()).thenReturn(of(authStatementAssertion));
    InboundResponseFromIdpDto result = translateAndCheckCommonFields();
    checkAuthnStatementValues(result);
    assert (result.getFraudIndicator().get()).equals(fraudIndicator);
    assert (result.getIdpFraudEventId().get()).equals(fraudEventId);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto) FraudDetectedDetails(uk.gov.ida.saml.core.domain.FraudDetectedDetails) Test(org.junit.jupiter.api.Test)

Aggregations

FraudDetectedDetails (uk.gov.ida.saml.core.domain.FraudDetectedDetails)10 Test (org.junit.jupiter.api.Test)9 AuthnContext (uk.gov.ida.saml.core.domain.AuthnContext)5 PassthroughAssertion (uk.gov.ida.saml.core.domain.PassthroughAssertion)5 Assertion (org.opensaml.saml.saml2.core.Assertion)4 InboundResponseFromMatchingServiceDto (uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto)4 SamlResponseContainerDto (uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto)4 AssertionBuilder.anAssertion (uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion)4 MatchingServiceIdaStatus (uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus)4 InboundResponseFromIdpDto (uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto)1 PersistentId (uk.gov.ida.saml.core.domain.PersistentId)1