Search in sources :

Example 1 with SubjectConfirmationData

use of org.opensaml.saml.saml2.core.SubjectConfirmationData in project OpenAttestation by OpenAttestation.

the class SamlGenerator method createSubjectConfirmationData.

/**
         * 
         * The SubjectConfirmationData element may be extended with custom information that we want to include, both as attributes or as child elements.
         * 
         * See also section 2.4.1.2 Element <SubjectConfirmationData> of http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
         * 
         * @param host
         * @return
         * @throws ConfigurationException
         * @throws UnknownHostException 
         */
private SubjectConfirmationData createSubjectConfirmationData(TxtHost host) throws ConfigurationException, UnknownHostException {
    SAMLObjectBuilder confirmationMethodBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
    SubjectConfirmationData confirmationMethod = (SubjectConfirmationData) confirmationMethodBuilder.buildObject();
    DateTime now = new DateTime();
    // Required to add to cache
    samlAssertion.created_ts = now.toDate();
    confirmationMethod.setNotBefore(now);
    if (validitySeconds != null) {
        confirmationMethod.setNotOnOrAfter(now.plusSeconds(validitySeconds));
        // Required to add to cache
        samlAssertion.expiry_ts = confirmationMethod.getNotOnOrAfter().toDate();
    }
    InetAddress localhost = InetAddress.getLocalHost();
    // NOTE: This is the ATTESTATION SERVICE IP ADDRESS,  **NOT** THE HOST ADDRESS
    confirmationMethod.setAddress(localhost.getHostAddress());
    return confirmationMethod;
}
Also used : SAMLObjectBuilder(org.opensaml.common.SAMLObjectBuilder) SubjectConfirmationData(org.opensaml.saml2.core.SubjectConfirmationData) InetAddress(java.net.InetAddress) DateTime(org.joda.time.DateTime)

Example 2 with SubjectConfirmationData

use of org.opensaml.saml.saml2.core.SubjectConfirmationData in project cas by apereo.

the class AbstractSaml20ObjectBuilder method newSubject.

/**
     * New subject element.
     *
     * @param nameIdFormat the name id format
     * @param nameIdValue  the name id value
     * @param recipient    the recipient
     * @param notOnOrAfter the not on or after
     * @param inResponseTo the in response to
     * @return the subject
     */
public Subject newSubject(final String nameIdFormat, final String nameIdValue, final String recipient, final ZonedDateTime notOnOrAfter, final String inResponseTo) {
    final SubjectConfirmation confirmation = newSamlObject(SubjectConfirmation.class);
    confirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
    final SubjectConfirmationData data = newSamlObject(SubjectConfirmationData.class);
    data.setRecipient(recipient);
    data.setNotOnOrAfter(DateTimeUtils.dateTimeOf(notOnOrAfter));
    data.setInResponseTo(inResponseTo);
    confirmation.setSubjectConfirmationData(data);
    final Subject subject = newSamlObject(Subject.class);
    subject.setNameID(getNameID(nameIdFormat, nameIdValue));
    subject.getSubjectConfirmations().add(confirmation);
    return subject;
}
Also used : SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) Subject(org.opensaml.saml.saml2.core.Subject)

Aggregations

InetAddress (java.net.InetAddress)1 DateTime (org.joda.time.DateTime)1 SAMLObjectBuilder (org.opensaml.common.SAMLObjectBuilder)1 Subject (org.opensaml.saml.saml2.core.Subject)1 SubjectConfirmation (org.opensaml.saml.saml2.core.SubjectConfirmation)1 SubjectConfirmationData (org.opensaml.saml.saml2.core.SubjectConfirmationData)1 SubjectConfirmationData (org.opensaml.saml2.core.SubjectConfirmationData)1