|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wsp; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\WSSecurity\XML\wsp\AppliesTo; |
|
10
|
|
|
use SimpleSAML\WSSecurity\XML\wsp\Policy; |
|
11
|
|
|
use SimpleSAML\WSSecurity\XML\wsp\PolicyReference; |
|
12
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
13
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
|
14
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
|
15
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
|
16
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
|
17
|
|
|
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
|
18
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
|
19
|
|
|
|
|
20
|
|
|
use function array_merge; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class representing a wsp:PolicyAttachment element. |
|
24
|
|
|
* |
|
25
|
|
|
* @package simplesamlphp/ws-security |
|
26
|
|
|
*/ |
|
27
|
|
|
final class PolicyAttachment extends AbstractWspElement implements SchemaValidatableElementInterface |
|
28
|
|
|
{ |
|
29
|
|
|
use ExtendableAttributesTrait; |
|
30
|
|
|
use ExtendableElementTrait; |
|
|
|
|
|
|
31
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** The namespace-attribute for the xs:any element */ |
|
34
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
|
35
|
|
|
|
|
36
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
|
37
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::ANY; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Initialize a wsp:PolicyAttachment |
|
42
|
|
|
* |
|
43
|
|
|
* @param \SimpleSAML\WSSecurity\XML\wsp\AppliesTo $appliesTo |
|
44
|
|
|
* @param (\SimpleSAML\WSSecurity\XML\wsp\Policy|\SimpleSAML\WSSecurity\XML\wsp\PolicyReference)[] $policies |
|
45
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children |
|
46
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
protected AppliesTo $appliesTo, |
|
50
|
|
|
protected array $policies, |
|
51
|
|
|
array $children = [], |
|
52
|
|
|
array $namespacedAttributes = [], |
|
53
|
|
|
) { |
|
54
|
|
|
$this->setElements($children); |
|
55
|
|
|
$this->setAttributesNS($namespacedAttributes); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Collect the value of the AppliesTo property. |
|
61
|
|
|
* |
|
62
|
|
|
* @return \SimpleSAML\WSSecurity\XML\wsp\AppliesTo |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getAppliesTo(): AppliesTo |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->appliesTo; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Collect the value of the Policies property. |
|
72
|
|
|
* |
|
73
|
|
|
* @return (\SimpleSAML\WSSecurity\XML\wsp\Policy|\SimpleSAML\WSSecurity\XML\wsp\PolicyReference)[] |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getPolicies(): array |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->policies; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/* |
|
82
|
|
|
* Convert XML into an wsp:PolicyAttachment element |
|
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
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
|
|
|
|
|
93
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
94
|
|
|
|
|
95
|
|
|
$appliesTo = AppliesTo::getChildrenOfClass($xml); |
|
96
|
|
|
Assert::minCount($appliesTo, 1, MissingElementException::class); |
|
|
|
|
|
|
97
|
|
|
Assert::maxCount($appliesTo, 1, TooManyElementsException::class); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$policy = Policy::getChildrenOfClass($xml); |
|
100
|
|
|
$policyReference = PolicyReference::getChildrenOfClass($xml); |
|
101
|
|
|
|
|
102
|
|
|
$policies = array_merge($policy, $policyReference); |
|
103
|
|
|
Assert::minCount($policies, 1, MissingElementException::class); |
|
104
|
|
|
|
|
105
|
|
|
return new static( |
|
106
|
|
|
$appliesTo[0], |
|
107
|
|
|
$policies, |
|
108
|
|
|
self::getChildElementsFromXML($xml), |
|
109
|
|
|
self::getAttributesNSFromXML($xml), |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Convert this wsp:PolicyAttachment to XML. |
|
116
|
|
|
* |
|
117
|
|
|
* @param \DOMElement|null $parent The element we should add this wsp:AppliesTo to. |
|
118
|
|
|
* @return \DOMElement This wsp:AppliesTo element. |
|
119
|
|
|
*/ |
|
120
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
121
|
|
|
{ |
|
122
|
|
|
$e = $this->instantiateParentElement($parent); |
|
123
|
|
|
|
|
124
|
|
|
$this->getAppliesTo()->toXML($e); |
|
125
|
|
|
|
|
126
|
|
|
foreach ($this->getPolicies() as $pol) { |
|
127
|
|
|
$pol->toXML($e); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
131
|
|
|
$attr->toXML($e); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ |
|
135
|
|
|
foreach ($this->getElements() as $child) { |
|
136
|
|
|
if (!$child->isEmptyElement()) { |
|
137
|
|
|
$child->toXML($e); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $e; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|