/** * @param \DOMElement $xml * @throws \AerialShip\LightSaml\Error\InvalidXmlException */ function loadFromXml(\DOMElement $xml) { parent::loadFromXml($xml); if ($xml->hasAttribute('InResponseTo')) { $this->setInResponseTo($xml->getAttribute('InResponseTo')); } $this->iterateChildrenElements($xml, function (\DOMElement $node) { if ($node->localName == 'Status' && $node->namespaceURI == Protocol::SAML2) { $this->setStatus(new Status()); $this->getStatus()->loadFromXml($node); } }); if (!$this->getStatus()) { throw new InvalidXmlException('Missing Status element'); } }
/** * @param Request $request * @return Message * @throws \AerialShip\LightSaml\Error\BindingException */ function receive(Request $request) { $post = $request->getPost(); if (array_key_exists('SAMLRequest', $post)) { $msg = $post['SAMLRequest']; } elseif (array_key_exists('SAMLResponse', $post)) { $msg = $post['SAMLResponse']; } else { throw new BindingException('Missing SAMLRequest or SAMLResponse parameter'); } $msg = base64_decode($msg); $this->dispatchReceive($msg); $doc = new \DOMDocument(); $doc->loadXML($msg); $result = Message::fromXML($doc->firstChild); if (array_key_exists('RelayState', $post)) { $result->setRelayState($post['RelayState']); } return $result; }
/** * @param string $msg * @param Message $message * @return string */ private function getDestinationUrl($msg, Message $message) { $destination = $message->getDestination() ?: $this->getDestination(); if (strpos($destination, '?') === FALSE) { $destination .= '?' . $msg; } else { $destination .= '&' . $msg; } return $destination; }