/** * Sets the MIME content type of the transport. * * @param transport the transport to set content type on * @param contentType the content type to set */ public static void setContentType(HTTPOutTransport transport, String contentType) { transport.setHeader("Content-Type", contentType); }
/** * <p> * This implementation performs the following actions on the context's {@link HTTPOutTransport}: * <ol> * <li>Adds the HTTP header: "Cache-control: no-cache, no-store"</li> * <li>Adds the HTTP header: "Pragma: no-cache"</li> * <li>Sets the character encoding to: "UTF-8"</li> * <li>Sets the content type to: "text/xml"</li> * <li>Sets the SOAPAction HTTP header</li> * </ol> * </p> * * @param messageContext the current message context being processed * * @throws MessageEncodingException thrown if there is a problem preprocessing the transport */ protected void preprocessTransport(MessageContext messageContext) throws MessageEncodingException { 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"); }
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);
/** {@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); } }
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);
@Override public void sendAuthenticationRequest(SAMLMessageContext context, WebSSOProfileOptions options) throws SAMLException, MetadataProviderException, MessageEncodingException { SPSSODescriptor spDescriptor = (SPSSODescriptor) context.getLocalEntityRoleMetadata(); AssertionConsumerService assertionConsumer = getAssertionConsumerService(options, null, spDescriptor); // The last parameter refers to the IdP that should receive the message. However, // in ECP, we don't know in advance which IdP will be contacted. AuthnRequest authRequest = getAuthnRequest(context, options, assertionConsumer, null); context.setCommunicationProfileId(getProfileIdentifier()); context.setOutboundMessage(getEnvelope()); context.setOutboundSAMLMessage(authRequest); SOAPHelper.addHeaderBlock(context, getPAOSRequest(assertionConsumer)); SOAPHelper.addHeaderBlock(context, getECPRequest(context, options)); sendMessage(context, spDescriptor.isAuthnRequestsSigned(), SAMLConstants.SAML2_PAOS_BINDING_URI); HTTPOutTransport outTransport = (HTTPOutTransport) context.getOutboundMessageTransport(); outTransport.setHeader("Content-Type", "application/vnd.paos+xml"); SAMLMessageStorage messageStorage = context.getMessageStorage(); if (messageStorage != null) { messageStorage.storeMessage(authRequest.getID(), authRequest); } }