Search in sources :

Example 1 with PersistentId

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldProperlyTransform.

@Test
public void transform_shouldProperlyTransform() {
    PersistentId persistentId = new PersistentId("default-name-id");
    HubAttributeQueryRequest originalQuery = aHubAttributeQueryRequest().withId("originalId").withPersistentId(persistentId).build();
    AttributeQuery transformedQuery = transformer.apply(originalQuery);
    assertThat(transformedQuery.getID()).isEqualTo(originalQuery.getId());
    assertThat(transformedQuery.getSubject().getNameID().getValue()).isEqualTo(persistentId.getNameId());
    assertThat(transformedQuery.getIssuer().getValue()).isEqualTo(originalQuery.getIssuer());
    assertThat(transformedQuery.getVersion()).isEqualTo(SAMLVersion.VERSION_20);
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) PersistentId(uk.gov.ida.saml.core.domain.PersistentId) Test(org.junit.jupiter.api.Test)

Example 2 with PersistentId

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

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

the class HubEidasAttributeQueryRequestBuilder method createCycle3Assertion.

private Optional<HubAssertion> createCycle3Assertion(EidasAttributeQueryRequestDto attributeQueryRequestDto) {
    Optional<HubAssertion> cycle3AttributeAssertion = Optional.empty();
    Optional<uk.gov.ida.hub.samlengine.domain.Cycle3Dataset> serializableCycle3Dataset = attributeQueryRequestDto.getCycle3Dataset();
    if (serializableCycle3Dataset.isPresent()) {
        AssertionRestrictions assertionRestrictions = new AssertionRestrictions(attributeQueryRequestDto.getAssertionExpiry(), attributeQueryRequestDto.getRequestId(), attributeQueryRequestDto.getAuthnRequestIssuerEntityId());
        Optional<Cycle3Dataset> cycle3Data = serializableCycle3Dataset.map(uk.gov.ida.hub.samlengine.domain.Cycle3Dataset::getAttributes).map(Cycle3Dataset::createFromData);
        HubAssertion hubAssertion = new HubAssertion(UUID.randomUUID().toString(), hubEntityId, DateTime.now(), new PersistentId(attributeQueryRequestDto.getPersistentId().getNameId()), assertionRestrictions, cycle3Data);
        cycle3AttributeAssertion = Optional.of(hubAssertion);
    }
    return cycle3AttributeAssertion;
}
Also used : Cycle3Dataset(uk.gov.ida.saml.core.domain.Cycle3Dataset) AssertionRestrictions(uk.gov.ida.saml.core.domain.AssertionRestrictions) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) PersistentId(uk.gov.ida.saml.core.domain.PersistentId)

Example 4 with PersistentId

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

the class MatchingServiceResponseTranslatorServiceTest method setUpForTranslate.

private void setUpForTranslate(Optional<AuthnContext> authnContext, Optional<FraudDetectedDetails> fraudDetectedDetails, String encryptedAssertion, String inResponseTo, String issuer, String samlResponse, MatchingServiceIdaStatus status) {
    final PassthroughAssertion assertion = new PassthroughAssertion(new PersistentId("persistentId"), authnContext, encryptedAssertion, fraudDetectedDetails, Optional.of("principalIpAddressAsSeenByIdp"));
    final InboundResponseFromMatchingService inboundResponseFromMatchingService = InboundResponseFromMatchingServiceBuilder.anInboundResponseFromMatchingService().withInResponseTo(inResponseTo).withIssuerId(issuer).withMatchingServiceAssertion(assertion).withStatus(status).build();
    Response response = mock(Response.class);
    Issuer responseIssuer = mock(Issuer.class);
    when(response.getIssuer()).thenReturn(responseIssuer);
    when(responseUnmarshaller.apply(samlResponse)).thenReturn(response);
    when(responseToInboundResponseFromMatchingServiceTransformer.transform(response)).thenReturn(inboundResponseFromMatchingService);
    when(assertionBlobEncrypter.encryptAssertionBlob(eq(TEST_RP), any())).thenReturn(encryptedAssertion);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) Issuer(org.opensaml.saml.saml2.core.Issuer) PersistentId(uk.gov.ida.saml.core.domain.PersistentId) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService)

Example 5 with PersistentId

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

the class HubAttributeQueryRequestBuilder method createCycle3Assertion.

private Optional<HubAssertion> createCycle3Assertion(AttributeQueryRequestDto attributeQueryRequestDto) {
    Optional<HubAssertion> cycle3AttributeAssertion = Optional.empty();
    if (attributeQueryRequestDto.getCycle3Dataset().isPresent()) {
        AssertionRestrictions assertionRestrictions = new AssertionRestrictions(attributeQueryRequestDto.getAssertionExpiry(), attributeQueryRequestDto.getRequestId(), attributeQueryRequestDto.getAuthnRequestIssuerEntityId());
        Optional<Cycle3Dataset> cycle3Data = Optional.of(Cycle3Dataset.createFromData(attributeQueryRequestDto.getCycle3Dataset().get().getAttributes()));
        cycle3AttributeAssertion = Optional.of(new HubAssertion(UUID.randomUUID().toString(), hubEntityId, DateTime.now(), new PersistentId(attributeQueryRequestDto.getPersistentId().getNameId()), assertionRestrictions, cycle3Data));
    }
    return cycle3AttributeAssertion;
}
Also used : Cycle3Dataset(uk.gov.ida.saml.core.domain.Cycle3Dataset) AssertionRestrictions(uk.gov.ida.saml.core.domain.AssertionRestrictions) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) PersistentId(uk.gov.ida.saml.core.domain.PersistentId)

Aggregations

PersistentId (uk.gov.ida.saml.core.domain.PersistentId)5 AssertionRestrictions (uk.gov.ida.saml.core.domain.AssertionRestrictions)2 Cycle3Dataset (uk.gov.ida.saml.core.domain.Cycle3Dataset)2 HubAssertion (uk.gov.ida.saml.core.domain.HubAssertion)2 PassthroughAssertion (uk.gov.ida.saml.core.domain.PassthroughAssertion)2 Test (org.junit.jupiter.api.Test)1 AttributeQuery (org.opensaml.saml.saml2.core.AttributeQuery)1 Issuer (org.opensaml.saml.saml2.core.Issuer)1 Response (org.opensaml.saml.saml2.core.Response)1 AuthnContext (uk.gov.ida.saml.core.domain.AuthnContext)1 FraudDetectedDetails (uk.gov.ida.saml.core.domain.FraudDetectedDetails)1 HubAttributeQueryRequest (uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest)1 InboundResponseFromMatchingService (uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService)1 HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest (uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest)1