ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HTTPPost.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2;
4 
10 class HTTPPost extends Binding
11 {
19  public function send(Message $message)
20  {
21  if ($this->destination === null) {
22  $destination = $message->getDestination();
23  } else {
25  }
26  $relayState = $message->getRelayState();
27 
28  $msgStr = $message->toSignedXML();
29  $msgStr = $msgStr->ownerDocument->saveXML($msgStr);
30 
31  Utils::getContainer()->debugMessage($msgStr, 'out');
32 
33  $msgStr = base64_encode($msgStr);
34 
35  if ($message instanceof Request) {
36  $msgType = 'SAMLRequest';
37  } else {
38  $msgType = 'SAMLResponse';
39  }
40 
41  $post = array();
42  $post[$msgType] = $msgStr;
43 
44  if ($relayState !== null) {
45  $post['RelayState'] = $relayState;
46  }
47 
48  Utils::getContainer()->postRedirect($destination, $post);
49  }
50 
59  public function receive()
60  {
61  if (array_key_exists('SAMLRequest', $_POST)) {
62  $msg = $_POST['SAMLRequest'];
63  } elseif (array_key_exists('SAMLResponse', $_POST)) {
64  $msg = $_POST['SAMLResponse'];
65  } else {
66  throw new \Exception('Missing SAMLRequest or SAMLResponse parameter.');
67  }
68 
69  $msg = base64_decode($msg);
70 
71  Utils::getContainer()->debugMessage($msg, 'in');
72 
73  $document = DOMDocumentFactory::fromString($msg);
74  $xml = $document->firstChild;
75 
76  $msg = Message::fromXML($xml);
77 
78  if (array_key_exists('RelayState', $_POST)) {
79  $msg->setRelayState($_POST['RelayState']);
80  }
81 
82  return $msg;
83  }
84 }
getRelayState()
Retrieve the RelayState associated with this message.
Definition: Message.php:411
$destination
toSignedXML()
Convert this message to a signed XML document.
Definition: Message.php:481
Base class for all SAML 2 messages.
Definition: Message.php:18
send(Message $message)
Send a SAML 2 message using the HTTP-POST binding.
Definition: HTTPPost.php:19
catch(Exception $e) $message
receive()
Receive a SAML 2 message sent using the HTTP-POST binding.
Definition: HTTPPost.php:59
$relayState
$post
Definition: post.php:34
getDestination()
Retrieve the destination of this message.
Definition: Message.php:323
$_POST["username"]