use of org.opensaml.saml2.core.Attribute in project OpenAttestation by OpenAttestation.
the class TrustAssertion method populateAssertionMap.
/**
* Sample assertion statements that may appear in the XML: Trusted (boolean)
* Trusted_BIOS (boolean) Trusted_VMM (boolean) BIOS_Name (string)
* BIOS_Version (string) BIOS_OEM (string) VMM_Name (string) VMM_Version
* (string) VMM_OSName (string) VMM_OSVersion (string) The BIOS_* entries
* will only appear if Trusted_BIOS is true The VMM_* entries will only
* appear if Trusted_VMM is true
*/
private void populateAssertionMap() {
for (Statement statement : assertion.getStatements()) {
if (statement instanceof AttributeStatement) {
HashMap<String, String> assertionMap = new HashMap<String, String>();
HostTrustAssertion hostTrustAssertion = new HostTrustAssertion(assertion, assertionMap);
log.debug("attributes.size: " + ((AttributeStatement) statement).getAttributes().size());
for (Attribute attribute : ((AttributeStatement) statement).getAttributes()) {
String attributeValue = null;
for (XMLObject value : attribute.getAttributeValues()) {
if (value instanceof XSAny) {
// boolean attributes are the text "true" or "false"
attributeValue = (((XSAny) value).getTextContent());
}
if (value instanceof XSString) {
attributeValue = (((XSString) value).getValue());
}
}
assertionMap.put(attribute.getName(), attributeValue);
}
hostAssertionMap.put(assertionMap.get("Host_Name"), hostTrustAssertion);
}
}
}
use of org.opensaml.saml2.core.Attribute in project OpenAttestation by OpenAttestation.
the class SamlGenerator method createBase64BinaryAttribute.
/**
* Creates a base64-encoded attribute
* @param name
* @param value
* @return
* @throws ConfigurationException
*/
private Attribute createBase64BinaryAttribute(String name, byte[] value) throws ConfigurationException {
SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
Attribute attr = (Attribute) attrBuilder.buildObject();
attr.setName(name);
XMLObjectBuilder xmlBuilder = builderFactory.getBuilder(XSBase64Binary.TYPE_NAME);
XSBase64Binary attrValue = (XSBase64Binary) xmlBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME);
attrValue.setValue(Base64.encodeBase64String(value));
attr.getAttributeValues().add(attrValue);
return attr;
}
use of org.opensaml.saml2.core.Attribute in project OpenAttestation by OpenAttestation.
the class SamlGenerator method createBooleanAttribute.
/**
* This method builds a single-valued boolean attribute such as isTrusted=true
* @param name
* @param value
* @return
* @throws ConfigurationException
*/
private Attribute createBooleanAttribute(String name, boolean value) throws ConfigurationException {
SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
Attribute attr = (Attribute) attrBuilder.buildObject();
attr.setName(name);
XMLObjectBuilder xmlBuilder = builderFactory.getBuilder(XSAny.TYPE_NAME);
XSAny attrValue = (XSAny) xmlBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME);
attrValue.setTextContent(value ? "true" : "false");
attr.getAttributeValues().add(attrValue);
return attr;
}
use of org.opensaml.saml2.core.Attribute in project OpenAttestation by OpenAttestation.
the class SamlGenerator method createAssertion.
/**
* Differences from createAssertion:
* - the assertion ID is "MultipleHostTrustAssertion" instead of "HostTrustAssertion"
* - there is no overall Subject for the assertion because it's for multiple host
* - each host is identified with host attributes within its own attribute statement
*
* @param hosts
* @return
* @throws ConfigurationException
* @throws UnknownHostException
*/
private Assertion createAssertion(Collection<TxtHostWithAssetTag> hosts) throws ConfigurationException, UnknownHostException {
// Create the assertion
SAMLObjectBuilder assertionBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
Assertion assertion = (Assertion) assertionBuilder.buildObject();
// ID is arbitrary, only needs to be unique WITHIN THE DOCUMENT, and is required so that the Signature element can refer to it, for example #HostTrustAssertion
assertion.setID("MultipleHostTrustAssertion");
assertion.setIssuer(createIssuer());
DateTime now = new DateTime();
assertion.setIssueInstant(now);
assertion.setVersion(SAMLVersion.VERSION_20);
// assertion.setSubject(createSubject(host));
for (TxtHostWithAssetTag host : hosts) {
assertion.getAttributeStatements().add(createHostAttributes(host.getHost(), host.getTagCertificate(), null));
}
return assertion;
}
use of org.opensaml.saml2.core.Attribute 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);
}
}
Aggregations