1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\samlp; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Constants as C; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
12
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
13
|
|
|
|
14
|
|
|
use function array_pop; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class for handling SAML2 Scoping. |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/saml2 |
20
|
|
|
*/ |
21
|
|
|
final class Scoping extends AbstractSamlpElement implements SchemaValidatableElementInterface |
22
|
|
|
{ |
23
|
|
|
use SchemaValidatableElementTrait; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Initialize a Scoping element. |
28
|
|
|
* |
29
|
|
|
* @param int|null $proxyCount |
30
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\IDPList|null $IDPList |
31
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\RequesterID[] $requesterId |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
protected ?int $proxyCount = null, |
35
|
|
|
protected ?IDPList $IDPList = null, |
36
|
|
|
protected array $requesterId = [], |
37
|
|
|
) { |
38
|
|
|
Assert::maxCount($requesterId, C::UNBOUNDED_LIMIT); |
39
|
|
|
Assert::allIsInstanceOf($requesterId, RequesterID::class); |
40
|
|
|
Assert::nullOrNatural($proxyCount); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return \SimpleSAML\SAML2\XML\samlp\IDPList|null |
46
|
|
|
*/ |
47
|
|
|
public function getIDPList(): ?IDPList |
48
|
|
|
{ |
49
|
|
|
return $this->IDPList; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return \SimpleSAML\SAML2\XML\samlp\RequesterID[] |
55
|
|
|
*/ |
56
|
|
|
public function getRequesterId(): array |
57
|
|
|
{ |
58
|
|
|
return $this->requesterId; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return int|null |
64
|
|
|
*/ |
65
|
|
|
public function getProxyCount(): ?int |
66
|
|
|
{ |
67
|
|
|
return $this->proxyCount; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
73
|
|
|
* |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
public function isEmptyElement(): bool |
77
|
|
|
{ |
78
|
|
|
return empty($this->proxyCount) |
79
|
|
|
&& empty($this->IDPList) |
80
|
|
|
&& empty($this->requesterId); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Convert XML into a Scoping-element |
86
|
|
|
* |
87
|
|
|
* @param \DOMElement $xml The XML element we should load |
88
|
|
|
* @return static |
89
|
|
|
* |
90
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
91
|
|
|
* if the qualified name of the supplied element is wrong |
92
|
|
|
*/ |
93
|
|
|
public static function fromXML(DOMElement $xml): static |
94
|
|
|
{ |
95
|
|
|
Assert::same($xml->localName, 'Scoping', InvalidDOMElementException::class); |
96
|
|
|
Assert::same($xml->namespaceURI, Scoping::NS, InvalidDOMElementException::class); |
97
|
|
|
|
98
|
|
|
$proxyCount = self::getOptionalIntegerAttribute($xml, 'ProxyCount', null); |
99
|
|
|
$idpList = IDPList::getChildrenOfClass($xml); |
100
|
|
|
$requesterId = RequesterID::getChildrenOfClass($xml); |
101
|
|
|
|
102
|
|
|
return new static( |
103
|
|
|
$proxyCount, |
104
|
|
|
array_pop($idpList), |
105
|
|
|
$requesterId, |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Convert this Scoping to XML. |
112
|
|
|
* |
113
|
|
|
* @param \DOMElement|null $parent The element we should append this Scoping to. |
114
|
|
|
* @return \DOMElement |
115
|
|
|
*/ |
116
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
117
|
|
|
{ |
118
|
|
|
$e = $this->instantiateParentElement($parent); |
119
|
|
|
|
120
|
|
|
if ($this->getProxyCount() !== null) { |
121
|
|
|
$e->setAttribute('ProxyCount', strval($this->getProxyCount())); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this->getIDPList()?->toXML($e); |
125
|
|
|
|
126
|
|
|
foreach ($this->getRequesterId() as $rid) { |
127
|
|
|
$rid->toXML($e); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $e; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|