Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 48598db

Browse files
committed
Migrate to xsd-types
1 parent fd11f72 commit 48598db

77 files changed

Lines changed: 714 additions & 823 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
"simplesamlphp/assert": "~1.8.1",
1818
"simplesamlphp/composer-xmlprovider-installer": "~1.0.1",
19-
"simplesamlphp/saml2": "^5@dev",
20-
"simplesamlphp/xml-security": "~1.13.0",
21-
"simplesamlphp/xml-common": "~1.24.0"
19+
"simplesamlphp/saml2": "dev-feature/xsd-types",
20+
"simplesamlphp/xml-common": "dev-feature/xsd-types",
21+
"simplesamlphp/xml-security": "dev-feature/xsd-types",
22+
"simplesamlphp/xml-soap": "dev-feature/xsd-types"
2223
},
2324
"require-dev": {
2425
"simplesamlphp/simplesamlphp-test-framework": "~1.8.0"

resources/schemas/ws-authorization.xsd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
4545
<xs:any namespace='##other' processContents='lax' minOccurs='1' maxOccurs='1' />
4646
</xs:choice>
4747
<xs:attribute name='Name' type='xs:anyURI' use='required' />
48-
<xs:attribute name='Scope' type='xs:anyURI' use='optional' />
49-
<xs:anyAttribute namespace='##other' processContents='lax' />
48+
<xs:attribute name='Scope' type='xs:anyURI' use='optional' />
49+
<xs:anyAttribute namespace='##other' processContents='lax' />
5050
</xs:complexType>
5151

5252
<!-- Section 9.3 -->
@@ -57,16 +57,16 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
5757
<xs:element name="Description" type="tns:DescriptionType" minOccurs="0" maxOccurs="1" />
5858
<xs:element name="DisplayValue" type="tns:DisplayValueType" minOccurs="0" maxOccurs="1" />
5959
<xs:choice minOccurs='0'>
60-
<xs:element name='Value' type='xs:string' minOccurs='1' maxOccurs='1' />
60+
<xs:element name='Value' type='xs:string' minOccurs='1' maxOccurs='1' />
6161
<xs:element name='EncryptedValue' type='tns:EncryptedValueType' minOccurs='1' maxOccurs='1' />
6262
<xs:element name='StructuredValue' type='tns:StructuredValueType' minOccurs='1' maxOccurs='1' />
6363
<xs:element name='ConstrainedValue' type='tns:ConstrainedValueType' minOccurs='1' maxOccurs='1' />
64-
<xs:any namespace='##other' processContents='lax' minOccurs='1' maxOccurs='1' />
65-
</xs:choice>
64+
<xs:any namespace='##other' processContents='lax' minOccurs='1' maxOccurs='1' />
65+
</xs:choice>
6666
</xs:sequence>
67-
<xs:attribute name='Uri' type='xs:anyURI' use='required' />
68-
<xs:attribute name='Optional' type='xs:boolean' use='optional' />
69-
<xs:anyAttribute namespace='##other' processContents='lax' />
67+
<xs:attribute name='Uri' type='xs:anyURI' use='required' />
68+
<xs:attribute name='Optional' type='xs:boolean' use='optional' />
69+
<xs:anyAttribute namespace='##other' processContents='lax' />
7070
</xs:complexType>
7171

7272
<xs:complexType name="DisplayNameType">

src/XML/auth/AbstractAdditionalContextType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\WSSecurity\XML\auth\ContextItem;
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XML\ExtendableAttributesTrait;
12-
use SimpleSAML\XML\ExtendableElementTrait;
11+
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
1312
use SimpleSAML\XML\XsNamespace as NS;
1413

1514
/**

src/XML/auth/AbstractClaimType.php

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\WSSecurity\XML\auth\ConstrainedValue;
10-
use SimpleSAML\WSSecurity\XML\auth\Description;
11-
use SimpleSAML\WSSecurity\XML\auth\DisplayName;
12-
use SimpleSAML\WSSecurity\XML\auth\DisplayValue;
13-
use SimpleSAML\WSSecurity\XML\auth\EncryptedValue;
14-
use SimpleSAML\WSSecurity\XML\auth\StructuredValue;
15-
use SimpleSAML\WSSecurity\XML\auth\Value;
9+
use SimpleSAML\WSSecurity\XML\auth\{
10+
ConstrainedValue,
11+
Description,
12+
DisplayName,
13+
DisplayValue,
14+
EncryptedValue,
15+
StructuredValue,
16+
Value,
17+
};
1618
use SimpleSAML\XML\Chunk;
17-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
18-
use SimpleSAML\XML\Exception\TooManyElementsException;
19-
use SimpleSAML\XML\ExtendableAttributesTrait;
20-
use SimpleSAML\XML\SerializableElementInterface;
19+
use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException};
20+
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait, SerializableElementInterface};
21+
use SimpleSAML\XML\Type\{AnyURIValue, BooleanValue};
2122
use SimpleSAML\XML\XsNamespace as NS;
2223

2324
use function array_filter;
2425
use function array_merge;
2526
use function array_pop;
27+
use function var_export;
2628

2729
/**
2830
* Class defining the ClaimType element
@@ -32,16 +34,20 @@
3234
abstract class AbstractClaimType extends AbstractAuthElement
3335
{
3436
use ExtendableAttributesTrait;
37+
use ExtendableElementTrait;
3538

3639
/** The namespace-attribute for the xs:anyAttribute */
3740
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
3841

42+
/** The namespace-attribute for the xs:any element */
43+
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
44+
3945

4046
/**
4147
* AbstractClaimType constructor
4248
*
43-
* @param string $uri
44-
* @param bool|null $optional
49+
* @param \SimpleSAML\XML\Type\AnyURIValue $uri
50+
* @param \SimpleSAML\XML\Type\BooleanValue|null $optional
4551
* @param \SimpleSAML\WSSecurity\XML\auth\DisplayName|null $displayName
4652
* @param \SimpleSAML\WSSecurity\XML\auth\Description|null $description
4753
* @param \SimpleSAML\WSSecurity\XML\auth\DisplayValue|null $displayValue
@@ -56,15 +62,14 @@ abstract class AbstractClaimType extends AbstractAuthElement
5662
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
5763
*/
5864
final public function __construct(
59-
protected string $uri,
60-
protected ?bool $optional = null,
65+
protected AnyURIValue $uri,
66+
protected ?BooleanValue $optional = null,
6167
protected ?DisplayName $displayName = null,
6268
protected ?Description $description = null,
6369
protected ?DisplayValue $displayValue = null,
6470
protected null|Value|EncryptedValue|StructuredValue|ConstrainedValue|SerializableElementInterface $value = null,
6571
array $namespacedAttributes = [],
6672
) {
67-
Assert::validURI($uri);
6873
if (
6974
!($value === null ||
7075
$value instanceof Value ||
@@ -133,9 +138,9 @@ public function getDescription(): ?Description
133138
/**
134139
* Get the value of the uri property.
135140
*
136-
* @return string
141+
* @return \SimpleSAML\XML\Type\AnyURIValue
137142
*/
138-
public function getURI(): string
143+
public function getURI(): AnyURIValue
139144
{
140145
return $this->uri;
141146
}
@@ -144,9 +149,9 @@ public function getURI(): string
144149
/**
145150
* Get the value of the optional property.
146151
*
147-
* @return bool|null
152+
* @return \SimpleSAML\XML\Type\BooleanValue|null
148153
*/
149-
public function getOptional(): ?bool
154+
public function getOptional(): ?BooleanValue
150155
{
151156
return $this->optional;
152157
}
@@ -179,15 +184,7 @@ public static function fromXML(DOMElement $xml): static
179184
$structuredValue = StructuredValue::getChildrenOfClass($xml);
180185
$encryptedValue = EncryptedValue::getChildrenOfClass($xml);
181186
$constrainedValue = ConstrainedValue::getChildrenOfClass($xml);
182-
183-
$otherValue = [];
184-
foreach ($xml->childNodes as $child) {
185-
if (!($child instanceof DOMElement)) {
186-
continue;
187-
} elseif ($child->namespaceURI !== static::NS) {
188-
$otherValue[] = new Chunk($child);
189-
}
190-
}
187+
$otherValue = self::getChildElementsFromXML($xml);
191188

192189
$value = array_filter(array_merge(
193190
$simpleValue,
@@ -199,8 +196,8 @@ public static function fromXML(DOMElement $xml): static
199196
Assert::maxCount($value, 1, TooManyElementsException::class);
200197

201198
return new static(
202-
self::getAttribute($xml, 'Uri'),
203-
self::getOptionalBooleanAttribute($xml, 'Optional', null),
199+
self::getAttribute($xml, 'Uri', AnyURIValue::class),
200+
self::getOptionalAttribute($xml, 'Optional', BooleanValue::class, null),
204201
array_pop($displayName),
205202
array_pop($description),
206203
array_pop($displayValue),
@@ -220,9 +217,9 @@ public function toXML(?DOMElement $parent = null): DOMElement
220217
{
221218
$e = $this->instantiateParentElement($parent);
222219

223-
$e->setAttribute('Uri', $this->getURI());
220+
$e->setAttribute('Uri', $this->getURI()->getValue());
224221
if ($this->getOptional() !== null) {
225-
$e->setAttribute('Optional', $this->getOptional() ? 'true' : 'false');
222+
$e->setAttribute('Optional', var_export($this->getOptional()->toBoolean(), true));
226223
}
227224

228225
$this->getDisplayName()?->toXML($e);

src/XML/auth/AbstractConstrainedSingleValueType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\TooManyElementsException;
9+
use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException};
1110

1211
use function array_pop;
1312

src/XML/auth/AbstractConstrainedValueType.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\MissingElementException;
11-
use SimpleSAML\XML\Exception\TooManyElementsException;
9+
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
1210
use SimpleSAML\XML\ExtendableElementTrait;
11+
use SimpleSAML\XML\Type\BooleanValue;
1312
use SimpleSAML\XML\XsNamespace as NS;
1413

1514
use function array_filter;
1615
use function array_merge;
1716
use function array_pop;
17+
use function var_export;
1818

1919
/**
2020
* Class defining the ConstrainedValueType element
@@ -41,12 +41,12 @@ abstract class AbstractConstrainedValueType extends AbstractAuthElement
4141
* \SimpleSAML\WSSecurity\XML\auth\ValueOneOf
4242
* ) $value
4343
* @param \SimpleSAML\XML\SerializableElementInterface[] $children
44-
* @param bool|null $assertConstraint
44+
* @param \SimpleSAML\XML\Type\BooleanValue|null $assertConstraint
4545
*/
4646
final public function __construct(
4747
protected ValueLessThan|ValueLessThanOrEqual|ValueGreaterThan|ValueGreaterThanOrEqual|ValueInRangen|ValueOneOf $value,
4848
array $children = [],
49-
protected ?bool $assertConstraint = null,
49+
protected ?BooleanValue $assertConstraint = null,
5050
) {
5151
$this->setElements($children);
5252
}
@@ -73,9 +73,9 @@ public function getValue(): ValueLessThan|ValueLessThanOrEqual|ValueGreaterThan|
7373
/**
7474
* Get the value of the assertConstraint property.
7575
*
76-
* @return bool|null
76+
* @return \SimpleSAML\XML\Type\BooleanValue|null
7777
*/
78-
public function getAssertConstraint(): ?bool
78+
public function getAssertConstraint(): ?BooleanValue
7979
{
8080
return $this->assertConstraint;
8181
}
@@ -116,7 +116,7 @@ public static function fromXML(DOMElement $xml): static
116116
return new static(
117117
array_pop($value),
118118
self::getChildElementsFromXML($xml),
119-
self::getOptionalBooleanAttribute($xml, 'AssertConstraint', null),
119+
self::getOptionalAttribute($xml, 'AssertConstraint', BooleanValue::class, null),
120120
);
121121
}
122122

@@ -132,7 +132,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
132132
$e = $this->instantiateParentElement($parent);
133133

134134
if ($this->getAssertConstraint() !== null) {
135-
$e->setAttribute('AssertConstraint', $this->getAssertConstraint() ? 'true' : 'false');
135+
$e->setAttribute('AssertConstraint', var_export($this->getAssertConstraint()->toBoolean(), true));
136136
}
137137

138138
$this->getValue()->toXML($e);

src/XML/auth/AbstractContextItemType.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
use SimpleSAML\XML\Exception\TooManyElementsException;
12-
use SimpleSAML\XML\ExtendableAttributesTrait;
13-
use SimpleSAML\XML\ExtendableElementTrait;
14-
use SimpleSAML\XML\SerializableElementInterface;
9+
use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException};
10+
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait, SerializableElementInterface};
11+
use SimpleSAML\XML\Type\AnyURIValue;
1512
use SimpleSAML\XML\XsNamespace as NS;
1613

1714
use function array_pop;
@@ -36,22 +33,19 @@ abstract class AbstractContextItemType extends AbstractAuthElement
3633
/**
3734
* AbstractContextItemType constructor
3835
*
39-
* @param string $Name
40-
* @param string|null $Scope
36+
* @param \SimpleSAML\XML\Type\AnyURIValue $Name
37+
* @param \SimpleSAML\XML\Type\AnyURIValue|null $Scope
4138
* @param \SimpleSAML\WSSecurity\XML\auth\Value|null $value
4239
* @param \SimpleSAML\XML\SerializableElementInterface|null $child
4340
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
4441
*/
4542
final public function __construct(
46-
protected string $Name,
47-
protected ?string $Scope = null,
43+
protected AnyURIValue $Name,
44+
protected ?AnyURIValue $Scope = null,
4845
protected ?Value $value = null,
4946
?SerializableElementInterface $child = null,
5047
array $namespacedAttributes = [],
5148
) {
52-
Assert::validURI($Name);
53-
Assert::nullOrValidURI($Scope);
54-
5549
// One of both must exist, they can't be both null
5650
Assert::inArray(null, [$value, $child], SchemaViolationException::class);
5751
Assert::notSame($value, $child, SchemaViolationException::class);
@@ -77,9 +71,9 @@ public function getValue(): ?Value
7771
/**
7872
* Get the value of the Name property.
7973
*
80-
* @return string
74+
* @return \SimpleSAML\XML\Type\AnyURIValue
8175
*/
82-
public function getName(): string
76+
public function getName(): AnyURIValue
8377
{
8478
return $this->Name;
8579
}
@@ -88,9 +82,9 @@ public function getName(): string
8882
/**
8983
* Get the value of the Scope property.
9084
*
91-
* @return string|null
85+
* @return \SimpleSAML\XML\Type\AnyURIValue|null
9286
*/
93-
public function getScope(): ?string
87+
public function getScope(): ?AnyURIValue
9488
{
9589
return $this->Scope;
9690
}
@@ -117,8 +111,8 @@ public static function fromXML(DOMElement $xml): static
117111
Assert::maxCount($children, 1, TooManyElementsException::class);
118112

119113
return new static(
120-
self::getAttribute($xml, 'Name'),
121-
self::getOptionalAttribute($xml, 'Scope'),
114+
self::getAttribute($xml, 'Name', AnyURIValue::class),
115+
self::getOptionalAttribute($xml, 'Scope', AnyURIValue::class, null),
122116
array_pop($value),
123117
array_pop($children),
124118
self::getAttributesNSFromXML($xml),
@@ -136,9 +130,9 @@ public function toXML(?DOMElement $parent = null): DOMElement
136130
{
137131
$e = $this->instantiateParentElement($parent);
138132

139-
$e->setAttribute('Name', $this->getName());
133+
$e->setAttribute('Name', $this->getName()->getValue());
140134
if ($this->getScope() !== null) {
141-
$e->setAttribute('Scope', $this->getScope());
135+
$e->setAttribute('Scope', $this->getScope()->getValue());
142136
}
143137

144138
foreach ($this->getAttributesNS() as $attr) {

0 commit comments

Comments
 (0)