1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XMLSchema\Exception\{ |
10
|
|
|
InvalidDOMElementException, |
11
|
|
|
MissingElementException, |
12
|
|
|
SchemaViolationException, |
13
|
|
|
TooManyElementsException, |
14
|
|
|
}; |
15
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* SAML SubjectConfirmationType abstract data type. |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/saml11 |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractSubjectConfirmationType extends AbstractSamlElement |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Initialize a saml:SubjectConfirmationType from scratch |
26
|
|
|
* |
27
|
|
|
* @param array<\SimpleSAML\SAML11\XML\saml\ConfirmationMethod> $confirmationMethod |
28
|
|
|
* @param \SimpleSAML\SAML11\XML\saml\SubjectConfirmationData|null $subjectConfirmationData |
29
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo |
30
|
|
|
*/ |
31
|
|
|
final public function __construct( |
32
|
|
|
protected array $confirmationMethod, |
33
|
|
|
protected ?SubjectConfirmationData $subjectConfirmationData = null, |
34
|
|
|
protected ?KeyInfo $keyInfo = null, |
35
|
|
|
) { |
36
|
|
|
Assert::minCount($confirmationMethod, 1, MissingElementException::class); |
37
|
|
|
Assert::allIsInstanceOf($confirmationMethod, ConfirmationMethod::class, SchemaViolationException::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Collect the value of the confirmationMethod-property |
43
|
|
|
* |
44
|
|
|
* @return array<\SimpleSAML\SAML11\XML\saml\ConfirmationMethod> |
45
|
|
|
*/ |
46
|
|
|
public function getConfirmationMethod(): array |
47
|
|
|
{ |
48
|
|
|
return $this->confirmationMethod; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Collect the value of the subjectConfirmationData-property |
54
|
|
|
* |
55
|
|
|
* @return \SimpleSAML\SAML11\XML\saml\SubjectConfirmationData|null |
56
|
|
|
*/ |
57
|
|
|
public function getSubjectConfirmationData(): ?SubjectConfirmationData |
58
|
|
|
{ |
59
|
|
|
return $this->subjectConfirmationData; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Collect the value of the keyInfo-property |
65
|
|
|
* |
66
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null |
67
|
|
|
*/ |
68
|
|
|
public function getKeyInfo(): ?KeyInfo |
69
|
|
|
{ |
70
|
|
|
return $this->keyInfo; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Convert XML into an SubjectConfirmationType |
76
|
|
|
* |
77
|
|
|
* @param \DOMElement $xml The XML element we should load |
78
|
|
|
* @return static |
79
|
|
|
* |
80
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
81
|
|
|
* if the qualified name of the supplied element is wrong |
82
|
|
|
*/ |
83
|
|
|
public static function fromXML(DOMElement $xml): static |
84
|
|
|
{ |
85
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
86
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
87
|
|
|
|
88
|
|
|
$subjectConfirmationData = SubjectConfirmationData::getChildrenOfClass($xml); |
89
|
|
|
Assert::maxCount($subjectConfirmationData, 1, TooManyElementsException::class); |
90
|
|
|
|
91
|
|
|
$keyInfo = KeyInfo::getChildrenOfClass($xml); |
92
|
|
|
Assert::maxCount($keyInfo, 1, TooManyElementsException::class); |
93
|
|
|
|
94
|
|
|
return new static( |
95
|
|
|
ConfirmationMethod::getChildrenOfClass($xml), |
96
|
|
|
array_pop($subjectConfirmationData), |
97
|
|
|
array_pop($keyInfo), |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Convert this SubjectConfirmationType to XML. |
104
|
|
|
* |
105
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
106
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this SubjectConfirmationType. |
107
|
|
|
*/ |
108
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
109
|
|
|
{ |
110
|
|
|
$e = $this->instantiateParentElement($parent); |
111
|
|
|
|
112
|
|
|
foreach ($this->getConfirmationMethod() as $confirmationMethod) { |
113
|
|
|
$confirmationMethod->toXML($e); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$this->getSubjectConfirmationData()?->toXML($e); |
117
|
|
|
$this->getKeyInfo()?->toXML($e); |
118
|
|
|
|
119
|
|
|
return $e; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|