/** Constructor. */ protected AbstractXMLObjectMarshaller() { marshallerFactory = Configuration.getMarshallerFactory(); }
/** Constructor. */ protected AbstractXMLObjectMarshaller() { marshallerFactory = Configuration.getMarshallerFactory(); }
/** * This constructor supports checking an XMLObject to be marshalled, either element name or schema type, against a * given namespace/local name pair. * * @deprecated no replacement * * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this * unmarshaller operates on * @param targetLocalName the local name of either the schema type QName or element QName of the elements this * unmarshaller operates on */ protected AbstractXMLObjectMarshaller(String targetNamespaceURI, String targetLocalName) { targetQName = XMLHelper.constructQName(targetNamespaceURI, targetLocalName, null); marshallerFactory = Configuration.getMarshallerFactory(); }
/** * This constructor supports checking an XMLObject to be marshalled, either element name or schema type, against a * given namespace/local name pair. * * @deprecated no replacement * * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this * unmarshaller operates on * @param targetLocalName the local name of either the schema type QName or element QName of the elements this * unmarshaller operates on */ protected AbstractXMLObjectMarshaller(String targetNamespaceURI, String targetLocalName) { targetQName = XMLHelper.constructQName(targetNamespaceURI, targetLocalName, null); marshallerFactory = Configuration.getMarshallerFactory(); }
static String xmlToString(XMLObject aObject) throws IOException { Document doc; try { doc = Configuration.getMarshallerFactory().getMarshaller(aObject).marshall(aObject) .getOwnerDocument(); } catch (MarshallingException e) { throw new IOException(e); } try { Source source = new DOMSource(doc); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (TransformerException e) { throw new IOException(e); } }
/** * Get a KeyInfo marshaller. * * @return a KeyInfo marshaller * @throws SecurityException thrown if there is an error obtaining the marshaller from the configuration */ private Marshaller getMarshaller() throws SecurityException { if (keyInfoMarshaller != null) { return keyInfoMarshaller; } keyInfoMarshaller = Configuration.getMarshallerFactory().getMarshaller(KeyInfo.DEFAULT_ELEMENT_NAME); if (keyInfoMarshaller == null) { throw new SecurityException("Could not obtain KeyInfo marshaller from the configuration"); } return keyInfoMarshaller; }
/** * Get a KeyInfo marshaller. * * @return a KeyInfo marshaller * @throws SecurityException thrown if there is an error obtaining the marshaller from the configuration */ private Marshaller getMarshaller() throws SecurityException { if (keyInfoMarshaller != null) { return keyInfoMarshaller; } keyInfoMarshaller = Configuration.getMarshallerFactory().getMarshaller(KeyInfo.DEFAULT_ELEMENT_NAME); if (keyInfoMarshaller == null) { throw new SecurityException("Could not obtain KeyInfo marshaller from the configuration"); } return keyInfoMarshaller; }
/** * Initialise the SAML library */ public static synchronized void initSamlEngine() { if (!samlEngineInitialized) { if (LOG.isDebugEnabled()) { LOG.debug("Initializing the opensaml2 library..."); } try { OpenSAMLBootstrap.bootstrap(); builderFactory = Configuration.getBuilderFactory(); marshallerFactory = Configuration.getMarshallerFactory(); unmarshallerFactory = Configuration.getUnmarshallerFactory(); samlEngineInitialized = true; if (LOG.isDebugEnabled()) { LOG.debug("opensaml2 library bootstrap complete"); } } catch (ConfigurationException e) { LOG.error( "Unable to bootstrap the opensaml2 library - all SAML operations will fail", e ); } } }
/** * Initialise the SAML library */ public static synchronized void initSamlEngine() { if (!samlEngineInitialized) { if (LOG.isDebugEnabled()) { LOG.debug("Initializing the opensaml2 library..."); } try { OpenSAMLBootstrap.bootstrap(); builderFactory = Configuration.getBuilderFactory(); marshallerFactory = Configuration.getMarshallerFactory(); unmarshallerFactory = Configuration.getUnmarshallerFactory(); samlEngineInitialized = true; if (LOG.isDebugEnabled()) { LOG.debug("opensaml2 library bootstrap complete"); } } catch (ConfigurationException e) { LOG.error( "Unable to bootstrap the opensaml2 library - all SAML operations will fail", e ); } } }
public static Element getElementFromAssertion(XMLObject xmlObj) throws TrustException { try { MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObj); Element assertionElement = marshaller.marshall(xmlObj, ((DOMMetaFactory)OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM)).newDocumentBuilderFactory().newDocumentBuilder().newDocument()); log.debug("DOM element is created successfully from the OpenSAML2 XMLObject"); return assertionElement; } catch (Exception e) { throw new TrustException("Error creating DOM object from the assertion", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
/** * Ensure that the XMLObject is marshalled. * * @param xmlObject the object to check and marshall * @throws EncryptionException thrown if there is an error when marshalling the XMLObject */ protected void checkAndMarshall(XMLObject xmlObject) throws EncryptionException { Element targetElement = xmlObject.getDOM(); if (targetElement == null) { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject); try { targetElement = marshaller.marshall(xmlObject); } catch (MarshallingException e) { log.error("Error marshalling target XMLObject", e); throw new EncryptionException("Error marshalling target XMLObject", e); } } }
/** * Ensure that the XMLObject is marshalled. * * @param xmlObject the object to check and marshall * @throws EncryptionException thrown if there is an error when marshalling the XMLObject */ protected void checkAndMarshall(XMLObject xmlObject) throws EncryptionException { Element targetElement = xmlObject.getDOM(); if (targetElement == null) { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject); try { targetElement = marshaller.marshall(xmlObject); } catch (MarshallingException e) { log.error("Error marshalling target XMLObject", e); throw new EncryptionException("Error marshalling target XMLObject", e); } } }
/** * Creates the request entity that makes up the POST message body. * * @param message message to be sent * @param charset character set used for the message * * @return request entity that makes up the POST message body * * @throws SOAPClientException thrown if the message could not be marshalled */ protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException { try { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message); ByteArrayOutputStream arrayOut = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset); if (log.isDebugEnabled()) { log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message))); } XMLHelper.writeNode(marshaller.marshall(message), writer); return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml"); } catch (MarshallingException e) { throw new SOAPClientException("Unable to marshall SOAP envelope", e); } }
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException { try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString("UTF-8"); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } }
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException { try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString("UTF-8"); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } }
/** * Serializing a SAML2 object into a String. * * @param xmlObject object that needs to serialized. * @return serialized object * @throws SSOAgentException */ public static String marshall(XMLObject xmlObject) throws SSOAgentException { try { MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration .getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString(); } catch (Exception e) { throw new SSOAgentException("Error Serializing the SAML Response", e); } }