Search in sources :

Example 16 with SubjectConfirmation

use of org.opensaml.saml.saml2.core.SubjectConfirmation 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)

Example 17 with SubjectConfirmation

use of org.opensaml.saml.saml2.core.SubjectConfirmation in project spring-security by spring-projects.

the class OpenSamlAuthenticationProviderTests method assertion.

private Assertion assertion() {
    Assertion assertion = TestOpenSamlObjects.assertion();
    assertion.setIssueInstant(DateTime.now());
    for (SubjectConfirmation confirmation : assertion.getSubject().getSubjectConfirmations()) {
        SubjectConfirmationData data = confirmation.getSubjectConfirmationData();
        data.setNotBefore(DateTime.now().minus(Duration.millis(5 * 60 * 1000)));
        data.setNotOnOrAfter(DateTime.now().plus(Duration.millis(5 * 60 * 1000)));
    }
    Conditions conditions = assertion.getConditions();
    conditions.setNotBefore(DateTime.now().minus(Duration.millis(5 * 60 * 1000)));
    conditions.setNotOnOrAfter(DateTime.now().plus(Duration.millis(5 * 60 * 1000)));
    return assertion;
}
Also used : SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) Conditions(org.opensaml.saml.saml2.core.Conditions)

Example 18 with SubjectConfirmation

use of org.opensaml.saml.saml2.core.SubjectConfirmation in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProviderTests method assertion.

private Assertion assertion() {
    Assertion assertion = TestOpenSamlObjects.assertion();
    assertion.setIssueInstant(Instant.now());
    for (SubjectConfirmation confirmation : assertion.getSubject().getSubjectConfirmations()) {
        SubjectConfirmationData data = confirmation.getSubjectConfirmationData();
        data.setNotBefore(Instant.now().minus(Duration.ofMillis(5 * 60 * 1000)));
        data.setNotOnOrAfter(Instant.now().plus(Duration.ofMillis(5 * 60 * 1000)));
    }
    Conditions conditions = assertion.getConditions();
    conditions.setNotBefore(Instant.now().minus(Duration.ofMillis(5 * 60 * 1000)));
    conditions.setNotOnOrAfter(Instant.now().plus(Duration.ofMillis(5 * 60 * 1000)));
    return assertion;
}
Also used : SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) Conditions(org.opensaml.saml.saml2.core.Conditions)

Aggregations

SubjectConfirmation (org.opensaml.saml.saml2.core.SubjectConfirmation)16 Assertion (org.opensaml.saml.saml2.core.Assertion)8 SubjectConfirmationData (org.opensaml.saml.saml2.core.SubjectConfirmationData)8 Subject (org.opensaml.saml.saml2.core.Subject)7 NameID (org.opensaml.saml.saml2.core.NameID)6 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)5 Conditions (org.opensaml.saml.saml2.core.Conditions)4 Issuer (org.opensaml.saml.saml2.core.Issuer)4 CertificateFactory (java.security.cert.CertificateFactory)3 X509Certificate (java.security.cert.X509Certificate)3 DateTime (org.joda.time.DateTime)3 AuthnStatement (org.opensaml.saml.saml2.core.AuthnStatement)3 SecurityServiceException (ddf.security.service.SecurityServiceException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 SignatureException (java.security.SignatureException)2 CertificateException (java.security.cert.CertificateException)2