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\SAML2\Constants as C; |
10
|
|
|
use SimpleSAML\XML\Attribute as XMLAttribute; |
11
|
|
|
use SimpleSAML\XML\Chunk; |
12
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
13
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
14
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing SAML2 AuthnContextDecl |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/saml2 |
20
|
|
|
*/ |
21
|
|
|
final class AuthnContextDecl extends AbstractSamlElement |
22
|
|
|
{ |
23
|
|
|
use ExtendableAttributesTrait; |
|
|
|
|
24
|
|
|
use ExtendableElementTrait; |
25
|
|
|
|
26
|
|
|
/** The namespace-attribute for the xs:any element */ |
27
|
|
|
public const XS_ANY_ELT_NAMESPACE = C::XS_ANY_NS_ANY; |
28
|
|
|
|
29
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
30
|
|
|
public const XS_ANY_ATTR_NAMESPACE = C::XS_ANY_NS_ANY; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initialize an AuthnContextDecl. |
35
|
|
|
* |
36
|
|
|
* @param \SimpleSAML\XML\Chunk[] $elements |
37
|
|
|
* @param \SimpleSAML\XML\Attribute[] $attributes |
38
|
|
|
*/ |
39
|
|
|
public function __construct(array $elements = [], array $attributes = []) |
40
|
|
|
{ |
41
|
|
|
$this->setElements($elements); |
42
|
|
|
$this->setAttributesNS($attributes); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
49
|
|
|
* |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
public function isEmptyElement(): bool |
53
|
|
|
{ |
54
|
|
|
return empty($this->getAttributesNS()) |
55
|
|
|
&& empty($this->getElements()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert XML into a AuthnContextDecl |
61
|
|
|
* |
62
|
|
|
* @param \DOMElement $xml The XML element we should load |
63
|
|
|
* @return static |
64
|
|
|
* |
65
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
66
|
|
|
* if the qualified name of the supplied element is wrong |
67
|
|
|
*/ |
68
|
|
|
public static function fromXML(DOMElement $xml): static |
69
|
|
|
{ |
70
|
|
|
Assert::same($xml->localName, 'AuthnContextDecl', InvalidDOMElementException::class); |
71
|
|
|
Assert::same($xml->namespaceURI, AuthnContextDecl::NS, InvalidDOMElementException::class); |
72
|
|
|
|
73
|
|
|
$elements = []; |
74
|
|
|
foreach ($xml->childNodes as $element) { |
75
|
|
|
if ($element->namespaceURI === C::NS_SAML) { |
76
|
|
|
continue; |
77
|
|
|
} elseif (!($element instanceof DOMElement)) { |
78
|
|
|
continue; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$elements[] = new Chunk($element); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return new static($elements, self::getAttributesNSFromXML($xml)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Convert this AuthContextDecl to XML. |
90
|
|
|
* |
91
|
|
|
* @param \DOMElement|null $parent The element we should append this AuthnContextDecl to. |
92
|
|
|
* @return \DOMElement |
93
|
|
|
*/ |
94
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
95
|
|
|
{ |
96
|
|
|
$e = $this->instantiateParentElement($parent); |
97
|
|
|
|
98
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
99
|
|
|
$attr->toXML($e); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
foreach ($this->getElements() as $element) { |
103
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $element */ |
104
|
|
|
$element->toXML($e); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $e; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|