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\SubjectConfirmationData; |
11
|
|
|
use SimpleSAML\SOAP\Constants as C; |
12
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
13
|
|
|
use SimpleSAML\XML\Exception\MissingAttributeException; |
14
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
15
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
16
|
|
|
|
17
|
|
|
use function boolval; |
18
|
|
|
use function intval; |
19
|
|
|
use function is_null; |
20
|
|
|
use function is_numeric; |
21
|
|
|
use function strval; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class representing the ECP SubjectConfirmation element. |
25
|
|
|
* |
26
|
|
|
* @package simplesamlphp/saml2 |
27
|
|
|
*/ |
28
|
|
|
final class SubjectConfirmation extends AbstractEcpElement |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Create a ECP SubjectConfirmation element. |
32
|
|
|
* |
33
|
|
|
* @param bool $mustUnderstand |
34
|
|
|
* @param string $method |
35
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\SubjectConfirmationData|null $subjectConfirmationData |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
protected bool $mustUnderstand, |
39
|
|
|
protected string $method, |
40
|
|
|
protected ?SubjectConfirmationData $subjectConfirmationData = null, |
41
|
|
|
) { |
42
|
|
|
Assert::validURI($method, SchemaViolationException::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Collect the value of the mustUnderstand-property |
48
|
|
|
* |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
public function getMustUnderstand(): bool |
52
|
|
|
{ |
53
|
|
|
return $this->mustUnderstand; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Collect the value of the method-property |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getMethod(): string |
63
|
|
|
{ |
64
|
|
|
return $this->method; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Collect the value of the subjectConfirmationData-property |
70
|
|
|
* |
71
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\SubjectConfirmationData|null |
72
|
|
|
*/ |
73
|
|
|
public function getSubjectConfirmationData(): ?SubjectConfirmationData |
74
|
|
|
{ |
75
|
|
|
return $this->subjectConfirmationData; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Convert XML into a SubjectConfirmation |
81
|
|
|
* |
82
|
|
|
* @param \DOMElement $xml The XML element we should load |
83
|
|
|
* @return static |
84
|
|
|
* |
85
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
86
|
|
|
* if the qualified name of the supplied element is wrong |
87
|
|
|
* @throws \SimpleSAML\XML\Exception\MissingAttributeException |
88
|
|
|
* if the supplied element is missing any of the mandatory attributes |
89
|
|
|
*/ |
90
|
|
|
public static function fromXML(DOMElement $xml): static |
91
|
|
|
{ |
92
|
|
|
Assert::same($xml->localName, 'SubjectConfirmation', InvalidDOMElementException::class); |
93
|
|
|
Assert::same($xml->namespaceURI, SubjectConfirmation::NS, InvalidDOMElementException::class); |
94
|
|
|
|
95
|
|
|
// Assert required attributes |
96
|
|
|
Assert::true( |
97
|
|
|
$xml->hasAttributeNS(C::NS_SOAP_ENV_11, 'actor'), |
98
|
|
|
'Missing env:actor attribute in <ecp:SubjectConfirmation>.', |
99
|
|
|
MissingAttributeException::class, |
100
|
|
|
); |
101
|
|
|
Assert::true( |
102
|
|
|
$xml->hasAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand'), |
103
|
|
|
'Missing env:mustUnderstand attribute in <ecp:SubjectConfirmation>.', |
104
|
|
|
MissingAttributeException::class, |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand'); |
108
|
|
|
$mustUnderstand = ($mustUnderstand === '') ? null : boolval(intval($mustUnderstand)); |
109
|
|
|
Assert::nullOrBoolean( |
110
|
|
|
$mustUnderstand, |
111
|
|
|
'Invalid value of env:mustUnderstand attribute in <ecp:SubjectConfirmation>.', |
112
|
|
|
ProtocolViolationException::class, |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$actor = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'actor'); |
116
|
|
|
Assert::same( |
117
|
|
|
$actor, |
118
|
|
|
C::SOAP_ACTOR_NEXT, |
119
|
|
|
'Invalid value of env:actor attribute in <ecp:SubjectConfirmation>.', |
120
|
|
|
ProtocolViolationException::class, |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$subjectConfirmationData = SubjectConfirmationData::getChildrenOfClass($xml); |
124
|
|
|
Assert::maxCount( |
125
|
|
|
$subjectConfirmationData, |
126
|
|
|
1, |
127
|
|
|
'More than one <saml:SubjectConfirmationData> in <saml:SubjectConfirmation>.', |
128
|
|
|
TooManyElementsException::class, |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
return new static( |
132
|
|
|
$mustUnderstand, |
|
|
|
|
133
|
|
|
self::getAttribute($xml, 'Method'), |
134
|
|
|
array_pop($subjectConfirmationData), |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Convert this ECP SubjectConfirmation to XML. |
141
|
|
|
* |
142
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
143
|
|
|
* @return \DOMElement |
144
|
|
|
*/ |
145
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
146
|
|
|
{ |
147
|
|
|
$e = $this->instantiateParentElement($parent); |
148
|
|
|
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand()))); |
149
|
|
|
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT); |
150
|
|
|
$e->setAttribute('Method', $this->getMethod()); |
151
|
|
|
|
152
|
|
|
$this->getSubjectConfirmationData()?->toXML($e); |
153
|
|
|
|
154
|
|
|
return $e; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|