1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\auth; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\WSSecurity\XML\auth\ContextItem; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
12
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
13
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class defining the AdditionalContextType element |
17
|
|
|
* |
18
|
|
|
* @package simplesamlphp/ws-security |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractAdditionalContextType extends AbstractAuthElement |
21
|
|
|
{ |
22
|
|
|
use ExtendableAttributesTrait; |
23
|
|
|
use ExtendableElementTrait; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** The namespace-attribute for the xs:anyAttribute */ |
26
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
27
|
|
|
|
28
|
|
|
/** The namespace-attribute for the xs:any */ |
29
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* AbstractAdditionalContextType constructor |
34
|
|
|
* |
35
|
|
|
* @param \SimpleSAML\WSSecurity\XML\auth\ContextItem[] $contextItem |
36
|
|
|
* @param list<\SimpleSAML\XML\SerializableElementInterface> $children |
37
|
|
|
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
final public function __construct( |
40
|
|
|
protected array $contextItem = [], |
41
|
|
|
array $children = [], |
42
|
|
|
array $namespacedAttributes = [], |
43
|
|
|
) { |
44
|
|
|
$this->setElements($children); |
45
|
|
|
$this->setAttributesNS($namespacedAttributes); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the value of the $contextItem property. |
51
|
|
|
* |
52
|
|
|
* @return \SimpleSAML\WSSecurity\XML\auth\ContextItem[] |
53
|
|
|
*/ |
54
|
|
|
public function getContextItem(): array |
55
|
|
|
{ |
56
|
|
|
return $this->contextItem; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Create an instance of this object from its XML representation. |
62
|
|
|
* |
63
|
|
|
* @param \DOMElement $xml |
64
|
|
|
* @return static |
65
|
|
|
* |
66
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
67
|
|
|
* if the qualified name of the supplied element is wrong |
68
|
|
|
*/ |
69
|
|
|
public static function fromXML(DOMElement $xml): static |
70
|
|
|
{ |
71
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
72
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
73
|
|
|
|
74
|
|
|
$contextItem = ContextItem::getChildrenOfClass($xml); |
75
|
|
|
$children = self::getChildElementsFromXML($xml); |
76
|
|
|
|
77
|
|
|
return new static( |
78
|
|
|
$contextItem, |
79
|
|
|
$children, |
80
|
|
|
self::getAttributesNSFromXML($xml), |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Add this AdditionalContext to an XML element. |
87
|
|
|
* |
88
|
|
|
* @param \DOMElement $parent The element we should append this username token to. |
89
|
|
|
* @return \DOMElement |
90
|
|
|
*/ |
91
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
92
|
|
|
{ |
93
|
|
|
$e = $this->instantiateParentElement($parent); |
94
|
|
|
|
95
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
96
|
|
|
$attr->toXML($e); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
foreach ($this->getContextItem() as $ctx) { |
100
|
|
|
$ctx->toXML($e); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
foreach ($this->getElements() as $elt) { |
104
|
|
|
$elt->toXML($e); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $e; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|