use of org.opensaml.core.xml.io.Marshaller in project cas by apereo.
the class AbstractSamlObjectBuilder method marshalSamlXmlObject.
/**
* Marshal the saml xml object to raw xml.
*
* @param object the object
* @param writer the writer
* @return the xml string
*/
public String marshalSamlXmlObject(final XMLObject object, final StringWriter writer) {
try {
final MarshallerFactory marshallerFactory = XMLObjectProviderRegistrySupport.getMarshallerFactory();
final Marshaller marshaller = marshallerFactory.getMarshaller(object);
if (marshaller == null) {
throw new IllegalArgumentException("Cannot obtain marshaller for object " + object.getElementQName());
}
final Element element = marshaller.marshall(object);
element.setAttributeNS(NAMESPACE_URI, "xmlns", SAMLConstants.SAML20_NS);
element.setAttributeNS(NAMESPACE_URI, "xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#");
final TransformerFactory transFactory = TransformerFactory.newInstance();
final Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new DOMSource(element), new StreamResult(writer));
return writer.toString();
} catch (final Exception e) {
throw new IllegalStateException("An error has occurred while marshalling SAML object to xml", e);
}
}
use of org.opensaml.core.xml.io.Marshaller in project spring-security by spring-projects.
the class OpenSamlSigningUtils method serialize.
static String serialize(XMLObject object) {
try {
Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);
Element element = marshaller.marshall(object);
return SerializeSupport.nodeToString(element);
} catch (MarshallingException ex) {
throw new Saml2Exception(ex);
}
}
use of org.opensaml.core.xml.io.Marshaller in project spring-security by spring-projects.
the class OpenSamlSigningUtils method serialize.
static String serialize(XMLObject object) {
try {
Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);
Element element = marshaller.marshall(object);
return SerializeSupport.nodeToString(element);
} catch (MarshallingException ex) {
throw new Saml2Exception(ex);
}
}
Aggregations