/** * Find the raw query string parameter indicated and append it to the string builder. * * The appended value will be in the form 'paramName=paramValue' (minus the quotes). * * @param builder string builder to which to append the parameter * @param queryString the URL query string containing parameters * @param paramName the name of the parameter to append * @return true if parameter was found, false otherwise */ private boolean appendParameter(StringBuilder builder, String queryString, String paramName) { String rawParam = HTTPTransportUtils.getRawQueryStringParameter(queryString, paramName); if (rawParam == null) { return false; } if (builder.length() > 0) { builder.append('&'); } builder.append(rawParam); return true; } }
/** * <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"); }
/** {@inheritDoc} */ protected void doEncode(MessageContext messageContext) throws MessageEncodingException { if (!(messageContext instanceof SAMLMessageContext)) { log.error("Invalid message context type, this encoder only support SAMLMessageContext"); throw new MessageEncodingException( "Invalid message context type, this encoder only support SAMLMessageContext"); } if (!(messageContext.getOutboundMessageTransport() instanceof HTTPOutTransport)) { log.error("Invalid outbound message transport type, this encoder only support HTTPOutTransport"); throw new MessageEncodingException( "Invalid outbound message transport type, this encoder only support HTTPOutTransport"); } SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext; String endpointURL = getEndpointURL(samlMsgCtx).buildURL(); setResponseDestination(samlMsgCtx.getOutboundSAMLMessage(), endpointURL); removeSignature(samlMsgCtx); String encodedMessage = deflateAndBase64Encode(samlMsgCtx.getOutboundSAMLMessage()); String redirectURL = buildRedirectURL(samlMsgCtx, endpointURL, encodedMessage); HTTPOutTransport out = (HTTPOutTransport) messageContext.getOutboundMessageTransport(); HTTPTransportUtils.addNoCacheHeaders(out); HTTPTransportUtils.setUTF8Encoding(out); out.sendRedirect(redirectURL); }
if (userInfo.contains(":")) { String[] userInfoComps = userInfo.split(":"); setUsername(HTTPTransportUtils.urlDecode(userInfoComps[0])); setPassword(HTTPTransportUtils.urlDecode(userInfoComps[1])); } else { setUsername(userInfo); queryComp = queryComps[i]; if (!queryComp.contains("=")) { paramName = HTTPTransportUtils.urlDecode(queryComp); queryParams.add(new Pair<String, String>(paramName, null)); } else { paramComps = queryComp.split("="); paramName = HTTPTransportUtils.urlDecode(paramComps[0]); paramValue = HTTPTransportUtils.urlDecode(paramComps[1]); queryParams.add(new Pair<String, String>(paramName, paramValue));
if (!SigningUtil.verifyWithURI(cred, getAlgorithmURIFromID(HTTPTransportUtils.urlDecode(samlSig)), DatatypeConverter.parseBase64Binary(HTTPTransportUtils.urlDecode(samlSigature)), sb.toString().getBytes("UTF-8"))) { throw new SAMLException("!SigningUtil.verifyWithURI"); decoded = inflate(DatatypeConverter.parseBase64Binary(HTTPTransportUtils.urlDecode(samlTicket))); } catch (IOException ex) { throw new SAMLException(ex);
/** * Base64 and POST encodes the outbound message and writes it to the outbound transport. * * @param messageContext current message context * @param endpointURL endpoint URL to which to encode message * * @throws MessageEncodingException thrown if there is a problem encoding the message */ protected void postEncode(SAMLMessageContext messageContext, String endpointURL) throws MessageEncodingException { log.debug("Invoking Velocity template to create POST body"); try { VelocityContext context = new VelocityContext(); populateVelocityContext(context, messageContext, endpointURL); HTTPOutTransport outTransport = (HTTPOutTransport) messageContext.getOutboundMessageTransport(); HTTPTransportUtils.addNoCacheHeaders(outTransport); HTTPTransportUtils.setUTF8Encoding(outTransport); HTTPTransportUtils.setContentType(outTransport, "text/html"); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); velocityEngine.mergeTemplate(velocityTemplateId, "UTF-8", context, out); out.flush(); } catch (Exception e) { log.error("Error invoking Velocity template", e); throw new MessageEncodingException("Error creating output document", e); } }
/** * Find the raw query string parameter indicated and append it to the string * builder. * <p/> * The appended value will be in the form 'paramName=paramValue' (minus the * quotes). * * @param builder string builder to which to append the parameter * @param queryString the URL query string containing parameters * @param paramName the name of the parameter to append * @return true if parameter was found, false otherwise */ private static boolean appendParameter(StringBuilder builder, String queryString, String paramName) { String rawParam = HTTPTransportUtils.getRawQueryStringParameter(queryString, paramName); if (rawParam == null) { return false; } if (builder.length() > 0) { builder.append('&'); } builder.append(rawParam); return true; }
HTTPTransportUtils.addNoCacheHeaders(outTransport); HTTPTransportUtils.setUTF8Encoding(outTransport); HTTPTransportUtils.setContentType(outTransport, "text/xml");
/** * Find the raw query string parameter indicated and append it to the string * builder. * <p/> * The appended value will be in the form 'paramName=paramValue' (minus the * quotes). * * @param builder * string builder to which to append the parameter * @param queryString * the URL query string containing parameters * @param paramName * the name of the parameter to append * @return true if parameter was found, false otherwise */ private static boolean appendParameter(StringBuilder builder, String queryString, String paramName) { String rawParam = HTTPTransportUtils.getRawQueryStringParameter(queryString, paramName); if (rawParam == null) { return false; } if (builder.length() > 0) { builder.append('&'); } builder.append(rawParam); return true; }
HTTPTransportUtils.addNoCacheHeaders(outTransport); HTTPTransportUtils.setUTF8Encoding(outTransport); HTTPTransportUtils.setContentType(outTransport, "text/html");
/** * Find the raw query string parameter indicated and append it to the string * builder. * <p/> * The appended value will be in the form 'paramName=paramValue' (minus the * quotes). * * @param builder string builder to which to append the parameter * @param queryString the URL query string containing parameters * @param paramName the name of the parameter to append * @return true if parameter was found, false otherwise */ private static boolean appendParameter(StringBuilder builder, String queryString, String paramName) { String rawParam = HTTPTransportUtils.getRawQueryStringParameter(queryString, paramName); if (rawParam == null) { return false; } if (builder.length() > 0) { builder.append('&'); } builder.append(rawParam); return true; }
/** {@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); } }
/** * @param queryString * @return * @throws SecurityPolicyException * @throws IdentitySAML2SSOException */ private static String getSigAlg(String queryString) throws SecurityPolicyException { String sigAlgQueryParam = HTTPTransportUtils.getRawQueryStringParameter(queryString, "SigAlg"); if (DatatypeHelper.isEmpty(sigAlgQueryParam)) { throw new SecurityPolicyException( "Could not extract Signature Algorithm from query string"); } String sigAlg = null; try { /* Split 'SigAlg=<sigalg_value>' query param using '=' as the delimiter, and get the Signature Algorithm */ sigAlg = URLDecoder.decode(sigAlgQueryParam.split("=")[1], "UTF-8"); } catch (UnsupportedEncodingException e) { if (log.isDebugEnabled()) { log.debug("Encoding not supported.", e); } // JVM is required to support UTF-8 return null; } return sigAlg; }
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");
String signatureQueryParam = HTTPTransportUtils.getRawQueryStringParameter(queryString, "Signature"); if (DatatypeHelper.isEmpty(signatureQueryParam)) { throw new SecurityPolicyException("Could not extract the Signature from query string");
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");