Search in sources :

Example 1 with AssertionMarshaller

use of org.opensaml.saml2.core.impl.AssertionMarshaller in project OpenAttestation by OpenAttestation.

the class SamlGenerator method generateHostAssertion.

/*
    public void setKeystoreResource(Resource keystoreResource) {
        this.keystoreResource = keystoreResource;
    }*/
/**
     * Input is a Host record with all the attributes to assert
     * Output is XML containing the SAML assertions
     * 
     * From /hosts/trust we get BIOS:1,VMM:1
     * From /hosts/location we get location
     * From /pollhosts we get trust level "unknown/untrusted/trusted" and timestamp
     * From /hosts/reports/trust we get host name, mle info string, created on, overall trust status, and verified on
     * From /hosts/reports/manifest we get PCR values, trust status, and verified on for each PCR
     * 
     * @return @SamlAssertion
     * @throws MarshallingException 
     */
public SamlAssertion generateHostAssertion(TxtHost host, X509AttributeCertificate tagCertificate, Map<String, String> vmMetaData) throws MarshallingException, ConfigurationException, UnknownHostException, GeneralSecurityException, XMLSignatureException, MarshalException {
    samlAssertion = new SamlAssertion();
    Assertion assertion = createAssertion(host, tagCertificate, vmMetaData);
    AssertionMarshaller marshaller = new AssertionMarshaller();
    Element plaintextElement = marshaller.marshall(assertion);
    //String originalAssertionString = XMLHelper.nodeToString(plaintextElement);
    XMLHelper.nodeToString(plaintextElement);
    log.info("Uncomment the next line to see the original Assertion String");
    //System.out.println("Assertion String: " + originalAssertionString);//
    // add signatures and/or encryption
    signAssertion(plaintextElement);
    samlAssertion.assertion = XMLHelper.nodeToString(plaintextElement);
    log.info("Uncomment the next line to see the saml Assertion propertie");
    //System.out.println("Signed Assertion String: " + samlAssertion.assertion );
    return samlAssertion;
}
Also used : AssertionMarshaller(org.opensaml.saml2.core.impl.AssertionMarshaller) Element(org.w3c.dom.Element) Assertion(org.opensaml.saml2.core.Assertion)

Example 2 with AssertionMarshaller

use of org.opensaml.saml2.core.impl.AssertionMarshaller in project OpenAttestation by OpenAttestation.

the class SamlGenerator method generateHostAssertions.

/**
     * Generates a multi-host SAML assertion which contains an AttributeStatement
     * for each host containing a Host_Address attribute with the host IP address
     * or hostname and the trust attributes as for a single-host assertion.
     * The Subject of the multi-host SAML assertion should not be used because
     * it is simply the collection hosts in the assertion and no statements
     * are made about the collection as a whole.
     * 
     * @param hosts
     * @return
     * @throws SamlException 
     */
public SamlAssertion generateHostAssertions(Collection<TxtHostWithAssetTag> hosts) throws SamlException {
    try {
        samlAssertion = new SamlAssertion();
        Assertion assertion = createAssertion(hosts);
        AssertionMarshaller marshaller = new AssertionMarshaller();
        Element plaintextElement = marshaller.marshall(assertion);
        String originalAssertionString = XMLHelper.nodeToString(plaintextElement);
        System.out.println("Assertion String: " + originalAssertionString);
        // add signatures and/or encryption
        signAssertion(plaintextElement);
        samlAssertion.assertion = XMLHelper.nodeToString(plaintextElement);
        System.out.println("Signed Assertion String: " + samlAssertion.assertion);
        return samlAssertion;
    } catch (Exception e) {
        throw new SamlException(e);
    }
}
Also used : AssertionMarshaller(org.opensaml.saml2.core.impl.AssertionMarshaller) Element(org.w3c.dom.Element) Assertion(org.opensaml.saml2.core.Assertion) XSString(org.opensaml.xml.schema.XSString) MarshalException(javax.xml.crypto.MarshalException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) XMLSignatureException(javax.xml.crypto.dsig.XMLSignatureException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) MarshallingException(org.opensaml.xml.io.MarshallingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(org.opensaml.xml.ConfigurationException)

Aggregations

Assertion (org.opensaml.saml2.core.Assertion)2 AssertionMarshaller (org.opensaml.saml2.core.impl.AssertionMarshaller)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1 CertificateException (java.security.cert.CertificateException)1 MarshalException (javax.xml.crypto.MarshalException)1 XMLSignatureException (javax.xml.crypto.dsig.XMLSignatureException)1 ConfigurationException (org.opensaml.xml.ConfigurationException)1 MarshallingException (org.opensaml.xml.io.MarshallingException)1 XSString (org.opensaml.xml.schema.XSString)1