/** * @param SAML2_Message $samlMessage * @return mixed */ public function serialize(SAML2_Message $samlMessage) { if ($samlMessage->getSignatureKey()) { $samlMessageDomElement = $samlMessage->toSignedXML(); } else { $samlMessageDomElement = $samlMessage->toUnsignedXML(); } return $samlMessageDomElement->ownerDocument->saveXML($samlMessageDomElement); }
/** * Create the redirect URL for a message. * * @param SAML2_Message $message The message. * @return string The URL the user should be redirected to in order to send a message. */ public function getRedirectURL(SAML2_Message $message) { if ($this->destination === NULL) { $destination = $message->getDestination(); } else { $destination = $this->destination; } $relayState = $message->getRelayState(); $key = $message->getSignatureKey(); $msgStr = $message->toUnsignedXML(); $msgStr = $msgStr->ownerDocument->saveXML($msgStr); SimpleSAML_Utilities::debugMessage($msgStr, 'out'); $msgStr = gzdeflate($msgStr); $msgStr = base64_encode($msgStr); /* Build the query string. */ if ($message instanceof SAML2_Request) { $msg = 'SAMLRequest='; } else { $msg = 'SAMLResponse='; } $msg .= urlencode($msgStr); if ($relayState !== NULL) { $msg .= '&RelayState=' . urlencode($relayState); } if ($key !== NULL) { /* Add the signature. */ $msg .= '&SigAlg=' . urlencode(XMLSecurityKey::RSA_SHA1); $signature = $key->signData($msg); $msg .= '&Signature=' . urlencode(base64_encode($signature)); } if (strpos($destination, '?') === FALSE) { $destination .= '?' . $msg; } else { $destination .= '&' . $msg; } return $destination; }