1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SAML2\XML\md; |
6
|
|
|
|
7
|
|
|
use Assert\Assertion; |
8
|
|
|
|
9
|
|
|
use SAML2\Constants; |
10
|
|
|
use SAML2\SignedElementHelper; |
11
|
|
|
use SAML2\Utils; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing SAML 2 AffiliationDescriptor element. |
15
|
|
|
* |
16
|
|
|
* @package SimpleSAMLphp |
17
|
|
|
*/ |
18
|
|
|
class AffiliationDescriptor extends SignedElementHelper |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The affiliationOwnerID. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
public $affiliationOwnerID = ''; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The ID of this element. |
29
|
|
|
* |
30
|
|
|
* @var string|null |
31
|
|
|
*/ |
32
|
|
|
public $ID = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* How long this element is valid, as a unix timestamp. |
36
|
|
|
* |
37
|
|
|
* @var int|null |
38
|
|
|
*/ |
39
|
|
|
public $validUntil = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The length of time this element can be cached, as string. |
43
|
|
|
* |
44
|
|
|
* @var string|null |
45
|
|
|
*/ |
46
|
|
|
public $cacheDuration = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Extensions on this element. |
50
|
|
|
* |
51
|
|
|
* Array of extension elements. |
52
|
|
|
* |
53
|
|
|
* @var \SAML2\XML\Chunk[] |
54
|
|
|
*/ |
55
|
|
|
public $Extensions = []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The AffiliateMember(s). |
59
|
|
|
* |
60
|
|
|
* Array of entity ID strings. |
61
|
|
|
* |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
public $AffiliateMember = []; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* KeyDescriptor elements. |
68
|
|
|
* |
69
|
|
|
* Array of \SAML2\XML\md\KeyDescriptor elements. |
70
|
|
|
* |
71
|
|
|
* @var \SAML2\XML\md\KeyDescriptor[] |
72
|
|
|
*/ |
73
|
|
|
public $KeyDescriptor = []; |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Initialize a AffiliationDescriptor. |
78
|
|
|
* |
79
|
|
|
* @param \DOMElement|null $xml The XML element we should load. |
80
|
|
|
* @throws \Exception |
81
|
|
|
*/ |
82
|
|
|
public function __construct(\DOMElement $xml = null) |
83
|
|
|
{ |
84
|
|
|
parent::__construct($xml); |
85
|
|
|
|
86
|
|
|
if ($xml === null) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (!$xml->hasAttribute('affiliationOwnerID')) { |
91
|
|
|
throw new \Exception('Missing affiliationOwnerID on AffiliationDescriptor.'); |
92
|
|
|
} |
93
|
|
|
$this->setAffiliationOwnerID($xml->getAttribute('affiliationOwnerID')); |
94
|
|
|
|
95
|
|
|
if ($xml->hasAttribute('ID')) { |
96
|
|
|
$this->setID($xml->getAttribute('ID')); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ($xml->hasAttribute('validUntil')) { |
100
|
|
|
$this->setValidUntil(Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'))); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ($xml->hasAttribute('cacheDuration')) { |
104
|
|
|
$this->setCacheDuration($xml->getAttribute('cacheDuration')); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$this->setExtensions(Extensions::getList($xml)); |
108
|
|
|
|
109
|
|
|
$this->setAffiliateMember(Utils::extractStrings($xml, Constants::NS_MD, 'AffiliateMember')); |
110
|
|
|
if (empty($this->AffiliateMember)) { |
111
|
|
|
throw new \Exception('Missing AffiliateMember in AffiliationDescriptor.'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
foreach (Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) { |
115
|
|
|
$this->addKeyDescriptor(new KeyDescriptor($kd)); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Collect the value of the affiliationOwnerId-property |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getAffiliationOwnerID() : string |
125
|
|
|
{ |
126
|
|
|
return $this->affiliationOwnerID; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set the value of the affiliationOwnerId-property |
132
|
|
|
* @param string $affiliationOwnerId |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
public function setAffiliationOwnerID(string $affiliationOwnerId) |
136
|
|
|
{ |
137
|
|
|
$this->affiliationOwnerID = $affiliationOwnerId; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Collect the value of the ID-property |
143
|
|
|
* @return string|null |
144
|
|
|
*/ |
145
|
|
|
public function getID() |
146
|
|
|
{ |
147
|
|
|
return $this->ID; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set the value of the ID-property |
153
|
|
|
* @param string|null $Id |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
|
public function setID(string $Id = null) |
157
|
|
|
{ |
158
|
|
|
$this->ID = $Id; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Collect the value of the validUntil-property |
164
|
|
|
* @return int|null |
165
|
|
|
*/ |
166
|
|
|
public function getValidUntil() |
167
|
|
|
{ |
168
|
|
|
return $this->validUntil; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Set the value of the validUntil-property |
174
|
|
|
* @param int|null $validUntil |
175
|
|
|
* @return void |
176
|
|
|
*/ |
177
|
|
|
public function setValidUntil(int $validUntil = null) |
178
|
|
|
{ |
179
|
|
|
$this->validUntil = $validUntil; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Collect the value of the cacheDuration-property |
185
|
|
|
* @return string|null |
186
|
|
|
*/ |
187
|
|
|
public function getCacheDuration() |
188
|
|
|
{ |
189
|
|
|
return $this->cacheDuration; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Set the value of the cacheDuration-property |
195
|
|
|
* @param string|null $cacheDuration |
196
|
|
|
* @return void |
197
|
|
|
*/ |
198
|
|
|
public function setCacheDuration(string $cacheDuration = null) |
199
|
|
|
{ |
200
|
|
|
$this->cacheDuration = $cacheDuration; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Collect the value of the Extensions-property |
206
|
|
|
* @return \SAML2\XML\Chunk[] |
207
|
|
|
*/ |
208
|
|
|
public function getExtensions() : array |
209
|
|
|
{ |
210
|
|
|
return $this->Extensions; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set the value of the Extensions-property |
216
|
|
|
* @param array $extensions |
217
|
|
|
* @return void |
218
|
|
|
*/ |
219
|
|
|
public function setExtensions(array $extensions) |
220
|
|
|
{ |
221
|
|
|
$this->Extensions = $extensions; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Add an Extension. |
227
|
|
|
* |
228
|
|
|
* @param \SAML2\XML\Chunk $extensions The Extensions |
229
|
|
|
* @return void |
230
|
|
|
*/ |
231
|
|
|
public function addExtension(Extensions $extension) |
232
|
|
|
{ |
233
|
|
|
$this->Extensions[] = $extension; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Collect the value of the AffiliateMember-property |
239
|
|
|
* @return array |
240
|
|
|
*/ |
241
|
|
|
public function getAffiliateMember() : array |
242
|
|
|
{ |
243
|
|
|
return $this->AffiliateMember; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Set the value of the AffiliateMember-property |
249
|
|
|
* @param array $affiliateMember |
250
|
|
|
* @return void |
251
|
|
|
*/ |
252
|
|
|
public function setAffiliateMember(array $affiliateMember) |
253
|
|
|
{ |
254
|
|
|
$this->AffiliateMember = $affiliateMember; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Collect the value of the KeyDescriptor-property |
260
|
|
|
* @return \SAML2\XML\md\KeyDescriptor[] |
261
|
|
|
*/ |
262
|
|
|
public function getKeyDescriptor() : array |
263
|
|
|
{ |
264
|
|
|
return $this->KeyDescriptor; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Set the value of the KeyDescriptor-property |
270
|
|
|
* @param array $keyDescriptor |
271
|
|
|
* @return void |
272
|
|
|
*/ |
273
|
|
|
public function setKeyDescriptor(array $keyDescriptor) |
274
|
|
|
{ |
275
|
|
|
$this->KeyDescriptor = $keyDescriptor; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Add the value to the KeyDescriptor-property |
281
|
|
|
* @param \SAML2\XML\md\KeyDescriptor $keyDescriptor |
282
|
|
|
* @return void |
283
|
|
|
*/ |
284
|
|
|
public function addKeyDescriptor(KeyDescriptor $keyDescriptor) |
285
|
|
|
{ |
286
|
|
|
$this->KeyDescriptor[] = $keyDescriptor; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Add this AffiliationDescriptor to an EntityDescriptor. |
292
|
|
|
* |
293
|
|
|
* @param \DOMElement $parent The EntityDescriptor we should append this endpoint to. |
294
|
|
|
* @return \DOMElement |
295
|
|
|
*/ |
296
|
|
|
public function toXML(\DOMElement $parent) : \DOMElement |
297
|
|
|
{ |
298
|
|
|
Assertion::notEmpty($this->affiliateMember); |
|
|
|
|
299
|
|
|
|
300
|
|
|
$e = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:AffiliationDescriptor'); |
301
|
|
|
$parent->appendChild($e); |
302
|
|
|
|
303
|
|
|
$e->setAttribute('affiliationOwnerID', $this->getAffiliationOwnerID()); |
304
|
|
|
|
305
|
|
|
if ($this->getID() !== null) { |
306
|
|
|
$e->setAttribute('ID', $this->getID()); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
if ($this->getValidUntil() !== null) { |
310
|
|
|
$e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->getValidUntil())); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
if ($this->getCacheDuration() !== null) { |
314
|
|
|
$e->setAttribute('cacheDuration', $this->getCacheDuration()); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
Extensions::addList($e, $this->getExtensions()); |
318
|
|
|
|
319
|
|
|
Utils::addStrings($e, Constants::NS_MD, 'md:AffiliateMember', false, $this->getAffiliateMember()); |
320
|
|
|
|
321
|
|
|
foreach ($this->getKeyDescriptor() as $kd) { |
322
|
|
|
$kd->toXML($e); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
$this->signElement($e, $e->firstChild); |
326
|
|
|
|
327
|
|
|
return $e; |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|