org.opensaml.ws.soap.soap11.Envelope Java Examples

The following examples show how to use org.opensaml.ws.soap.soap11.Envelope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpSOAPClient.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void send(String endpoint, SOAPMessageContext messageContext) throws SOAPException, SecurityException {
    PostMethod post = null;
    try {
        post = createPostMethod(endpoint, (HttpSOAPRequestParameters) messageContext.getSOAPRequestParameters(),
                (Envelope) messageContext.getOutboundMessage());

        int result = httpClient.executeMethod(post);
        log.debug("Received HTTP status code of {} when POSTing SOAP message to {}", result, endpoint);

        if (result == HttpStatus.SC_OK) {
            processSuccessfulResponse(post, messageContext);
        } else if (result == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            processFaultResponse(post, messageContext);
        } else {
            throw new SOAPClientException("Received " + result + " HTTP response status code from HTTP request to "
                    + endpoint);
        }
    } catch (IOException e) {
        throw new SOAPClientException("Unable to send request to " + endpoint, e);
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}
 
Example #2
Source File: CasHTTPSOAP11Encoder.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Override
protected Envelope buildSOAPMessage(final SAMLObject samlMessage) {
    final XMLObjectBuilderFactory builderFactory = Configuration.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);

    body.getUnknownXMLObjects().add(samlMessage);
    envelope.setBody(body);

    return envelope;
}
 
Example #3
Source File: SOAP11Decoder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that all headers which carry the <code>soap11:mustUnderstand</code> attribute
 * and which are targeted to this SOAP node via the <code>soap11:actor</code> were understood by the
 * decoder.
 * 
 * @param messageContext the message context being processed
 * 
 * @throws MessageDecodingException thrown if a SOAP header requires understanding by 
 *              this node but was not understood
 */
private void checkUnderstoodSOAPHeaders(MessageContext messageContext)
        throws MessageDecodingException {
    
    Envelope envelope = (Envelope) messageContext.getInboundMessage();
    Header soapHeader = envelope.getHeader();
    if (soapHeader == null) {
        log.debug("SOAP Envelope contained no Header");
        return;
    }
    List<XMLObject> headers = soapHeader.getUnknownXMLObjects();
    if (headers == null || headers.isEmpty()) {
        log.debug("SOAP Envelope header list was either null or empty");
        return;
    }

    for (XMLObject header : headers) {
        //TODO
    }
}
 
Example #4
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a header block from the SOAP envelope contained within the specified message context's
 * {@link MessageContext#getInboundMessage()}.
 * 
 * @param msgContext 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
 */
public static List<XMLObject> getInboundHeaderBlock(MessageContext msgContext, QName headerName,
        Set<String> targetNodes, boolean isFinalDestination) {
    XMLObject inboundEnvelope = msgContext.getInboundMessage();
    if (inboundEnvelope == null) {
        throw new IllegalArgumentException("Message context does not contain an inbound SOAP envelope");
    }
    
    // SOAP 1.1 Envelope
    if (inboundEnvelope instanceof Envelope) {
        return getSOAP11HeaderBlock((Envelope) inboundEnvelope, headerName, targetNodes, isFinalDestination);
    }
    
    //TODO SOAP 1.2 support when object providers are implemented
    return Collections.emptyList();
}
 
Example #5
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a header block from the SOAP envelope contained within the specified message context's
 * {@link MessageContext#getOutboundMessage()}.
 * 
 * @param msgContext 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 specifies they should not be returned
 * @return the list of matching header blocks
 */
public static List<XMLObject> getOutboundHeaderBlock(MessageContext msgContext, QName headerName,
        Set<String> targetNodes, boolean isFinalDestination) {
    XMLObject outboundEnvelope = msgContext.getOutboundMessage();
    if (outboundEnvelope == null) {
        throw new IllegalArgumentException("Message context does not contain an outbound SOAP envelope");
    }
    
    // SOAP 1.1 Envelope
    if (outboundEnvelope instanceof Envelope) {
        return getSOAP11HeaderBlock((Envelope) outboundEnvelope, headerName, targetNodes, isFinalDestination);
    }
    
    //TODO SOAP 1.2 support when object providers are implemented
    return Collections.emptyList();
}
 
Example #6
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a header block from the SOAP 1.1 envelope.
 * 
 * @param envelope the SOAP 1.1 envelope to process 
 * @param headerName the name of the header block to return 
 * @param targetNodes the explicitly specified SOAP node actors for which the header is desired
 * @param isFinalDestination true specifies that headers targeted for message final destination should be returned,
 *          false specifies they should not be returned
 * @return the list of matching header blocks
 */
public static List<XMLObject> getSOAP11HeaderBlock(Envelope envelope, QName headerName, Set<String> targetNodes,
        boolean isFinalDestination) {
    Header envelopeHeader = envelope.getHeader();
    if (envelopeHeader == null) {
        return Collections.emptyList();
    }
    ArrayList<XMLObject> headers = new ArrayList<XMLObject>();
    for (XMLObject header : envelopeHeader.getUnknownXMLObjects(headerName)) {
        if (isSOAP11HeaderTargetedToNode(header, targetNodes, isFinalDestination)) {
            headers.add(header);
        }
    }
    
    return headers;
}
 
Example #7
Source File: HTTPSOAP11Encoder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds the SOAP message to be encoded.
 * 
 * @param samlMessage body of the SOAP message
 * 
 * @return the SOAP message
 */
@SuppressWarnings("unchecked")
protected Envelope buildSOAPMessage(SAMLObject samlMessage) {
    log.debug("Building SOAP message");
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();

    SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory
            .getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    Envelope envelope = envBuilder.buildObject();

    log.debug("Adding SAML message to the SOAP message's body");
    SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory
            .getBuilder(Body.DEFAULT_ELEMENT_NAME);
    Body body = bodyBuilder.buildObject();
    body.getUnknownXMLObjects().add(samlMessage);
    envelope.setBody(body);

    return envelope;
}
 
Example #8
Source File: HTTPSOAP11Encoder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds the SOAP message to be encoded.
 * 
 * @param samlMessage body of the SOAP message
 * 
 * @return the SOAP message
 */
@SuppressWarnings("unchecked")
protected Envelope buildSOAPMessage(SAMLObject samlMessage) {
    if (log.isDebugEnabled()) {
        log.debug("Building SOAP message");
    }
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();

    SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory
            .getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    Envelope envelope = envBuilder.buildObject();

    if (log.isDebugEnabled()) {
        log.debug("Adding SAML message to the SOAP message's body");
    }
    SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory
            .getBuilder(Body.DEFAULT_ELEMENT_NAME);
    Body body = bodyBuilder.buildObject();
    body.getUnknownXMLObjects().add(samlMessage);
    envelope.setBody(body);

    return envelope;
}
 
Example #9
Source File: HandlerChainAwareHTTPSOAP11Encoder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Perform final binding-specific processing of message context and prepare it for encoding
 * to the transport.  
 * 
 * <p>
 * This should include constructing and populating all binding-specific structure and data that needs to be
 * reflected by the message context's properties.
 * </p>
 * 
 * <p>
 * This method is called prior to {@link #processOutboundHandlerChain(MessageContext)}.
 * </p>
 * 
 * @param messageContext the message context to process
 * @throws MessageEncodingException thrown if there is a problem preparing the message context
 *              for encoding
 */
protected void prepareMessageContext(MessageContext messageContext) throws MessageEncodingException {
    SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;

    SAMLObject samlMessage = samlMsgCtx.getOutboundSAMLMessage();
    if (samlMessage == null) {
        throw new MessageEncodingException("No outbound SAML message contained in message context");
    }

    signMessage(samlMsgCtx);

    log.debug("Building SOAP envelope");

    Envelope envelope = envBuilder.buildObject();
    Body body = bodyBuilder.buildObject();
    envelope.setBody(body);
    body.getUnknownXMLObjects().add(samlMessage);

    messageContext.setOutboundMessage(envelope);
}
 
Example #10
Source File: HttpSOAPClient.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes a SOAP fault, as determined by an HTTP 500 status code, response.
 * 
 * @param httpMethod the HTTP method used to send the request and receive the response
 * @param messageContext current messages context
 * 
 * @throws SOAPClientException thrown if the response can not be read from the {@link PostMethod}
 * @throws SOAPFaultException an exception containing the SOAP fault
 */
protected void processFaultResponse(PostMethod httpMethod, SOAPMessageContext messageContext)
        throws SOAPClientException, SOAPFaultException {
    try {
        Envelope response = unmarshallResponse(httpMethod.getResponseBodyAsStream());
        messageContext.setInboundMessage(response);

        List<XMLObject> faults = response.getBody().getUnknownXMLObjects(Fault.DEFAULT_ELEMENT_NAME);
        if (faults.size() < 1) {
            throw new SOAPClientException("HTTP status code was 500 but SOAP response did not contain a Fault");
        }
        Fault fault = (Fault) faults.get(0);

        log.debug("SOAP fault code {} with message {}", fault.getCode().getValue(), fault.getMessage().getValue());
        SOAPFaultException faultException = new SOAPFaultException("SOAP Fault: " + fault.getCode().getValue()
                + " Fault Message: " + fault.getMessage().getValue());
        faultException.setFault(fault);
        throw faultException;
    } catch (IOException e) {
        throw new SOAPClientException("Unable to read response", e);
    }
}
 
Example #11
Source File: SamlFederationResource.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Handles artifact binding request.
 * @param request
 * @param uriInfo
 * @return
 */
@GET
@Path("sso/artifact")
public Response processArtifactBinding(@Context HttpServletRequest request, @Context UriInfo uriInfo) {
    String artifact = request.getParameter("SAMLart");
    String realmId = request.getParameter("RelayState");

    if (artifact == null) {
        throw new APIAccessDeniedException("No artifact provided by the IdP");
    }

    String artifactUrl = samlHelper.getArtifactUrl(realmId, artifact);


    ArtifactResolve artifactResolve = artifactBindingHelper.generateArtifactResolveRequest(artifact, dsPKEntry, artifactUrl);
    Envelope soapEnvelope = artifactBindingHelper.generateSOAPEnvelope(artifactResolve);

    XMLObject response = soapHelper.sendSOAPCommunication(soapEnvelope, artifactUrl, clientCertPKEntry);

    ArtifactResponse artifactResponse = (ArtifactResponse)((EnvelopeImpl) response).getBody().getUnknownXMLObjects().get(0);
    org.opensaml.saml2.core.Response samlResponse = (org.opensaml.saml2.core.Response) artifactResponse.getMessage();

    return processSAMLResponse(samlResponse, uriInfo);
}
 
Example #12
Source File: HttpSOAPClient.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #13
Source File: HandlerChainAwareHTTPSOAP11Encoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor. */
public HandlerChainAwareHTTPSOAP11Encoder() {
    super();
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
    envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME);
}
 
Example #14
Source File: ArtifactBindingHelper.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param artifactResolutionRequest
 * @return
 */
protected Envelope generateSOAPEnvelope(ArtifactResolve artifactResolutionRequest) {
    XMLObjectBuilderFactory xmlObjectBuilderFactory = Configuration.getBuilderFactory();
    Envelope envelope = (Envelope) xmlObjectBuilderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME).buildObject(Envelope.DEFAULT_ELEMENT_NAME);
    Body body = (Body) xmlObjectBuilderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME).buildObject(Body.DEFAULT_ELEMENT_NAME);

    body.getUnknownXMLObjects().add(artifactResolutionRequest);
    envelope.setBody(body);

    return envelope;
}
 
Example #15
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine whether the inbound message represented by the message context 
 * contains a SOAP Envelope.
 * 
 * @param messageContext the current message context
 * @return true if the inbound message contains a SOAP Envelope, false otherwise
 */
public static boolean isInboundSOAPMessage(MessageContext messageContext) {
    XMLObject inboundMessage = messageContext.getInboundMessage();
    if (inboundMessage == null) {
        return false;
    }
    // SOAP 1.1 Envelope
    if (inboundMessage instanceof Envelope) {
        return true;
    }
    //TODO SOAP 1.2 support when object providers are implemented
    return false;
}
 
Example #16
Source File: ArtifactBindingHelperTest.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@Test
public void generateSOAPEnvelopeTest() {
    ArtifactResolve artifactRequest = Mockito.mock(ArtifactResolve.class);
    Envelope env = artifactBindingHelper.generateSOAPEnvelope(artifactRequest);
    Assert.assertEquals(artifactRequest, env.getBody().getUnknownXMLObjects().get(0));
    Assert.assertEquals(Envelope.DEFAULT_ELEMENT_NAME, env.getElementQName());
}
 
Example #17
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a header block to the SOAP envelope contained within the specified message context's
 * {@link MessageContext#getOutboundMessage()}.
 * 
 * @param messageContext the message context being processed
 * @param headerBlock the header block to add
 */
public static void addHeaderBlock(MessageContext messageContext, XMLObject headerBlock) {
    XMLObject outboundEnvelope = messageContext.getOutboundMessage();
    if (outboundEnvelope == null) {
        throw new IllegalArgumentException("Message context does not contain a SOAP envelope");
    }
    
    // SOAP 1.1 Envelope
    if (outboundEnvelope instanceof Envelope) {
        addSOAP11HeaderBlock((Envelope) outboundEnvelope, headerBlock);
    }
    
    //TODO SOAP 1.2 support when object providers are implemented
    
}
 
Example #18
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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(Envelope envelope, XMLObject headerBlock) {
    Header envelopeHeader = envelope.getHeader();
    if (envelopeHeader == null) {
        envelopeHeader = (Header) Configuration.getBuilderFactory().getBuilder(Header.DEFAULT_ELEMENT_NAME)
            .buildObject(Header.DEFAULT_ELEMENT_NAME);
        envelope.setHeader(envelopeHeader);
    }
    
    envelopeHeader.getUnknownXMLObjects().add(headerBlock);
}
 
Example #19
Source File: SOAP11Decoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void doDecode(MessageContext messageContext) throws MessageDecodingException {

    InTransport inTransport = messageContext.getInboundMessageTransport();

    log.debug("Unmarshalling SOAP message");
    Envelope soapMessage = (Envelope) unmarshallMessage(inTransport.getIncomingStream());
    messageContext.setInboundMessage(soapMessage);
}
 
Example #20
Source File: EnvelopeMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@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 = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey()) 
                || envelope.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
 
Example #21
Source File: EnvelopeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    Envelope envelope = (Envelope) xmlObject;
    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());
    if (attribute.isId()) {
        envelope.getUnknownAttributes().registerID(attribQName);
    }
    envelope.getUnknownAttributes().put(attribQName, attribute.getValue());
}
 
Example #22
Source File: EnvelopeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@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);
    }
}
 
Example #23
Source File: SOAP11Encoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds the SOAP envelope and body skeleton to be encoded.
 * 
 * @param messageContext the message context being processed
 * 
 * @return the minimal SOAP message envelope skeleton
 */
protected Envelope buildSOAPEnvelope(MessageContext messageContext) {
    log.debug("Building SOAP envelope");

    Envelope envelope = envBuilder.buildObject();

    Body body = bodyBuilder.buildObject();
    envelope.setBody(body);

    return envelope;
}
 
Example #24
Source File: SOAP11Encoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor. */
@SuppressWarnings("unchecked")
public SOAP11Encoder() {
    super();
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
    envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME);
}
 
Example #25
Source File: HTTPSOAP11Encoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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>
 * 
 * @param messageContext the current message context being processed
 * @return a SOAPAction HTTP header URI value
 */
protected String getSOAPAction(MessageContext messageContext) {
    Envelope env = (Envelope) messageContext.getOutboundMessage();
    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();
    }
}
 
Example #26
Source File: HttpSOAPClient.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Processes a successful, as determined by an HTTP 200 status code, response.
 * 
 * @param httpMethod the HTTP method used to send the request and receive the response
 * @param messageContext current messages context
 * 
 * @throws SOAPClientException thrown if there is a problem reading the response from the {@link PostMethod}
 */
protected void processSuccessfulResponse(PostMethod httpMethod, SOAPMessageContext messageContext)
        throws SOAPClientException {
    try {
        Envelope response = unmarshallResponse(httpMethod.getResponseBodyAsStream());
        messageContext.setInboundMessage(response);
        evaluateSecurityPolicy(messageContext);
    } catch (IOException e) {
        throw new SOAPClientException("Unable to read response", e);
    }
}
 
Example #27
Source File: HttpSOAPClient.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the post method used to send the SOAP request.
 * 
 * @param endpoint endpoint to which the message is sent
 * @param requestParams HTTP request parameters
 * @param message message to be sent
 * 
 * @return the post method to be used to send this message
 * 
 * @throws SOAPClientException thrown if the message could not be marshalled
 */
protected PostMethod createPostMethod(String endpoint, HttpSOAPRequestParameters requestParams, Envelope message)
        throws SOAPClientException {
    log.debug("POSTing SOAP message to {}", endpoint);

    PostMethod post = new PostMethod(endpoint);
    post.setRequestEntity(createRequestEntity(message, Charset.forName("UTF-8")));
    if (requestParams != null && requestParams.getSoapAction() != null) {
        post.setRequestHeader(HttpSOAPRequestParameters.SOAP_ACTION_HEADER, requestParams.getSoapAction());
    }

    return post;
}
 
Example #28
Source File: EnvelopeBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Envelope buildObject(String namespaceURI, String localName, String namespacePrefix) {
    return new EnvelopeImpl(namespaceURI, localName, namespacePrefix);
}
 
Example #29
Source File: HTTPSOAP11Decoder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
    if (!(messageContext instanceof SAMLMessageContext)) {
        log.error("Invalid message context type, this decoder only support SAMLMessageContext");
        throw new MessageDecodingException(
                "Invalid message context type, this decoder only support SAMLMessageContext");
    }

    if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
        log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
        throw new MessageDecodingException(
                "Invalid inbound message transport type, this decoder only support HTTPInTransport");
    }

    SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;

    HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
    if (!inTransport.getHTTPMethod().equalsIgnoreCase("POST")) {
        throw new MessageDecodingException("This message decoder only supports the HTTP POST method");
    }

    log.debug("Unmarshalling SOAP message");
    Envelope soapMessage = (Envelope) unmarshallMessage(inTransport.getIncomingStream());
    samlMsgCtx.setInboundMessage(soapMessage);

    Header messageHeader = soapMessage.getHeader();
    if (messageHeader != null) {
        checkUnderstoodSOAPHeaders(soapMessage.getHeader().getUnknownXMLObjects());
    }

    List<XMLObject> soapBodyChildren = soapMessage.getBody().getUnknownXMLObjects();
    if (soapBodyChildren.size() < 1 || soapBodyChildren.size() > 1) {
        log.error("Unexpected number of children in the SOAP body, " + soapBodyChildren.size()
                + ".  Unable to extract SAML message");
        throw new MessageDecodingException(
                "Unexpected number of children in the SOAP body, unable to extract SAML message");
    }

    XMLObject incommingMessage = soapBodyChildren.get(0);
    if (!(incommingMessage instanceof SAMLObject)) {
        log.error("Unexpected SOAP body content.  Expected a SAML request but recieved {}", incommingMessage
                .getElementQName());
        throw new MessageDecodingException("Unexpected SOAP body content.  Expected a SAML request but recieved "
                + incommingMessage.getElementQName());
    }

    SAMLObject samlMessage = (SAMLObject) incommingMessage;
    log.debug("Decoded SOAP messaged which included SAML message of type {}", samlMessage.getElementQName());
    samlMsgCtx.setInboundSAMLMessage(samlMessage);

    populateMessageContext(samlMsgCtx);
}
 
Example #30
Source File: HTTPSOAP11Decoder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
    if (!(messageContext instanceof SAMLMessageContext)) {
        log.error("Invalid message context type, this decoder only support SAMLMessageContext");
        throw new MessageDecodingException(
                "Invalid message context type, this decoder only support SAMLMessageContext");
    }

    if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
        log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
        throw new MessageDecodingException(
                "Invalid inbound message transport type, this decoder only support HTTPInTransport");
    }

    SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;

    HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
    if (!inTransport.getHTTPMethod().equalsIgnoreCase("POST")) {
        throw new MessageDecodingException("This message decoder only supports the HTTP POST method");
    }

    log.debug("Unmarshalling SOAP message");
    Envelope soapMessage = (Envelope) unmarshallMessage(inTransport.getIncomingStream());
    samlMsgCtx.setInboundMessage(soapMessage);

    Header messageHeader = soapMessage.getHeader();
    if (messageHeader != null) {
        checkUnderstoodSOAPHeaders(soapMessage.getHeader().getUnknownXMLObjects());
    }

    List<XMLObject> soapBodyChildren = soapMessage.getBody().getUnknownXMLObjects();
    if (soapBodyChildren.size() < 1 || soapBodyChildren.size() > 1) {
        log.error("Unexpected number of children in the SOAP body, " + soapBodyChildren.size()
                + ".  Unable to extract SAML message");
        throw new MessageDecodingException(
                "Unexpected number of children in the SOAP body, unable to extract SAML message");
    }

    XMLObject incommingMessage = soapBodyChildren.get(0);
    if (!(incommingMessage instanceof SAMLObject)) {
        log.error("Unexpected SOAP body content.  Expected a SAML request but recieved {}", incommingMessage
                .getElementQName());
        throw new MessageDecodingException("Unexpected SOAP body content.  Expected a SAML request but recieved "
                + incommingMessage.getElementQName());
    }

    SAMLObject samlMessage = (SAMLObject) incommingMessage;
    log.debug("Decoded SOAP messaged which included SAML message of type {}", samlMessage.getElementQName());
    samlMsgCtx.setInboundSAMLMessage(samlMessage);

    populateMessageContext(samlMsgCtx);
}