Search in sources :

Example 1 with SubjectConfirmationData

use of org.opensaml.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)

Example 2 with SubjectConfirmationData

use of org.opensaml.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 3 with SubjectConfirmationData

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

the class AbstractSaml20ObjectBuilder method newSubject.

/**
 * New subject element.
 *
 * @param nameId       the nameId
 * @param recipient    the recipient
 * @param notOnOrAfter the not on or after
 * @param inResponseTo the in response to
 * @param notBefore    the not before
 * @return the subject
 */
public Subject newSubject(final NameID nameId, final String recipient, final ZonedDateTime notOnOrAfter, final String inResponseTo, final ZonedDateTime notBefore) {
    LOGGER.debug("Building subject for NameID [{}] and recipient [{}], in response to [{}]", nameId, recipient, inResponseTo);
    final SubjectConfirmation confirmation = newSamlObject(SubjectConfirmation.class);
    confirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
    final SubjectConfirmationData data = newSamlObject(SubjectConfirmationData.class);
    if (StringUtils.isNotBlank(recipient)) {
        data.setRecipient(recipient);
    }
    if (notOnOrAfter != null) {
        data.setNotOnOrAfter(DateTimeUtils.dateTimeOf(notOnOrAfter));
    }
    if (StringUtils.isNotBlank(inResponseTo)) {
        data.setInResponseTo(inResponseTo);
        final InetAddress ip = InetAddressUtils.getByName(inResponseTo);
        if (ip != null) {
            data.setAddress(ip.getHostName());
        }
    }
    if (notBefore != null) {
        data.setNotBefore(DateTimeUtils.dateTimeOf(notBefore));
    }
    confirmation.setSubjectConfirmationData(data);
    final Subject subject = newSamlObject(Subject.class);
    if (nameId != null) {
        subject.setNameID(nameId);
    }
    subject.getSubjectConfirmations().add(confirmation);
    LOGGER.debug("Built subject [{}]", subject);
    return subject;
}
Also used : SubjectConfirmation(org.opensaml.saml.saml2.core.SubjectConfirmation) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) InetAddress(java.net.InetAddress) Subject(org.opensaml.saml.saml2.core.Subject)

Aggregations

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