public static String encodeSAMLRequest(XMLObject authnRequest) throws MarshallingException, IOException { Marshaller marshaller = Configuration.getMarshallerFactory() .getMarshaller(authnRequest); Element authDOM = marshaller.marshall(authnRequest); StringWriter requestWriter = new StringWriter(); XMLHelper.writeNode(authDOM, requestWriter); String requestMessage = requestWriter.toString(); Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8"))); deflaterOutputStream.close(); String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim(); return encodedRequestMessage; }
/** * Writes a Node out to an OutputStream using the DOM, level 3, Load/Save serializer. The written content * is encoded using the encoding specified in the output stream configuration. * * @param node the node to write out * @param output the output stream to write the XML to */ public static void writeNode(Node node, OutputStream output) { writeNode(node, output, null); }
/** * Writes a Node out to an OutputStream using the DOM, level 3, Load/Save serializer. The written content * is encoded using the encoding specified in the output stream configuration. * * @param node the node to write out * @param output the output stream to write the XML to */ public static void writeNode(Node node, OutputStream output) { writeNode(node, output, null); }
/** * Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. The written content is encoded using * the encoding specified in the writer configuration. * * @param node the node to write out * @param output the writer to write the XML to */ public static void writeNode(Node node, Writer output) { writeNode(node, output, null); }
/** * Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. The written content is encoded using * the encoding specified in the writer configuration. * * @param node the node to write out * @param output the writer to write the XML to */ public static void writeNode(Node node, Writer output) { writeNode(node, output, null); }
/** * Converts a Node into a String using the DOM, level 3, Load/Save serializer. * * @param node the node to be written to a string * * @return the string representation of the node */ public static String nodeToString(Node node) { StringWriter writer = new StringWriter(); writeNode(node, writer); return writer.toString(); }
/** * Converts a Node into a String using the DOM, level 3, Load/Save serializer. * * @param node the node to be written to a string * * @return the string representation of the node */ public static String nodeToString(Node node) { StringWriter writer = new StringWriter(); writeNode(node, writer); return writer.toString(); }
/** * Marshall an XMLObject to an OutputStream. * * @param xmlObject the XMLObject to marshall * @param outputStream the OutputStream to which to marshall * @throws MarshallingException if there is a problem marshalling the object */ public static void marshallToOutputStream(XMLObject xmlObject, OutputStream outputStream) throws MarshallingException { Element element = marshall(xmlObject); XMLHelper.writeNode(element, outputStream); }
/** * Marshall an XMLObject to a Writer. * * @param xmlObject the XMLObject to marshall * @param writer the Writer to which to marshall * @throws MarshallingException if there is a problem marshalling the object */ public static void marshallToWriter(XMLObject xmlObject, Writer writer) throws MarshallingException { Element element = marshall(xmlObject); XMLHelper.writeNode(element, writer); }
/** * Pretty prints the XML node. * * @param node xml node to print * * @return pretty-printed xml */ public static String prettyPrintXML(Node node) { StringWriter writer = new StringWriter(); writeNode(node, writer, getPrettyPrintParams()); return writer.toString(); }
/** * Marshall an XMLObject to a Writer. * * @param xmlObject the XMLObject to marshall * @param writer the Writer to which to marshall * @throws MarshallingException if there is a problem marshalling the object */ public static void marshallToWriter(XMLObject xmlObject, Writer writer) throws MarshallingException { Element element = marshall(xmlObject); XMLHelper.writeNode(element, writer); }
/** * Pretty prints the XML node. * * @param node xml node to print * * @return pretty-printed xml */ public static String prettyPrintXML(Node node) { StringWriter writer = new StringWriter(); writeNode(node, writer, getPrettyPrintParams()); return writer.toString(); }
/** * Marshall an XMLObject to an OutputStream. * * @param xmlObject the XMLObject to marshall * @param outputStream the OutputStream to which to marshall * @throws MarshallingException if there is a problem marshalling the object */ public static void marshallToOutputStream(XMLObject xmlObject, OutputStream outputStream) throws MarshallingException { Element element = marshall(xmlObject); XMLHelper.writeNode(element, outputStream); }
authDOM = marshaller.marshall(requestMessage); StringWriter rspWrt = new StringWriter(); XMLHelper.writeNode(authDOM, rspWrt); if (SAMLConstants.SAML2_REDIRECT_BINDING_URI.equals(binding)) {
/** {@inheritDoc} */ protected void encodeToTransport(MessageContext messageContext) throws MessageEncodingException { Element envelopeElem = marshallMessage(messageContext.getOutboundMessage()); preprocessTransport(messageContext); try { OutTransport outTransport = messageContext.getOutboundMessageTransport(); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); XMLHelper.writeNode(envelopeElem, out); out.flush(); } catch (UnsupportedEncodingException e) { log.error("JVM does not support required UTF-8 encoding"); throw new MessageEncodingException("JVM does not support required UTF-8 encoding"); } catch (IOException e) { log.error("Unable to write message content to outbound stream", e); throw new MessageEncodingException("Unable to write message content to outbound stream", 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); } }
/** * Encode the message context to the transport. * * @param messageContext the message context to process * @throws MessageEncodingException thrown if there is a problem encoding the message context * to the transport */ protected void encodeToTransport(MessageContext messageContext) throws MessageEncodingException { Element envelopeElem = marshallMessage(messageContext.getOutboundMessage()); preprocessTransport(messageContext); try { OutTransport outTransport = messageContext.getOutboundMessageTransport(); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); XMLHelper.writeNode(envelopeElem, out); out.flush(); } catch (UnsupportedEncodingException e) { log.error("JVM does not support required UTF-8 encoding"); throw new MessageEncodingException("JVM does not support required UTF-8 encoding"); } catch (IOException e) { log.error("Unable to write message content to outbound stream", e); throw new MessageEncodingException("Unable to write message content to outbound stream", e); } }
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(request); Element dom = marshaller.marshall(request); XMLHelper.writeNode(dom, stringWriter); } catch (MarshallingException ex) { throw new SamlException("Error while marshalling SAML request to XML", ex);
outTransport.setHeader("SOAPAction", "http://www.oasis-open.org/committees/security"); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); XMLHelper.writeNode(envelopeElem, out); out.flush(); } catch (UnsupportedEncodingException e) {
/** {@inheritDoc} */ protected void doEncode(MessageContext messageContext) throws MessageEncodingException { validateMessageContent(messageContext); SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext; SAMLObject samlMessage = samlMsgCtx.getOutboundSAMLMessage(); if (samlMessage == null) { throw new MessageEncodingException("No outbound SAML message contained in message context"); } signMessage(samlMsgCtx); Envelope envelope = buildSOAPMessage(samlMsgCtx, samlMessage); Element envelopeElem = marshallMessage(envelope); try { HTTPOutTransport outTransport = (HTTPOutTransport) messageContext.getOutboundMessageTransport(); HTTPTransportUtils.addNoCacheHeaders(outTransport); HTTPTransportUtils.setUTF8Encoding(outTransport); HTTPTransportUtils.setContentType(outTransport, "text/xml"); outTransport.setHeader("SOAPAction", "http://www.oasis-open.org/committees/security"); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); XMLHelper.writeNode(envelopeElem, out); out.flush(); } catch (UnsupportedEncodingException e) { log.error("JVM does not support required UTF-8 encoding"); throw new MessageEncodingException("JVM does not support required UTF-8 encoding"); } catch (IOException e) { log.error("Unable to write message content to outbound stream", e); throw new MessageEncodingException("Unable to write message content to outbound stream", e); } }