@Override public String getBindingURI(final SAML2MessageContext messageContext) { if (messageContext.getSOAP11Context().getEnvelope() != null) { return SAMLConstants.SAML2_SOAP11_BINDING_URI; } else { return SAMLConstants.SAML2_POST_BINDING_URI; } } }
/** * Store the constructed SOAP envelope in the message context for later encoding. * * @param envelope the SOAP envelope */ protected void storeSOAPEnvelope(Envelope envelope) { getMessageContext().getSubcontext(SOAP11Context.class, true).setEnvelope(envelope); }
/** * Get the registered SOAP 1.1 fault, if any. * * @param messageContext the current message context * @return the registered fault, or null */ public static Fault getSOAP11Fault(@Nonnull final MessageContext messageContext) { SOAP11Context soap11Context = getSOAP11Context(messageContext, false); if (soap11Context != null) { return soap11Context.getFault(); } else { return null; } }
/** * Process a successful response, i.e. one where the HTTP response code was 200. * * @param httpResponse the HTTP client response * @param soapContext the SOAP11Context instance * * @throws MessageDecodingException if message can not be unmarshalled * @throws IOException if there is a problem with the response entity input stream */ protected void processSuccessResponse(HttpResponse httpResponse, SOAP11Context soapContext) throws MessageDecodingException, IOException { if (httpResponse.getEntity() == null) { throw new MessageDecodingException("No response body from server"); } Envelope soapMessage = (Envelope) unmarshallMessage(httpResponse.getEntity().getContent()); // Defensive sanity check, otherwise body handler could later fail non-gracefully with runtime exception Fault fault = getFault(soapMessage); if (fault != null) { throw new SOAP11FaultDecodingException(fault); } soapContext.setEnvelope(soapMessage); soapContext.setHTTPResponseStatus(httpResponse.getStatusLine().getStatusCode()); }
@Override protected Event doExecute( final @Nonnull RequestContext springRequestContext, final @Nonnull ProfileRequestContext profileRequestContext) { final MessageContext<SAMLObject> msgContext = new MessageContext<>(); try { msgContext.setMessage(buildSamlResponse(springRequestContext, profileRequestContext)); } catch (final IllegalStateException e) { return ProtocolError.IllegalState.event(this); } final SAMLBindingContext bindingContext = new SAMLBindingContext(); bindingContext.setBindingUri(SAMLConstants.SAML1_SOAP11_BINDING_URI); msgContext.addSubcontext(bindingContext); // Ensure message uses SOAP-ENV ns prefix required by old/broken CAS clients final Envelope envelope = (Envelope) XMLObjectSupport.buildXMLObject(envelopeName); envelope.setBody((Body) XMLObjectSupport.buildXMLObject(bodyName)); final SOAP11Context soapCtx = new SOAP11Context(); soapCtx.setEnvelope(envelope); msgContext.addSubcontext(soapCtx); profileRequestContext.setOutboundMessageContext(msgContext); return ActionSupport.buildProceedEvent(this); }
/** * Get the HTTP response status code to return. * * @return the HTTP response status code */ protected int getHTTPResponseStatusCode() { final Integer contextStatus = getMessageContext().getSubcontext(SOAP11Context.class, true).getHTTPResponseStatus(); if (contextStatus != null) { return contextStatus; } final Envelope envelope = getSOAPEnvelope(); if (envelope != null && envelope.getBody() != null) { final Body body = envelope.getBody(); final List<XMLObject> faults = body.getUnknownXMLObjects(Fault.DEFAULT_ELEMENT_NAME); if (!faults.isEmpty()) { return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } return HttpServletResponse.SC_OK; }
/** {@inheritDoc} */ @Override protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException { final Collection<ChannelBindings> channelBindings = new ArrayList<>(); final List<XMLObject> headers = SOAPMessagingSupport.getHeaderBlock(messageContext, ChannelBindings.DEFAULT_ELEMENT_NAME, null, finalDestination); for (final XMLObject header : headers) { if (header instanceof ChannelBindings) { if (null == ((ActorBearing) header).getSOAP11Actor() || nextDestination) { channelBindings.add((ChannelBindings) header); } } } if (channelBindings.isEmpty()) { log.debug("{} No ChannelBindings header blocks found", getLogPrefix()); } else { log.debug("{} {} ChannelBindings header block(s) found", getLogPrefix(), channelBindings.size()); messageContext.getSubcontext(SOAP11Context.class).getSubcontext(ChannelBindingsContext.class, true).getChannelBindings().addAll(channelBindings); } }
/** * Get the HTTP response status code to return. * * @return the HTTP response status code */ protected int getHTTPResponseStatusCode() { Integer contextStatus = getMessageContext().getSubcontext(SOAP11Context.class, true).getHTTPResponseStatus(); if (contextStatus != null) { return contextStatus; } Envelope envelope = getSOAPEnvelope(); if (envelope != null && envelope.getBody() != null) { Body body = envelope.getBody(); List<XMLObject> faults = body.getUnknownXMLObjects(Fault.DEFAULT_ELEMENT_NAME); if (!faults.isEmpty()) { return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } return HttpServletResponse.SC_OK; }
/** * Add a header block to the SOAP envelope contained within the specified message context's * SOAP subcontext. * * @param messageContext the message context being processed * @param headerBlock the header block to add */ public static void addHeaderBlock(@Nonnull final MessageContext messageContext, @Nonnull final XMLObject headerBlock) { Constraint.isNotNull(messageContext, "Message context cannot be null"); // SOAP 1.1 Envelope final SOAP11Context soap11 = getSOAP11Context(messageContext, false); if (soap11 != null && soap11.getEnvelope() != null) { addSOAP11HeaderBlock(soap11.getEnvelope(), headerBlock); } else { //TODO SOAP 1.2 support when object providers are implemented throw new IllegalArgumentException("Message context did not contain a SOAP Envelope"); } }
/** * Store the constructed SOAP envelope in the message context for later encoding. * * @param envelope the SOAP envelope */ protected void storeSOAPEnvelope(final Envelope envelope) { getMessageContext().getSubcontext(SOAP11Context.class, true).setEnvelope(envelope); }
/** {@inheritDoc} */ @Override protected XMLObject getMessageToLog() { return getMessageContext().getSubcontext(SOAP11Context.class, true).getEnvelope(); }
/** * Store the constructed SOAP envelope in the message context for later encoding. * * @param envelope the SOAP envelope */ protected void storeSOAPEnvelope(Envelope envelope) { getMessageContext().getSubcontext(SOAP11Context.class, true).setEnvelope(envelope); }
/** * Determine the SOAP version of the message represented by the message context. * * @param messageContext the current message context * @return the SOAP version. May be null if the version could not be determined. */ @Nullable public static SOAPVersion getSOAPVersion( @Nonnull final MessageContext<? extends XMLObject> messageContext) { Constraint.isNotNull(messageContext, "Message context cannot be null"); final SOAP11Context soap11 = getSOAP11Context(messageContext, false); // SOAP 1.1 Envelope if (soap11 != null && soap11.getEnvelope() != null) { return SOAP_1_1; } //TODO SOAP 1.2 support when object providers are implemented return null; }
/** * Process a successful, as determined by an HTTP 200 status code, response. * * @param httpResponse the HTTP response * @param context current operation context * * @throws SOAPClientException thrown if there is a problem reading the response from the {@link HttpPost} */ protected void processSuccessfulResponse(@Nonnull final HttpResponse httpResponse, @Nonnull final InOutOperationContext context) throws SOAPClientException { try { if (httpResponse.getEntity() == null) { throw new SOAPClientException("No response body from server"); } final Envelope response = unmarshallResponse(httpResponse.getEntity().getContent()); context.setInboundMessageContext(new MessageContext()); context.getInboundMessageContext().getSubcontext(SOAP11Context.class, true).setEnvelope(response); //TODO: goes away? //evaluateSecurityPolicy(messageContext); } catch (final IOException e) { throw new SOAPClientException("Unable to read response", e); } }
/** * Get a header block from the SOAP envelope contained within the specified message context's * SOAP subcontext. * * @param messageContext the message context being processed * @param headerName the name of the header block to return * @param targetNodes the explicitly specified SOAP node actors (1.1) or roles (1.2) for which the header is desired * @param isFinalDestination true specifies that headers targeted for message final destination should be returned, * false means they should not be returned * * @return the list of matching header blocks */ @Nonnull public static List<XMLObject> getHeaderBlock( @Nonnull final MessageContext messageContext, @Nonnull final QName headerName, @Nullable Set<String> targetNodes, boolean isFinalDestination) { Constraint.isNotNull(messageContext, "Message context cannot be null"); final SOAP11Context soap11 = getSOAP11Context(messageContext, false); // SOAP 1.1 Envelope if (soap11 != null && soap11.getEnvelope() != null) { return getSOAP11HeaderBlock(soap11.getEnvelope(), headerName, targetNodes, isFinalDestination); } //TODO SOAP 1.2 support when object providers are implemented return Collections.emptyList(); }
try { soapMessage = (Envelope) unmarshallMessage(request.getInputStream()); messageContext.getSubcontext(SOAP11Context.class, true).setEnvelope(soapMessage); } catch (IOException e) { log.error("Unable to obtain input stream from HttpServletRequest", e);
/** {@inheritDoc} */ @Override protected XMLObject getMessageToLog() { return getMessageContext().getSubcontext(SOAP11Context.class, true).getEnvelope(); }
try { soapMessage = (Envelope) unmarshallMessage(request.getInputStream()); messageContext.getSubcontext(SOAP11Context.class, true).setEnvelope(soapMessage); } catch (final IOException e) { log.error("Unable to obtain input stream from HttpServletRequest", e);
/** * Retrieve the previously stored SOAP envelope from the message context. * * @return the previously stored SOAP envelope */ protected Envelope getSOAPEnvelope() { return getMessageContext().getSubcontext(SOAP11Context.class, true).getEnvelope(); }
context.getInboundMessageContext().getSubcontext(SOAP11Context.class, true).setEnvelope(response);