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\SAML11\Constants as C; |
10
|
|
|
use SimpleSAML\XML\Chunk; |
11
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
12
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
13
|
|
|
use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
14
|
|
|
use SimpleSAML\XMLSchema\XML\Constants\NS; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* SAML AdviceType abstract data type. |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/saml11 |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractAdviceType extends AbstractSamlElement |
22
|
|
|
{ |
23
|
|
|
use ExtendableElementTrait; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** The namespace-attribute for the xs:any element */ |
27
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initialize a saml:AdviceType from scratch |
32
|
|
|
* |
33
|
|
|
* @param array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference> $assertionIDReference |
34
|
|
|
* @param array<\SimpleSAML\SAML11\XML\saml\Assertion> $assertion |
35
|
|
|
* @param \SimpleSAML\XML\SerializableElementInterface[] $elements |
36
|
|
|
*/ |
37
|
|
|
final public function __construct( |
38
|
|
|
protected array $assertionIDReference = [], |
39
|
|
|
protected array $assertion = [], |
40
|
|
|
array $elements = [], |
41
|
|
|
) { |
42
|
|
|
Assert::maxCount($assertionIDReference, C::UNBOUNDED_LIMIT); |
43
|
|
|
Assert::maxCount($assertion, C::UNBOUNDED_LIMIT); |
44
|
|
|
Assert::allIsInstanceOf($assertionIDReference, AssertionIDReference::class, SchemaViolationException::class); |
45
|
|
|
Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class); |
46
|
|
|
|
47
|
|
|
$this->setElements($elements); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Collect the value of the assertionIDReference-property |
53
|
|
|
* |
54
|
|
|
* @return array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference> |
55
|
|
|
*/ |
56
|
|
|
public function getAssertionIDReference(): array |
57
|
|
|
{ |
58
|
|
|
return $this->assertionIDReference; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Collect the value of the assertion-property |
64
|
|
|
* |
65
|
|
|
* @return array<\SimpleSAML\SAML11\XML\saml\Assertion> |
66
|
|
|
*/ |
67
|
|
|
public function getAssertion(): array |
68
|
|
|
{ |
69
|
|
|
return $this->assertion; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function isEmptyElement(): bool |
79
|
|
|
{ |
80
|
|
|
return empty($this->assertionIDReference) |
81
|
|
|
&& empty($this->assertion) |
82
|
|
|
&& empty($this->getElements()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Convert XML into an AdviceType |
88
|
|
|
* |
89
|
|
|
* @param \DOMElement $xml The XML element we should load |
90
|
|
|
* @return static |
91
|
|
|
* |
92
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
93
|
|
|
* if the qualified name of the supplied element is wrong |
94
|
|
|
*/ |
95
|
|
|
public static function fromXML(DOMElement $xml): static |
96
|
|
|
{ |
97
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
98
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
99
|
|
|
|
100
|
|
|
$elements = []; |
101
|
|
|
foreach ($xml->childNodes as $element) { |
102
|
|
|
if ($element->namespaceURI === C::NS_SAML) { |
103
|
|
|
continue; |
104
|
|
|
} elseif (!($element instanceof DOMElement)) { |
105
|
|
|
continue; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$elements[] = new Chunk($element); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return new static( |
112
|
|
|
AssertionIDReference::getChildrenOfClass($xml), |
113
|
|
|
Assertion::getChildrenOfClass($xml), |
114
|
|
|
$elements, |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Convert this EvidenceType to XML. |
121
|
|
|
* |
122
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
123
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this EvidenceType. |
124
|
|
|
*/ |
125
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
126
|
|
|
{ |
127
|
|
|
$e = $this->instantiateParentElement($parent); |
128
|
|
|
|
129
|
|
|
foreach ($this->getAssertionIDReference() as $assertionIDRef) { |
130
|
|
|
$assertionIDRef->toXML($e); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
foreach ($this->getAssertion() as $assertion) { |
134
|
|
|
$assertion->toXML($e); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
foreach ($this->getElements() as $element) { |
138
|
|
|
$element->toXML($e); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $e; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|