/** {@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("GET")) {
throw new MessageDecodingException("This message deocoder only supports the HTTP GET method");
}
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);