1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\ecp; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML2\Exception\ProtocolViolationException; |
10
|
|
|
use SimpleSAML\SAML2\XML\saml\Issuer; |
11
|
|
|
use SimpleSAML\SAML2\XML\samlp\IDPList; |
12
|
|
|
use SimpleSAML\SOAP\Constants as C; |
13
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
14
|
|
|
use SimpleSAML\XML\Exception\MissingAttributeException; |
15
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
16
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
17
|
|
|
|
18
|
|
|
use function boolval; |
19
|
|
|
use function intval; |
20
|
|
|
use function is_null; |
21
|
|
|
use function is_numeric; |
22
|
|
|
use function strval; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class representing the ECP Request element. |
26
|
|
|
* |
27
|
|
|
* @package simplesamlphp/saml2 |
28
|
|
|
*/ |
29
|
|
|
final class Request extends AbstractEcpElement |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Create a ECP Request element. |
33
|
|
|
* |
34
|
|
|
* @param bool $mustUnderstand |
35
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\Issuer $issuer |
36
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\IDPList|null $idpList |
37
|
|
|
* @param string|null $providerName |
38
|
|
|
* @param bool|null $isPassive |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
protected bool $mustUnderstand, |
42
|
|
|
protected Issuer $issuer, |
43
|
|
|
protected ?IDPList $idpList = null, |
44
|
|
|
protected ?string $providerName = null, |
45
|
|
|
protected ?bool $isPassive = null, |
46
|
|
|
) { |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Collect the value of the mustUnderstand-property |
52
|
|
|
* |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function getMustUnderstand(): bool |
56
|
|
|
{ |
57
|
|
|
return $this->mustUnderstand; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Collect the value of the isPassive-property |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function getIsPassive(): bool |
67
|
|
|
{ |
68
|
|
|
return $this->isPassive; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Collect the value of the providerName-property |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getProviderName(): string |
78
|
|
|
{ |
79
|
|
|
return $this->providerName; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Collect the value of the issuer-property |
85
|
|
|
* |
86
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\Issuer |
87
|
|
|
*/ |
88
|
|
|
public function getIssuer(): Issuer |
89
|
|
|
{ |
90
|
|
|
return $this->issuer; |
91
|
|
|
} |
92
|
|
|
/** |
93
|
|
|
* Collect the value of the idpList-property |
94
|
|
|
* |
95
|
|
|
* @return \SimpleSAML\SAML2\XML\samlp\IDPList|null |
96
|
|
|
*/ |
97
|
|
|
public function getIDPList(): ?IDPList |
98
|
|
|
{ |
99
|
|
|
return $this->idpList; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Convert XML into a Request |
105
|
|
|
* |
106
|
|
|
* @param \DOMElement $xml The XML element we should load |
107
|
|
|
* @return static |
108
|
|
|
* |
109
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
110
|
|
|
* if the qualified name of the supplied element is wrong |
111
|
|
|
* @throws \SimpleSAML\XML\Exception\MissingAttributeException |
112
|
|
|
* if the supplied element is missing any of the mandatory attributes |
113
|
|
|
*/ |
114
|
|
|
public static function fromXML(DOMElement $xml): static |
115
|
|
|
{ |
116
|
|
|
Assert::same($xml->localName, 'Request', InvalidDOMElementException::class); |
117
|
|
|
Assert::same($xml->namespaceURI, Request::NS, InvalidDOMElementException::class); |
118
|
|
|
|
119
|
|
|
// Assert required attributes |
120
|
|
|
Assert::true( |
121
|
|
|
$xml->hasAttributeNS(C::NS_SOAP_ENV_11, 'actor'), |
122
|
|
|
'Missing env:actor attribute in <ecp:Request>.', |
123
|
|
|
MissingAttributeException::class, |
124
|
|
|
); |
125
|
|
|
Assert::true( |
126
|
|
|
$xml->hasAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand'), |
127
|
|
|
'Missing env:mustUnderstand attribute in <ecp:Request>.', |
128
|
|
|
MissingAttributeException::class, |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand'); |
132
|
|
|
$mustUnderstand = ($mustUnderstand === '') ? null : boolval(intval($mustUnderstand)); |
133
|
|
|
Assert::nullOrBoolean( |
134
|
|
|
$mustUnderstand, |
135
|
|
|
'Invalid value of env:mustUnderstand attribute in <ecp:Request>.', |
136
|
|
|
ProtocolViolationException::class, |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$actor = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'actor'); |
140
|
|
|
Assert::same( |
141
|
|
|
$actor, |
142
|
|
|
C::SOAP_ACTOR_NEXT, |
143
|
|
|
'Invalid value of env:actor attribute in <ecp:Request>.', |
144
|
|
|
ProtocolViolationException::class, |
145
|
|
|
); |
146
|
|
|
|
147
|
|
|
$issuer = Issuer::getChildrenOfClass($xml); |
148
|
|
|
Assert::count( |
149
|
|
|
$issuer, |
150
|
|
|
1, |
151
|
|
|
'More than one <saml:Issuer> in <ecp:Request>.', |
152
|
|
|
TooManyElementsException::class, |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$idpList = IDPList::getChildrenOfClass($xml); |
156
|
|
|
|
157
|
|
|
return new static( |
158
|
|
|
$mustUnderstand, |
|
|
|
|
159
|
|
|
array_pop($issuer), |
160
|
|
|
array_pop($idpList), |
161
|
|
|
self::getOptionalAttribute($xml, 'ProviderName', null), |
162
|
|
|
self::getOptionalBooleanAttribute($xml, 'IsPassive', null), |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Convert this ECP SubjectConfirmation to XML. |
169
|
|
|
* |
170
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
171
|
|
|
* @return \DOMElement |
172
|
|
|
*/ |
173
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
174
|
|
|
{ |
175
|
|
|
$e = $this->instantiateParentElement($parent); |
176
|
|
|
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand()))); |
177
|
|
|
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT); |
178
|
|
|
|
179
|
|
|
if ($this->getProviderName() !== null) { |
|
|
|
|
180
|
|
|
$e->setAttribute('ProviderName', $this->getProviderName()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
if ($this->getIsPassive() !== null) { |
|
|
|
|
184
|
|
|
$e->setAttribute('IsPassive', strval(intval($this->getIsPassive()))); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$this->getIssuer()->toXML($e); |
188
|
|
|
$this->getIDPList()?->toXML($e); |
189
|
|
|
|
190
|
|
|
return $e; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|