public static Envelope createSoapMessage(SignableSAMLObject signableSAMLObject) { Body body = soapBodyBuilder.buildObject(); body.getUnknownXMLObjects().add(signableSAMLObject); Envelope envelope = soapEnvelopeBuilder.buildObject(); envelope.setBody(body); Header header = soapHeaderBuilder.buildObject(); envelope.setHeader(header); return envelope; }
/** * Builds the SOAP message to be encoded. * * @param payload body of the SOAP message */ protected void buildAndStoreSOAPMessage(@Nonnull final XMLObject payload) { Envelope envelope = getSOAPEnvelope(); if (envelope == null) { envelope = envBuilder.buildObject(); storeSOAPEnvelope(envelope); } Body body = envelope.getBody(); if (body == null) { body = bodyBuilder.buildObject(); envelope.setBody(body); } if (!body.getUnknownXMLObjects().isEmpty()) { log.warn("Existing SOAP Envelope Body already contained children"); } body.getUnknownXMLObjects().add(payload); }
/** * Add a header to the SOAP 1.1 Envelope. * * @param envelope the SOAP 1.1 envelope to process * @param headerBlock the header to add */ public static void addSOAP11HeaderBlock(@Nonnull final Envelope envelope, @Nonnull final XMLObject headerBlock) { Constraint.isNotNull(envelope, "Envelope cannot be null"); Constraint.isNotNull(headerBlock, "Header block cannot be null"); Header envelopeHeader = envelope.getHeader(); if (envelopeHeader == null) { envelopeHeader = (Header) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder( Header.DEFAULT_ELEMENT_NAME).buildObject(Header.DEFAULT_ELEMENT_NAME); envelope.setHeader(envelopeHeader); } envelopeHeader.getUnknownXMLObjects().add(headerBlock); }
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject) throws UnmarshallingException { Envelope envelope = (Envelope) parentXMLObject; if (childXMLObject instanceof Header) { envelope.setHeader((Header) childXMLObject); } else if (childXMLObject instanceof Body) { envelope.setBody((Body) childXMLObject); } else { envelope.getUnknownXMLObjects().add(childXMLObject); } }
/** * Return the Fault element from the SOAP message, if any. * * @param soapMessage the SOAP 1.1. Envelope being processed * @return the first Fault element found, or null */ protected Fault getFault(Envelope soapMessage) { if (soapMessage.getBody() != null) { List<XMLObject> faults = soapMessage.getBody().getUnknownXMLObjects(Fault.DEFAULT_ELEMENT_NAME); if (!faults.isEmpty()) { return (Fault) faults.get(0); } else { return null; } } else { return null; } }
@Override protected void buildAndStoreSOAPMessage(final XMLObject payload) { final XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory(); final SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME); final Envelope envelope = envBuilder.buildObject( SOAPConstants.SOAP11_NS, Envelope.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX); final SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME); final Body body = bodyBuilder.buildObject( SOAPConstants.SOAP11_NS, Body.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX); if(!body.getUnknownXMLObjects().isEmpty()) { LOGGER.warn("Existing SOAP Envelope Body already contained children"); } body.getUnknownXMLObjects().add(payload); envelope.setBody(body); this.storeSOAPEnvelope(envelope); }
/** * Extracts the {@link UsernameToken} from the given {@link Envelope}. * * @param message the message from which the token should be extracted * * @return the extracted token */ @Nullable private UsernameToken getUsernameToken(@Nonnull final Envelope message) { final Header header = message.getHeader(); final List<XMLObject> securityHeaders = header.getUnknownXMLObjects(Security.ELEMENT_NAME); if (securityHeaders == null || securityHeaders.size() == 0) { log.debug("{} Inbound message does not contain <Security>", getLogPrefix()); return null; } final List<XMLObject> usernameTokens = ((Security) securityHeaders.get(0)).getUnknownXMLObjects(UsernameToken.ELEMENT_NAME); if (usernameTokens == null || usernameTokens.size() == 0) { log.debug("{} Inbound message security header does not contain <UsernameToken>", getLogPrefix()); return null; } return (UsernameToken) usernameTokens.get(0); } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException { Envelope envelope = (Envelope) xmlObject; QName attribQName = QNameSupport.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute .getPrefix()); if (attribute.isId()) { envelope.getUnknownAttributes().registerID(attribQName); } envelope.getUnknownAttributes().put(attribQName, attribute.getValue()); }
/** {@inheritDoc} */ protected void doInvoke(MessageContext messageContext) throws MessageHandlerException { Envelope env = (Envelope) messageContext.getSubcontext(SOAP11Context.class).getEnvelope(); List<XMLObject> bodyChildren = env.getBody().getUnknownXMLObjects(); if (bodyChildren == null || bodyChildren.isEmpty()) { throw new MessageHandlerException("SOAP Envelope Body contained no children"); } else if (bodyChildren.size() > 1) { log.warn("SOAP Envelope Body contained more than one child. Returning the first as the message"); } messageContext.setMessage(env.getBody().getUnknownXMLObjects().get(0)); }
val envelope = envelopeBuilder.buildObject(); val body = bodyBuilder.buildObject(); envelope.setBody(body); body.getUnknownXMLObjects().add(samlLogoutRequest);
/** * Determine the value of the SOAPAction HTTP header to send. * * <p> * The default behavior is to return the value of the SOAP Envelope's WS-Addressing Action header, * if present. * </p> * * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction() { final Envelope env = getSOAPEnvelope(); final Header header = env.getHeader(); if (header == null) { return null; } final List<XMLObject> objList = header.getUnknownXMLObjects(Action.ELEMENT_NAME); if (objList == null || objList.isEmpty()) { return null; } else { return ((Action)objList.get(0)).getValue(); } }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { Envelope envelope = (Envelope) xmlObject; Attr attribute; for (Entry<QName, String> entry : envelope.getUnknownAttributes().entrySet()) { attribute = AttributeSupport.constructAttribute(domElement.getOwnerDocument(), entry.getKey()); attribute.setValue(entry.getValue()); domElement.setAttributeNodeNS(attribute); if (XMLObjectProviderRegistrySupport.isIDAttribute(entry.getKey()) || envelope.getUnknownAttributes().isIDAttribute(entry.getKey())) { attribute.getOwnerElement().setIdAttributeNode(attribute, true); } } }
@Override public Envelope build(final RequestAbstractType authnRequest, final HttpServletRequest request, final HttpServletResponse response, final Object casAssertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String binding, final MessageContext messageContext) throws SamlException { val header = newSoapObject(Header.class); val body = newSoapObject(Body.class); val query = (AttributeQuery) authnRequest; val saml2Response = buildSaml2Response(casAssertion, query, service, adaptor, request, SAMLConstants.SAML2_POST_BINDING_URI, messageContext); body.getUnknownXMLObjects().add(saml2Response); val envelope = newSoapObject(Envelope.class); envelope.setHeader(header); envelope.setBody(body); SamlUtils.logSamlObject(this.configBean, envelope); return encodeFinalResponse(request, response, service, adaptor, envelope, binding, authnRequest, casAssertion); } }
/** * Builds the SOAP message to be encoded. * * @param payload body of the SOAP message */ protected void buildAndStoreSOAPMessage(@Nonnull final XMLObject payload) { Envelope envelope = getSOAPEnvelope(); if (envelope == null) { envelope = envBuilder.buildObject(); storeSOAPEnvelope(envelope); } Body body = envelope.getBody(); if (body == null) { body = bodyBuilder.buildObject(); envelope.setBody(body); } if (!body.getUnknownXMLObjects().isEmpty()) { log.warn("Existing SOAP Envelope Body already contained children"); } body.getUnknownXMLObjects().add(payload); }
private String[] getPrincipalIdFromSamlEcpResponse(final Envelope envelope) { val objects = envelope.getBody().getUnknownXMLObjects(); if (objects.isEmpty()) { return ArrayUtils.EMPTY_STRING_ARRAY; } val object = objects.get(0); if (object instanceof Response) { return getPrincipalIdFromSamlResponse((Response) object); } if (object instanceof Fault) { return getPrincipalIdFromSamlEcpFault((Fault) object); } return ArrayUtils.EMPTY_STRING_ARRAY; }
@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); }
/** * Determine the value of the SOAPAction HTTP header to send. * * <p> * The default behavior is to return the value of the SOAP Envelope's WS-Addressing Action header, * if present. * </p> * * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction() { Envelope env = getSOAPEnvelope(); Header header = env.getHeader(); if (header == null) { return null; } List<XMLObject> objList = header.getUnknownXMLObjects(Action.ELEMENT_NAME); if (objList == null || objList.isEmpty()) { return null; } else { return ((Action)objList.get(0)).getValue(); } }
/** * Builds the SOAP message to be encoded. * * @param payload body of the SOAP message */ protected void buildAndStoreSOAPMessage(@Nonnull final XMLObject payload) { Envelope envelope = getSOAPEnvelope(); if (envelope == null) { envelope = envBuilder.buildObject(); storeSOAPEnvelope(envelope); } Body body = envelope.getBody(); if (body == null) { body = bodyBuilder.buildObject(); envelope.setBody(body); } if (!body.getUnknownXMLObjects().isEmpty()) { log.warn("Existing SOAP Envelope Body already contained children"); } body.getUnknownXMLObjects().add(payload); }
/** * 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; }