1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\sp_200702; |
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
|
|
|
use function sprintf; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing WS security policy RequestSecurityTokenTemplateType. |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/ws-security |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractRequestSecurityTokenTemplateType extends AbstractSpElement |
22
|
|
|
{ |
23
|
|
|
use ExtendableAttributesTrait; |
24
|
|
|
use ExtendableElementTrait; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** The namespace-attribute for the xs:any element */ |
27
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
28
|
|
|
|
29
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
30
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::ANY; |
31
|
|
|
|
32
|
|
|
/** The exclusions for the xs:anyAttribute element */ |
33
|
|
|
public const XS_ANY_ATTR_EXCLUSIONS = [ |
34
|
|
|
[null, 'TrustVersion'], |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* AbstractRequestSecurityTokenTemplateType constructor. |
40
|
|
|
* |
41
|
|
|
* @param string|null $trustVersion |
42
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts |
43
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
44
|
|
|
*/ |
45
|
|
|
final public function __construct( |
46
|
|
|
protected ?string $trustVersion = null, |
47
|
|
|
array $elts = [], |
48
|
|
|
array $namespacedAttributes = [], |
49
|
|
|
) { |
50
|
|
|
Assert::nullOrValidURI($trustVersion); |
|
|
|
|
51
|
|
|
|
52
|
|
|
$this->setElements($elts); |
53
|
|
|
$this->setAttributesNS($namespacedAttributes); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Collect the value of the trustVersion property. |
59
|
|
|
* |
60
|
|
|
* @return string|null |
61
|
|
|
*/ |
62
|
|
|
public function getTrustVersion(): ?string |
63
|
|
|
{ |
64
|
|
|
return $this->trustVersion; |
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->trustVersion) && empty($this->elements) && empty($this->namespacedAttributes); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Initialize an RequestSecurityTokenTemplateType. |
81
|
|
|
* |
82
|
|
|
* Note: this method cannot be used when extending this class, if the constructor has a different signature. |
83
|
|
|
* |
84
|
|
|
* @param \DOMElement $xml The XML element we should load. |
85
|
|
|
* @return static |
86
|
|
|
* |
87
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
88
|
|
|
* if the qualified name of the supplied element is wrong |
89
|
|
|
*/ |
90
|
|
|
public static function fromXML(DOMElement $xml): static |
91
|
|
|
{ |
92
|
|
|
$qualifiedName = static::getClassName(static::class); |
93
|
|
|
Assert::eq( |
|
|
|
|
94
|
|
|
$xml->localName, |
95
|
|
|
$qualifiedName, |
96
|
|
|
sprintf( |
97
|
|
|
'Unexpected name for RequestSecurityTokenTemplateType: %s. Expected: %s.', |
98
|
|
|
$xml->localName, |
99
|
|
|
$qualifiedName, |
100
|
|
|
), |
101
|
|
|
InvalidDOMElementException::class, |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
return new static( |
105
|
|
|
self::getOptionalAttribute($xml, 'TrustVersion', null), |
106
|
|
|
self::getChildElementsFromXML($xml), |
107
|
|
|
self::getAttributesNSFromXML($xml), |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Convert this element to XML. |
114
|
|
|
* |
115
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
116
|
|
|
* @return \DOMElement |
117
|
|
|
*/ |
118
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
119
|
|
|
{ |
120
|
|
|
$e = $this->instantiateParentElement($parent); |
121
|
|
|
|
122
|
|
|
if ($this->getTrustVersion() !== null) { |
123
|
|
|
$e->setAttribute('TrustVersion', $this->getTrustVersion()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
foreach ($this->getElements() as $elt) { |
127
|
|
|
$elt->toXML($e); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
131
|
|
|
$attr->toXML($e); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $e; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|