Search in sources :

Example 6 with HubAssertion

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

the class HubEidasAttributeQueryRequestBuilderTest method shouldCreateHubAttributeQueryRequest.

@Test
public void shouldCreateHubAttributeQueryRequest() {
    final EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = anEidasAttributeQueryRequestDto().build();
    final Optional<HubAssertion> cycle3AttributeAssertion = Optional.empty();
    HubEidasAttributeQueryRequest expectedResult = new HubEidasAttributeQueryRequest(eidasAttributeQueryRequestDto.getRequestId(), HUB_EIDAS_ENTITY_ID, NOW, new uk.gov.ida.saml.core.domain.PersistentId(eidasAttributeQueryRequestDto.getPersistentId().getNameId()), eidasAttributeQueryRequestDto.getAssertionConsumerServiceUri(), eidasAttributeQueryRequestDto.getAuthnRequestIssuerEntityId(), eidasAttributeQueryRequestDto.getEncryptedIdentityAssertion(), AuthnContext.LEVEL_2, cycle3AttributeAssertion, 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()).isEqualTo(cycle3AttributeAssertion);
    assertThat(hubEidasAttributeQueryRequest.getUserAccountCreationAttributes()).isEqualTo(USER_ACCOUNT_CREATION_ATTRIBUTES);
}
Also used : HubEidasAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubEidasAttributeQueryRequest) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto(uk.gov.ida.hub.samlengine.builders.EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto) EidasAttributeQueryRequestDto(uk.gov.ida.hub.samlengine.domain.EidasAttributeQueryRequestDto) Test(org.junit.Test)

Example 7 with HubAssertion

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

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

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldOnlyIncludeCycle3Unencrypted.

@Test
public void transform_shouldOnlyIncludeCycle3Unencrypted() {
    final HubAssertion cycle3DataAssertion = aHubAssertion().build();
    HubAttributeQueryRequest originalQuery = aHubAttributeQueryRequest().withCycle3DataAssertion(cycle3DataAssertion).build();
    AttributeQuery transformedQuery = transformer.apply(originalQuery);
    List<XMLObject> unknownXMLObjects = transformedQuery.getSubject().getSubjectConfirmations().get(0).getSubjectConfirmationData().getUnknownXMLObjects(Assertion.DEFAULT_ELEMENT_NAME);
    assertThat(unknownXMLObjects.size()).isEqualTo(1);
    assertThat(((Assertion) unknownXMLObjects.get(0)).getID()).isEqualTo(cycle3DataAssertion.getId());
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) PassthroughAssertionBuilder.aPassthroughAssertion(uk.gov.ida.saml.core.test.builders.PassthroughAssertionBuilder.aPassthroughAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) XMLObject(org.opensaml.core.xml.XMLObject) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Test(org.junit.jupiter.api.Test)

Example 10 with HubAssertion

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

the class HubAssertionMarshallerTest method transform_shouldTransformLevelOfCycle3DataAssertion.

@Test
public void transform_shouldTransformLevelOfCycle3DataAssertion() {
    String attributeName = "someName";
    String value = "some value";
    HubAssertion assertion = aHubAssertion().withCycle3Data(aCycle3Dataset().addCycle3Data(attributeName, value).build()).build();
    Attribute expectedAttribute = aSimpleStringAttribute().build();
    when(attributeFactory.createCycle3DataAttribute(attributeName, value)).thenReturn(expectedAttribute);
    Assertion transformedAssertion = marshaller.toSaml(assertion);
    List<AttributeStatement> attributeStatements = transformedAssertion.getAttributeStatements();
    assertThat(attributeStatements.size()).isGreaterThan(0);
    Attribute attribute = attributeStatements.get(0).getAttributes().get(0);
    assertThat(attribute).isEqualTo(expectedAttribute);
}
Also used : SimpleStringAttributeBuilder.aSimpleStringAttribute(uk.gov.ida.saml.core.test.builders.SimpleStringAttributeBuilder.aSimpleStringAttribute) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Test(org.junit.jupiter.api.Test)

Aggregations

HubAssertion (uk.gov.ida.saml.core.domain.HubAssertion)14 Test (org.junit.jupiter.api.Test)8 Assertion (org.opensaml.saml.saml2.core.Assertion)8 HubAssertionBuilder.aHubAssertion (uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion)8 AttributeQuery (org.opensaml.saml.saml2.core.AttributeQuery)3 AssertionRestrictions (uk.gov.ida.saml.core.domain.AssertionRestrictions)3 Cycle3Dataset (uk.gov.ida.saml.core.domain.Cycle3Dataset)3 Test (org.junit.Test)2 Attribute (org.opensaml.saml.saml2.core.Attribute)2 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)2 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)2 Issuer (org.opensaml.saml.saml2.core.Issuer)2 NameID (org.opensaml.saml.saml2.core.NameID)2 EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto (uk.gov.ida.hub.samlengine.builders.EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto)2 EidasAttributeQueryRequestDto (uk.gov.ida.hub.samlengine.domain.EidasAttributeQueryRequestDto)2 PersistentId (uk.gov.ida.saml.core.domain.PersistentId)2 SimpleStringAttributeBuilder.aSimpleStringAttribute (uk.gov.ida.saml.core.test.builders.SimpleStringAttributeBuilder.aSimpleStringAttribute)2 HubAttributeQueryRequest (uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest)2 HubEidasAttributeQueryRequest (uk.gov.ida.saml.hub.domain.HubEidasAttributeQueryRequest)2 HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest (uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest)2