Search in sources :

Example 1 with AssertionRestrictions

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

the class HubEidasAttributeQueryRequestBuilderTest method shouldCreateHubAttributeQueryRequestWithCycle3Assertion.

@Test
public void shouldCreateHubAttributeQueryRequestWithCycle3Assertion() {
    final Map<String, String> dataset = new HashMap<>();
    dataset.put("DrivingLicenceNumber", "MORGA657054SM9IJ");
    final Cycle3Dataset cycle3Dataset = new Cycle3Dataset(dataset);
    final EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = anEidasAttributeQueryRequestDto().withCycle3Dataset(cycle3Dataset).build();
    final uk.gov.ida.saml.core.domain.PersistentId persistentId = new uk.gov.ida.saml.core.domain.PersistentId(eidasAttributeQueryRequestDto.getPersistentId().getNameId());
    final uk.gov.ida.saml.core.domain.Cycle3Dataset oldCycle3Dataset = uk.gov.ida.saml.core.domain.Cycle3Dataset.createFromData(eidasAttributeQueryRequestDto.getCycle3Dataset().get().getAttributes());
    final AssertionRestrictions assertionRestrictions = new AssertionRestrictions(eidasAttributeQueryRequestDto.getAssertionExpiry(), eidasAttributeQueryRequestDto.getRequestId(), eidasAttributeQueryRequestDto.getAuthnRequestIssuerEntityId());
    final HubAssertion hubAssertion = new HubAssertion(UUID.randomUUID().toString(), HUB_EIDAS_ENTITY_ID, NOW, persistentId, assertionRestrictions, Optional.of(oldCycle3Dataset));
    final Optional<HubAssertion> cycle3Assertion = Optional.of(hubAssertion);
    final HubEidasAttributeQueryRequest expectedResult = new HubEidasAttributeQueryRequest(eidasAttributeQueryRequestDto.getRequestId(), HUB_EIDAS_ENTITY_ID, NOW, persistentId, eidasAttributeQueryRequestDto.getAssertionConsumerServiceUri(), eidasAttributeQueryRequestDto.getAuthnRequestIssuerEntityId(), eidasAttributeQueryRequestDto.getEncryptedIdentityAssertion(), AuthnContext.LEVEL_2, cycle3Assertion, USER_ACCOUNT_CREATION_ATTRIBUTES);
    HubEidasAttributeQueryRequest hubEidasAttributeQueryRequest = builder.createHubAttributeQueryRequest(eidasAttributeQueryRequestDto);
    assertThat(hubEidasAttributeQueryRequest.getId()).isEqualTo(expectedResult.getId());
    assertThat(hubEidasAttributeQueryRequest.getPersistentId().getNameId()).isEqualTo(expectedResult.getPersistentId().getNameId());
    assertThat(hubEidasAttributeQueryRequest.getEncryptedIdentityAssertion()).isEqualTo(expectedResult.getEncryptedIdentityAssertion());
    assertThat(hubEidasAttributeQueryRequest.getAssertionConsumerServiceUrl()).isEqualTo(expectedResult.getAssertionConsumerServiceUrl());
    assertThat(hubEidasAttributeQueryRequest.getAuthnRequestIssuerEntityId()).isEqualTo(expectedResult.getAuthnRequestIssuerEntityId());
    assertThat(hubEidasAttributeQueryRequest.getAuthnContext()).isEqualTo(expectedResult.getAuthnContext());
    assertThat(hubEidasAttributeQueryRequest.getIssuer()).isEqualTo(expectedResult.getIssuer());
    assertThat(hubEidasAttributeQueryRequest.getIssueInstant()).isEqualTo(expectedResult.getIssueInstant());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().isPresent()).isTrue();
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getIssuerId()).isEqualTo(hubAssertion.getIssuerId());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getAssertionRestrictions().getInResponseTo()).isEqualTo(hubAssertion.getAssertionRestrictions().getInResponseTo());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getAssertionRestrictions().getNotOnOrAfter()).isEqualTo(hubAssertion.getAssertionRestrictions().getNotOnOrAfter());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getAssertionRestrictions().getRecipient()).isEqualTo(hubAssertion.getAssertionRestrictions().getRecipient());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getPersistentId().getNameId()).isEqualTo(hubAssertion.getPersistentId().getNameId());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getIssueInstant()).isEqualTo(hubAssertion.getIssueInstant());
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getCycle3Data().isPresent()).isTrue();
    assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getCycle3Data().get().getAttributes()).isEqualTo(hubAssertion.getCycle3Data().get().getAttributes());
    assertThat(hubEidasAttributeQueryRequest.getUserAccountCreationAttributes()).isEqualTo(USER_ACCOUNT_CREATION_ATTRIBUTES);
}
Also used : Cycle3Dataset(uk.gov.ida.hub.samlengine.domain.Cycle3Dataset) HashMap(java.util.HashMap) AssertionRestrictions(uk.gov.ida.saml.core.domain.AssertionRestrictions) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) HubEidasAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubEidasAttributeQueryRequest) EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto(uk.gov.ida.hub.samlengine.builders.EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto) EidasAttributeQueryRequestDto(uk.gov.ida.hub.samlengine.domain.EidasAttributeQueryRequestDto) Test(org.junit.Test)

Example 2 with AssertionRestrictions

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

Example 3 with AssertionRestrictions

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

Aggregations

AssertionRestrictions (uk.gov.ida.saml.core.domain.AssertionRestrictions)3 HubAssertion (uk.gov.ida.saml.core.domain.HubAssertion)3 Cycle3Dataset (uk.gov.ida.saml.core.domain.Cycle3Dataset)2 PersistentId (uk.gov.ida.saml.core.domain.PersistentId)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto (uk.gov.ida.hub.samlengine.builders.EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto)1 Cycle3Dataset (uk.gov.ida.hub.samlengine.domain.Cycle3Dataset)1 EidasAttributeQueryRequestDto (uk.gov.ida.hub.samlengine.domain.EidasAttributeQueryRequestDto)1 HubEidasAttributeQueryRequest (uk.gov.ida.saml.hub.domain.HubEidasAttributeQueryRequest)1