@Override protected void doDecode() throws MessageDecodingException { final SAML2MessageContext messageContext = new SAML2MessageContext(); if (ContextHelper.isPost(context)) { final String relayState = this.context.getRequestParameter("RelayState"); logger.debug("Decoded SAML relay state of: {}", relayState); SAMLBindingSupport.setRelayState(messageContext, relayState); final byte[] base64DecodedMessage = this.getBase64DecodedMessage(); final XMLObject xmlObject = this.unmarshallMessage(new ByteArrayInputStream(base64DecodedMessage)); final SAMLObject inboundMessage; if (xmlObject instanceof Envelope) { Envelope soapMessage = (Envelope) xmlObject; messageContext.getSOAP11Context().setEnvelope(soapMessage); try { new SAMLSOAPDecoderBodyHandler().invoke(messageContext); } catch (final MessageHandlerException e) { throw new MessageDecodingException("Cannot decode SOAP envelope", e); } } else { inboundMessage = (SAMLObject) xmlObject; messageContext.setMessage(inboundMessage); } logger.debug("Decoded SAML message"); this.populateBindingContext(messageContext); this.setMessageContext(messageContext); } else { throw new MessageDecodingException("This message decoder only supports the HTTP POST method"); } }
@Override protected AbstractPac4jDecoder getDecoder(final WebContext webContext) { final AbstractPac4jDecoder decoder; if (ContextHelper.isPost(webContext)) { decoder = new Pac4jHTTPPostDecoder(webContext); try { decoder.setParserPool(Configuration.getParserPool()); decoder.initialize(); decoder.decode(); } catch (final Exception e) { throw new SAMLException("Error decoding POST SAML message", e); } } else if (ContextHelper.isGet(webContext)) { decoder = new Pac4jHTTPRedirectDeflateDecoder(webContext); try { decoder.setParserPool(Configuration.getParserPool()); decoder.initialize(); decoder.decode(); } catch (final Exception e) { throw new SAMLException("Error decoding HTTP-Redirect SAML message", e); } } else { throw new SAMLException("Only GET or POST requests are accepted"); } return decoder; }