1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class representing a saml:Evidence element. |
14
|
|
|
* |
15
|
|
|
* @package simplesaml/saml2 |
16
|
|
|
*/ |
17
|
|
|
final class Evidence extends AbstractSamlElement |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] $assertionIDRef |
21
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] $assertionURIRef |
22
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\Assertion[] $assertion |
23
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] $encryptedAssertion |
24
|
|
|
*/ |
25
|
|
|
public function __construct( |
26
|
|
|
protected array $assertionIDRef = [], |
27
|
|
|
protected array $assertionURIRef = [], |
28
|
|
|
protected array $assertion = [], |
29
|
|
|
protected array $encryptedAssertion = [], |
30
|
|
|
) { |
31
|
|
|
Assert::allIsInstanceOf($assertionIDRef, AssertionIDRef::class, SchemaViolationException::class); |
32
|
|
|
Assert::allIsInstanceOf($assertionURIRef, AssertionURIRef::class, SchemaViolationException::class); |
33
|
|
|
Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class); |
34
|
|
|
Assert::allIsInstanceOf($encryptedAssertion, EncryptedAssertion::class, SchemaViolationException::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
40
|
|
|
* |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function isEmptyElement(): bool |
44
|
|
|
{ |
45
|
|
|
return ( |
46
|
|
|
empty($this->assertionIDRef) |
47
|
|
|
&& empty($this->assertionURIRef) |
48
|
|
|
&& empty($this->assertion) |
49
|
|
|
&& empty($this->encryptedAssertion) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] |
56
|
|
|
*/ |
57
|
|
|
public function getAssertionIDRef(): array |
58
|
|
|
{ |
59
|
|
|
return $this->assertionIDRef; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] |
65
|
|
|
*/ |
66
|
|
|
public function getAssertionURIRef(): array |
67
|
|
|
{ |
68
|
|
|
return $this->assertionURIRef; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\Assertion[] |
74
|
|
|
*/ |
75
|
|
|
public function getAssertion(): array |
76
|
|
|
{ |
77
|
|
|
return $this->assertion; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] |
83
|
|
|
*/ |
84
|
|
|
public function getEncryptedAssertion(): array |
85
|
|
|
{ |
86
|
|
|
return $this->encryptedAssertion; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Convert XML into an Evidence |
92
|
|
|
* |
93
|
|
|
* @param \DOMElement $xml The XML element we should load |
94
|
|
|
* @return static |
95
|
|
|
* |
96
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
97
|
|
|
* If the qualified name of the supplied element is wrong |
98
|
|
|
*/ |
99
|
|
|
public static function fromXML(DOMElement $xml): static |
100
|
|
|
{ |
101
|
|
|
$qualifiedName = static::getClassName(static::class); |
102
|
|
|
Assert::eq( |
103
|
|
|
$xml->localName, |
104
|
|
|
$qualifiedName, |
105
|
|
|
'Unexpected name for endpoint: ' . $xml->localName . '. Expected: ' . $qualifiedName . '.', |
106
|
|
|
InvalidDOMElementException::class, |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$assertionIDRef = AssertionIDRef::getChildrenOfClass($xml); |
110
|
|
|
$assertionURIRef = AssertionURIRef::getChildrenOfClass($xml); |
111
|
|
|
$assertion = Assertion::getChildrenOfClass($xml); |
112
|
|
|
$encryptedAssertion = EncryptedAssertion::getChildrenOfClass($xml); |
113
|
|
|
|
114
|
|
|
return new static( |
115
|
|
|
$assertionIDRef, |
116
|
|
|
$assertionURIRef, |
117
|
|
|
$assertion, |
118
|
|
|
$encryptedAssertion, |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Convert this Evidence to XML. |
125
|
|
|
* |
126
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
127
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this Condition. |
128
|
|
|
*/ |
129
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
130
|
|
|
{ |
131
|
|
|
$e = $this->instantiateParentElement($parent); |
132
|
|
|
|
133
|
|
|
foreach ($this->getAssertionIDRef() as $assertionIDRef) { |
134
|
|
|
$assertionIDRef->toXML($e); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
foreach ($this->getAssertionURIRef() as $assertionURIRef) { |
138
|
|
|
$assertionURIRef->toXML($e); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
foreach ($this->getAssertion() as $assertion) { |
142
|
|
|
$assertion->toXML($e); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
foreach ($this->getEncryptedAssertion() as $encryptedAssertion) { |
146
|
|
|
$encryptedAssertion->toXML($e); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return $e; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|