List of usage examples for org.w3c.dom.bootstrap DOMImplementationRegistry newInstance
public static DOMImplementationRegistry newInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException, ClassCastException
DOMImplementationRegistry
. From source file:org.wso2.carbon.identity.auth.saml2.common.SAML2AuthUtils.java
public static String marshall(XMLObject xmlObject) { try {/*w ww . j a v a 2 s.c om*/ 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(StandardCharsets.UTF_8.toString()); } catch (InstantiationException | MarshallingException | IllegalAccessException | UnsupportedEncodingException | ClassNotFoundException e) { throw new IdentityRuntimeException("Error marshalling the XML object", e); } }
From source file:org.wso2.carbon.identity.authenticator.saml2.sso.common.Util.java
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object/*from www. j a v a2 s .co m*/ * @throws SAML2SSOUIAuthenticatorException */ public static String marshall(XMLObject xmlObject) throws SAML2SSOUIAuthenticatorException { try { doBootstrap(); 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(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new SAML2SSOUIAuthenticatorException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.authenticator.saml2.sso.ui.Util.java
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object/*from ww w.j av a 2 s . com*/ * @throws org.wso2.carbon.identity.authenticator.saml2.sso.ui.SAML2SSOUIAuthenticatorException */ public static String marshall(XMLObject xmlObject) throws SAML2SSOUIAuthenticatorException { try { doBootstrap(); 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(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new SAML2SSOUIAuthenticatorException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.entitlement.pep.agent.wsxacml.WSXACMLEntitlementServiceClient.java
/** * Serialize XML objects//from w ww .j a va 2s. co m * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects */ private String marshall(XMLObject xmlObject) throws EntitlementAgentException { try { doBootstrap(); 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(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new EntitlementAgentException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.entitlement.proxy.wsxacml.WSXACMLEntitlementServiceClient.java
/** * Serialize XML objects//from w w w . ja v a 2 s . c o m * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects */ private String marshall(XMLObject xmlObject) throws EntitlementProxyException { try { doBootstrap(); System.setProperty(DOCUMENT_BUILDER_FACTORY, DOCUMENT_BUILDER_FACTORY_IMPL); 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 new String(byteArrayOutputStrm.toByteArray(), Charset.forName("UTF-8")); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new EntitlementProxyException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.entitlement.wsxacml.WSXACMLMessageReceiver.java
/** * `// ww w. j a v a 2 s .c om * Serialize XML objects * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects * @throws EntitlementException */ private String marshall(XMLObject xmlObject) throws EntitlementException { try { doBootstrap(); 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 byteArrayOutputStream = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStream); writer.write(element, output); return byteArrayOutputStream.toString(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new EntitlementException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.query.saml.util.SAMLQueryRequestUtil.java
/** * This method is used to serialize response message * * @param xmlObject well formed XML object * @return String serialized response//from ww w . j a va2 s . c o m * @throws IdentitySAML2QueryException If unable to marshall response */ public static String marshall(XMLObject xmlObject) throws IdentitySAML2QueryException { ByteArrayOutputStream byteArrayOutputStrm = null; try { doBootstrap(); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = XMLObjectProviderRegistrySupport.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); 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(SAMLQueryRequestConstants.GenericConstants.UTF8_ENC); } catch (IdentityException e) { log.error("Error de-serializing the SAML Response", e); throw new IdentitySAML2QueryException("Error de-serializing the SAML Response"); } catch (UnsupportedEncodingException e) { log.error("XML message contain invalid Encoding", e); throw new IdentitySAML2QueryException("XML message contain invalid Encoding"); } catch (MarshallingException e) { log.error("Unable to marshall", e); throw new IdentitySAML2QueryException("Unable to marshall"); } catch (IllegalAccessException e) { log.error("Illegal Access", e); throw new IdentitySAML2QueryException("Illegal Access"); } catch (InstantiationException e) { log.error("Unable to initialize", e); throw new IdentitySAML2QueryException("Unable to initialize"); } catch (ClassNotFoundException e) { log.error("Class not found", e); throw new IdentitySAML2QueryException("Class not found"); } catch (NullPointerException e) { log.error("Marshall throw null pointer exception", e); throw new IdentitySAML2QueryException("Marshall throw null pointer exception"); } finally { if (byteArrayOutputStrm != null) { try { byteArrayOutputStrm.close(); } catch (IOException e) { log.error("Error while closing the stream", e); } } } }
From source file:org.wso2.carbon.identity.saml.inbound.util.SAMLSSOUtil.java
/** * Serialize the Auth. Request/* w w w . ja va 2 s.com*/ * * @param xmlObject * @return serialized auth. req */ public static String marshall(XMLObject xmlObject) throws IdentityException { ByteArrayOutputStream byteArrayOutputStrm = null; try { doBootstrap(); // 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); 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(StandardCharsets.UTF_8.name()); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } finally { if (byteArrayOutputStrm != null) { try { byteArrayOutputStrm.close(); } catch (IOException e) { log.error("Error while closing the stream", e); } } } }
From source file:org.wso2.carbon.identity.sso.agent.saml.SAML2SSOManager.java
/** * Serialize the Auth. Request/* w ww . ja v a 2 s .com*/ * * @param xmlObject * @return serialized auth. req */ protected String marshall(XMLObject xmlObject) throws SSOAgentException { 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 new String(byteArrayOutputStrm.toByteArray(), Charset.forName("UTF-8")); } catch (ClassNotFoundException e) { throw new SSOAgentException("Error in marshalling SAML2 Assertion", e); } catch (InstantiationException e) { throw new SSOAgentException("Error in marshalling SAML2 Assertion", e); } catch (MarshallingException e) { throw new SSOAgentException("Error in marshalling SAML2 Assertion", e); } catch (IllegalAccessException e) { throw new SSOAgentException("Error in marshalling SAML2 Assertion", e); } }
From source file:org.wso2.carbon.identity.sso.saml.cloud.util.SAMLSSOUtil.java
/** * Serialize the Auth. Request/*from w w w.j av a2 s . c o m*/ * * @param xmlObject * @return serialized auth. req */ public static String marshall(XMLObject xmlObject) throws IdentityException { ByteArrayOutputStream byteArrayOutputStrm = null; try { doBootstrap(); 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); 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(StandardCharsets.UTF_8.name()); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } finally { if (byteArrayOutputStrm != null) { try { byteArrayOutputStrm.close(); } catch (IOException e) { log.error("Error while closing the stream", e); } } } }