Java Code Examples for org.opensaml.common.binding.SAMLMessageContext#setInboundSAMLMessage()

The following examples show how to use org.opensaml.common.binding.SAMLMessageContext#setInboundSAMLMessage() . 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: HTTPPostDecoder.java    From lams with GNU General Public License v2.0 5 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");
    }

    String relayState = inTransport.getParameterValue("TARGET");
    samlMsgCtx.setRelayState(relayState);
    log.debug("Decoded SAML relay state (TARGET parameter) of: {}", relayState);

    String base64Message = inTransport.getParameterValue("SAMLResponse");
    byte[] decodedBytes = Base64.decode(base64Message);
    if (decodedBytes == null) {
        log.error("Unable to Base64 decode SAML message");
        throw new MessageDecodingException("Unable to Base64 decode SAML message");
    }

    SAMLObject inboundMessage = (SAMLObject) unmarshallMessage(new ByteArrayInputStream(decodedBytes));
    samlMsgCtx.setInboundMessage(inboundMessage);
    samlMsgCtx.setInboundSAMLMessage(inboundMessage);
    log.debug("Decoded SAML message");

    populateMessageContext(samlMsgCtx);
}
 
Example 2
Source File: HTTPRedirectDeflateDecoder.java    From lams with GNU General Public License v2.0 5 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();
    String relayState = inTransport.getParameterValue("RelayState");
    samlMsgCtx.setRelayState(relayState);
    log.debug("Decoded RelayState: {}", relayState);

    InputStream samlMessageIns;
    if (!DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLRequest"))) {
        samlMessageIns = decodeMessage(inTransport.getParameterValue("SAMLRequest"));
    } else if (!DatatypeHelper.isEmpty(inTransport.getParameterValue("SAMLResponse"))) {
        samlMessageIns = decodeMessage(inTransport.getParameterValue("SAMLResponse"));
    } else {
        throw new MessageDecodingException(
                "No SAMLRequest or SAMLResponse query path parameter, invalid SAML 2 HTTP Redirect message");
    }

    SAMLObject samlMessage = (SAMLObject) unmarshallMessage(samlMessageIns);
    samlMsgCtx.setInboundSAMLMessage(samlMessage);
    samlMsgCtx.setInboundMessage(samlMessage);
    log.debug("Decoded SAML message");

    populateMessageContext(samlMsgCtx);
}
 
Example 3
Source File: HTTPPostDecoder.java    From lams with GNU General Public License v2.0 5 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");
    }

    String relayState = inTransport.getParameterValue("RelayState");
    samlMsgCtx.setRelayState(relayState);
    log.debug("Decoded SAML relay state of: {}", relayState);

    InputStream base64DecodedMessage = getBase64DecodedMessage(inTransport);
    SAMLObject inboundMessage = (SAMLObject) unmarshallMessage(base64DecodedMessage);
    samlMsgCtx.setInboundMessage(inboundMessage);
    samlMsgCtx.setInboundSAMLMessage(inboundMessage);
    log.debug("Decoded SAML message");

    populateMessageContext(samlMsgCtx);
}
 
Example 4
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 5
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);
}