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