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