ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
RoleDescriptor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\XML\md;
4 
7 use SAML2\Utils;
8 
15 {
21  private $elementName;
22 
28  public $ID;
29 
35  public $validUntil;
36 
43 
50 
56  public $errorURL;
57 
65  public $Extensions = array();
66 
74  public $KeyDescriptor = array();
75 
81  public $Organization = null;
82 
90  public $ContactPerson = array();
91 
99  protected function __construct($elementName, \DOMElement $xml = null)
100  {
101  assert(is_string($elementName));
102 
103  parent::__construct($xml);
104  $this->elementName = $elementName;
105 
106  if ($xml === null) {
107  return;
108  }
109 
110  if ($xml->hasAttribute('ID')) {
111  $this->ID = $xml->getAttribute('ID');
112  }
113  if ($xml->hasAttribute('validUntil')) {
114  $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
115  }
116  if ($xml->hasAttribute('cacheDuration')) {
117  $this->cacheDuration = $xml->getAttribute('cacheDuration');
118  }
119 
120  if (!$xml->hasAttribute('protocolSupportEnumeration')) {
121  throw new \Exception('Missing protocolSupportEnumeration attribute on ' . $xml->localName);
122  }
123  $this->protocolSupportEnumeration = preg_split('/[\s]+/', $xml->getAttribute('protocolSupportEnumeration'));
124 
125  if ($xml->hasAttribute('errorURL')) {
126  $this->errorURL = $xml->getAttribute('errorURL');
127  }
128 
130 
131  foreach (Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) {
132  $this->KeyDescriptor[] = new KeyDescriptor($kd);
133  }
134 
135  $organization = Utils::xpQuery($xml, './saml_metadata:Organization');
136  if (count($organization) > 1) {
137  throw new \Exception('More than one Organization in the entity.');
138  } elseif (!empty($organization)) {
139  $this->Organization = new Organization($organization[0]);
140  }
141 
142  foreach (Utils::xpQuery($xml, './saml_metadata:ContactPerson') as $cp) {
143  $this->contactPersons[] = new ContactPerson($cp);
144  }
145  }
146 
153  protected function toXML(\DOMElement $parent)
154  {
155  assert(is_null($this->ID) || is_string($this->ID));
156  assert(is_null($this->validUntil) || is_int($this->validUntil));
157  assert(is_null($this->cacheDuration) || is_string($this->cacheDuration));
158  assert(is_array($this->protocolSupportEnumeration));
159  assert(is_null($this->errorURL) || is_string($this->errorURL));
160  assert(is_array($this->Extensions));
161  assert(is_array($this->KeyDescriptor));
162  assert(is_null($this->Organization) || $this->Organization instanceof Organization);
163  assert(is_array($this->ContactPerson));
164 
165  $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, $this->elementName);
166  $parent->appendChild($e);
167 
168  if (isset($this->ID)) {
169  $e->setAttribute('ID', $this->ID);
170  }
171 
172  if (isset($this->validUntil)) {
173  $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil));
174  }
175 
176  if (isset($this->cacheDuration)) {
177  $e->setAttribute('cacheDuration', $this->cacheDuration);
178  }
179 
180  $e->setAttribute('protocolSupportEnumeration', implode(' ', $this->protocolSupportEnumeration));
181 
182  if (isset($this->errorURL)) {
183  $e->setAttribute('errorURL', $this->errorURL);
184  }
185 
186  Extensions::addList($e, $this->Extensions);
187 
188  foreach ($this->KeyDescriptor as $kd) {
189  $kd->toXML($e);
190  }
191 
192  if (isset($this->Organization)) {
193  $this->Organization->toXML($e);
194  }
195 
196  foreach ($this->ContactPerson as $cp) {
197  $cp->toXML($e);
198  }
199 
200  return $e;
201  }
202 }
__construct($elementName, \DOMElement $xml=null)
Initialize a RoleDescriptor.
$xml
Definition: metadata.php:240
const NS_MD
The namespace for the SAML 2 metadata.
Definition: Constants.php:225
static xpQuery(\DOMNode $node, $query)
Do an XPath query on an XML node.
Definition: Utils.php:191
Create styles array
The data for the language used.
static xsDateTimeToTimestamp($time)
This function converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(.s+)?Z to a UNIX timestamp...
Definition: Utils.php:721
static addList(\DOMElement $parent, array $extensions)
Add a list of Extensions to the given element.
Definition: Extensions.php:70
toXML(\DOMElement $parent)
Add this RoleDescriptor to an EntityDescriptor.
static getList(\DOMElement $parent)
Get a list of Extensions in the given element.
Definition: Extensions.php:27