Search in sources :

Example 11 with HubAssertion

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

the class HubAssertionMarshallerTest method transform_shouldTransformAssertionId.

@Test
public void transform_shouldTransformAssertionId() {
    String assertionId = "assertion-id";
    HubAssertion assertion = aHubAssertion().withId(assertionId).build();
    Assertion transformedAssertion = marshaller.toSaml(assertion);
    assertThat(transformedAssertion.getID()).isEqualTo(assertionId);
}
Also used : 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)

Example 12 with HubAssertion

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

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

the class HubAssertionMarshaller method toSaml.

public Assertion toSaml(HubAssertion hubAssertion) {
    Assertion transformedAssertion = openSamlXmlObjectFactory.createAssertion();
    transformedAssertion.setIssueInstant(hubAssertion.getIssueInstant());
    Issuer transformedIssuer = openSamlXmlObjectFactory.createIssuer(hubAssertion.getIssuerId());
    transformedAssertion.setIssuer(transformedIssuer);
    transformedAssertion.setID(hubAssertion.getId());
    if (hubAssertion.getCycle3Data().isPresent()) {
        Cycle3Dataset cycle3Data = hubAssertion.getCycle3Data().get();
        transformedAssertion.getAttributeStatements().add(transform(cycle3Data));
    }
    transformedAssertion.setSubject(outboundAssertionToSubjectTransformer.transform(hubAssertion));
    return transformedAssertion;
}
Also used : Cycle3Dataset(uk.gov.ida.saml.core.domain.Cycle3Dataset) Issuer(org.opensaml.saml.saml2.core.Issuer) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion)

Example 14 with HubAssertion

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformer method apply.

public AttributeQuery apply(HubAttributeQueryRequest originalQuery) {
    AttributeQuery transformedQuery = samlObjectFactory.createAttributeQuery();
    Issuer issuer = samlObjectFactory.createIssuer(originalQuery.getIssuer());
    transformedQuery.setID(originalQuery.getId());
    transformedQuery.setIssuer(issuer);
    transformedQuery.setIssueInstant(DateTime.now());
    if (originalQuery.getUserAccountCreationAttributes().isPresent()) {
        transformedQuery.getAttributes().addAll(createAttributeList(originalQuery.getUserAccountCreationAttributes().get()));
    }
    Subject subject = samlObjectFactory.createSubject();
    NameID nameId = samlObjectFactory.createNameId(originalQuery.getPersistentId().getNameId());
    nameId.setSPNameQualifier(originalQuery.getAuthnRequestIssuerEntityId());
    nameId.setNameQualifier(originalQuery.getAssertionConsumerServiceUrl().toASCIIString());
    subject.setNameID(nameId);
    SubjectConfirmation subjectConfirmation = samlObjectFactory.createSubjectConfirmation();
    SubjectConfirmationData subjectConfirmationData = samlObjectFactory.createSubjectConfirmationData();
    Stream.of(originalQuery.getEncryptedMatchingDatasetAssertion(), originalQuery.getEncryptedAuthnAssertion()).map(encryptedAssertionUnmarshaller::transform).forEach(subjectConfirmationData.getUnknownXMLObjects(EncryptedAssertion.DEFAULT_ELEMENT_NAME)::add);
    final Optional<HubAssertion> cycle3DatasetAssertion = originalQuery.getCycle3AttributeAssertion();
    if (cycle3DatasetAssertion.isPresent()) {
        Assertion transformedCycle3DatasetAssertion = hubAssertionMarshaller.toSaml(cycle3DatasetAssertion.get());
        subjectConfirmationData.getUnknownXMLObjects(Assertion.DEFAULT_ELEMENT_NAME).add(transformedCycle3DatasetAssertion);
    }
    subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);
    subject.getSubjectConfirmations().add(subjectConfirmation);
    transformedQuery.setSubject(subject);
    return transformedQuery;
}
Also used : SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) Issuer(org.opensaml.saml.saml2.core.Issuer) NameID(org.opensaml.saml.saml2.core.NameID) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) Subject(org.opensaml.saml.saml2.core.Subject) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion)

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