ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Binding.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2;
4 
10 abstract class Binding
11 {
17  protected $destination;
18 
28  public static function getBinding($urn)
29  {
30  assert(is_string($urn));
31 
32  switch ($urn) {
33  case Constants::BINDING_HTTP_POST:
34  return new HTTPPost();
35  case Constants::BINDING_HTTP_REDIRECT:
36  return new HTTPRedirect();
37  case Constants::BINDING_HTTP_ARTIFACT:
38  return new HTTPArtifact();
39  case Constants::BINDING_HOK_SSO:
40  return new HTTPPost();
41  // ECP ACS is defined with the PAOS binding, but as the IdP, we
42  // talk to the ECP using SOAP -- if support for ECP as an SP is
43  // implemented, this logic may need to change
44  case Constants::BINDING_PAOS:
45  return new SOAP();
46  default:
47  throw new \Exception('Unsupported binding: ' . var_export($urn, true));
48  }
49  }
50 
62  public static function getCurrentBinding()
63  {
64  switch ($_SERVER['REQUEST_METHOD']) {
65  case 'GET':
66  if (array_key_exists('SAMLRequest', $_GET) || array_key_exists('SAMLResponse', $_GET)) {
67  return new HTTPRedirect();
68  } elseif (array_key_exists('SAMLart', $_GET)) {
69  return new HTTPArtifact();
70  }
71  break;
72 
73  case 'POST':
74  if (isset($_SERVER['CONTENT_TYPE'])) {
75  $contentType = $_SERVER['CONTENT_TYPE'];
76  $contentType = explode(';', $contentType);
77  $contentType = $contentType[0]; /* Remove charset. */
78  } else {
79  $contentType = null;
80  }
81  if (array_key_exists('SAMLRequest', $_POST) || array_key_exists('SAMLResponse', $_POST)) {
82  return new HTTPPost();
83  } elseif (array_key_exists('SAMLart', $_POST)) {
84  return new HTTPArtifact();
85  } elseif ($contentType === 'text/xml') {
86  return new SOAP();
87  }
88  break;
89  }
90 
91  $logger = Utils::getContainer()->getLogger();
92  $logger->warning('Unable to find the SAML 2 binding used for this request.');
93  $logger->warning('Request method: ' . var_export($_SERVER['REQUEST_METHOD'], true));
94  if (!empty($_GET)) {
95  $logger->warning("GET parameters: '" . implode("', '", array_map('addslashes', array_keys($_GET))) . "'");
96  }
97  if (!empty($_POST)) {
98  $logger->warning("POST parameters: '" . implode("', '", array_map('addslashes', array_keys($_POST))) . "'");
99  }
100  if (isset($_SERVER['CONTENT_TYPE'])) {
101  $logger->warning('Content-Type: ' . var_export($_SERVER['CONTENT_TYPE'], true));
102  }
103 
104  throw new \Exception('Unable to find the current binding.');
105  }
106 
112  public function getDestination()
113  {
114  return $this->destination;
115  }
116 
124  public function setDestination($destination)
125  {
126  assert(is_string($destination) || is_null($destination));
127 
128  $this->destination = $destination;
129  }
130 
139  abstract public function send(Message $message);
140 
149  abstract public function receive();
150 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_GET["client_id"]
static getBinding($urn)
Retrieve a binding with the given URN.
Definition: Binding.php:28
$destination
static getCurrentBinding()
Guess the current binding.
Definition: Binding.php:62
getDestination()
Retrieve the destination of a message.
Definition: Binding.php:112
$destination
The destination of messages.
Definition: Binding.php:17
Base class for all SAML 2 messages.
Definition: Message.php:18
catch(Exception $e) $message
setDestination($destination)
Override the destination of a message.
Definition: Binding.php:124
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', mb_strtolower($path, 'UTF-8'))) $contentType
Definition: module.php:144
$_POST["username"]