|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\md; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\XML\Chunk; |
|
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
|
12
|
|
|
use SimpleSAML\XML\Utils as XMLUtils; |
|
13
|
|
|
|
|
14
|
|
|
use function preg_split; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class representing unknown RoleDescriptors. |
|
18
|
|
|
* |
|
19
|
|
|
* @package simplesamlphp/saml2 |
|
20
|
|
|
*/ |
|
21
|
|
|
final class UnknownRoleDescriptor extends AbstractRoleDescriptor |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* This RoleDescriptor as XML |
|
25
|
|
|
* |
|
26
|
|
|
* @var \SimpleSAML\XML\Chunk |
|
27
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
|
28
|
|
|
*/ |
|
29
|
|
|
protected Chunk $elt; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Initialize an unknown RoleDescriptor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \DOMElement $xml The XML element we should load. |
|
36
|
|
|
* @return \SimpleSAML\SAML2\XML\md\UnknownRoleDescriptor |
|
37
|
|
|
* |
|
38
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException if the qualified name of the supplied element is wrong |
|
39
|
|
|
* @throws \SimpleSAML\XML\Exception\MissingAttributeException if the supplied element is missing one of the mandatory attributes |
|
40
|
|
|
* @throws \SimpleSAML\XML\Exception\TooManyElementsException if too many child-elements of a type are specified |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function fromXML(DOMElement $xml): object |
|
43
|
|
|
{ |
|
44
|
|
|
$protocols = self::getAttribute($xml, 'protocolSupportEnumeration'); |
|
45
|
|
|
|
|
46
|
|
|
$validUntil = self::getAttribute($xml, 'validUntil', null); |
|
47
|
|
|
$orgs = Organization::getChildrenOfClass($xml); |
|
48
|
|
|
Assert::maxCount($orgs, 1, 'More than one Organization found in this descriptor', TooManyElementsException::class); |
|
49
|
|
|
|
|
50
|
|
|
$extensions = Extensions::getChildrenOfClass($xml); |
|
51
|
|
|
Assert::maxCount($extensions, 1, 'Only one md:Extensions element is allowed.', TooManyElementsException::class); |
|
52
|
|
|
|
|
53
|
|
|
$object = new self( |
|
54
|
|
|
preg_split('/[\s]+/', trim($protocols)), |
|
55
|
|
|
self::getAttribute($xml, 'ID', null), |
|
56
|
|
|
$validUntil !== null ? XMLUtils::xsDateTimeToTimestamp($validUntil) : null, |
|
57
|
|
|
self::getAttribute($xml, 'cacheDuration', null), |
|
58
|
|
|
!empty($extensions) ? $extensions[0] : null, |
|
59
|
|
|
self::getAttribute($xml, 'errorURL', null), |
|
60
|
|
|
KeyDescriptor::getChildrenOfClass($xml), |
|
61
|
|
|
!empty($orgs) ? $orgs[0] : null, |
|
62
|
|
|
ContactPerson::getChildrenOfClass($xml) |
|
63
|
|
|
); |
|
64
|
|
|
$object->elt = new Chunk($xml); |
|
65
|
|
|
return $object; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the original XML of this descriptor as a Chunk object. |
|
71
|
|
|
* |
|
72
|
|
|
* @return \SimpleSAML\XML\Chunk |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getElement(): Chunk |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->elt; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Add this RoleDescriptor to an EntityDescriptor. |
|
82
|
|
|
* |
|
83
|
|
|
* @param \DOMElement|null $parent The EntityDescriptor we should append this RoleDescriptor to. |
|
84
|
|
|
* @return \DOMElement |
|
85
|
|
|
*/ |
|
86
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->elt->toXML($parent); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|