1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\fed; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
11
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
12
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class defining the RequestPseudonymType element |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/ws-security |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractRequestPseudonymType extends AbstractFedElement |
20
|
|
|
{ |
21
|
|
|
use ExtendableAttributesTrait; |
22
|
|
|
use ExtendableElementTrait; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
25
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
26
|
|
|
|
27
|
|
|
/** The namespace-attribute for the xs:any element */ |
28
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* AbstractRequestPseudonymType constructor |
33
|
|
|
* |
34
|
|
|
* @param bool|null $SingleUse |
35
|
|
|
* @param bool|null $Lookup |
36
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children |
37
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
38
|
|
|
*/ |
39
|
|
|
final public function __construct( |
40
|
|
|
protected ?bool $SingleUse = null, |
41
|
|
|
protected ?bool $Lookup = null, |
42
|
|
|
array $children = [], |
43
|
|
|
array $namespacedAttributes = [], |
44
|
|
|
) { |
45
|
|
|
$this->setElements($children); |
46
|
|
|
$this->setAttributesNS($namespacedAttributes); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return bool|null |
52
|
|
|
*/ |
53
|
|
|
public function getSingleUse(): ?bool |
54
|
|
|
{ |
55
|
|
|
return $this->SingleUse; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return bool|null |
61
|
|
|
*/ |
62
|
|
|
public function getLookup(): ?bool |
63
|
|
|
{ |
64
|
|
|
return $this->Lookup; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
70
|
|
|
* |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function isEmptyElement(): bool |
74
|
|
|
{ |
75
|
|
|
return empty($this->getSingleUse()) |
76
|
|
|
&& empty($this->getLookup()) |
77
|
|
|
&& empty($this->getElements()) |
78
|
|
|
&& empty($this->getAttributesNS()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Create an instance of this object from its XML representation. |
84
|
|
|
* |
85
|
|
|
* @param \DOMElement $xml |
86
|
|
|
* @return static |
87
|
|
|
* |
88
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
89
|
|
|
* if the qualified name of the supplied element is wrong |
90
|
|
|
*/ |
91
|
|
|
public static function fromXML(DOMElement $xml): static |
92
|
|
|
{ |
93
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
94
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
95
|
|
|
|
96
|
|
|
return new static( |
97
|
|
|
self::getOptionalBooleanAttribute($xml, 'SingleUse', null), |
98
|
|
|
self::getOptionalBooleanAttribute($xml, 'Lookup', null), |
99
|
|
|
self::getChildElementsFromXML($xml), |
100
|
|
|
self::getAttributesNSFromXML($xml), |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Add this AbstractRequestPseudonymType to an XML element. |
107
|
|
|
* |
108
|
|
|
* @param \DOMElement|null $parent The element we should append this username token to. |
109
|
|
|
* @return \DOMElement |
110
|
|
|
*/ |
111
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
112
|
|
|
{ |
113
|
|
|
$e = parent::instantiateParentElement($parent); |
114
|
|
|
|
115
|
|
|
$singleUse = $this->getSingleUse(); |
116
|
|
|
if ($singleUse !== null) { |
117
|
|
|
$e->setAttribute('SingleUse', $singleUse ? 'true' : 'false'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$lookup = $this->getLookup(); |
121
|
|
|
if ($lookup !== null) { |
122
|
|
|
$e->setAttribute('Lookup', $lookup ? 'true' : 'false'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
126
|
|
|
$attr->toXML($e); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ |
130
|
|
|
foreach ($this->getElements() as $child) { |
131
|
|
|
if (!$child->isEmptyElement()) { |
132
|
|
|
$child->toXML($e); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $e; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|