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

Commit 4072268

Browse files
committed
Migrate to xsd-types
1 parent 152f1c4 commit 4072268

121 files changed

Lines changed: 416 additions & 417 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.

src/XML/sp_200507/AbstractIssuedTokenType.php

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

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9+
use SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue;
910
use SimpleSAML\XML\ExtendableAttributesTrait;
1011
use SimpleSAML\XML\ExtendableElementTrait;
1112
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
1213
use SimpleSAML\XMLSchema\Exception\MissingElementException;
1314
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14-
use SimpleSAML\XMLSchema\Type\StringValue;
1515
use SimpleSAML\XMLSchema\XML\Constants\NS;
16-
use ValueError;
1716

1817
use function array_pop;
19-
use function is_string;
2018
use function sprintf;
2119

2220
/**
@@ -48,14 +46,14 @@ abstract class AbstractIssuedTokenType extends AbstractSpElement
4846
*
4947
* @param \SimpleSAML\WSSecurity\XML\sp_200507\RequestSecurityTokenTemplate $requestSecurityTokenTemplate
5048
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Issuer|null $issuer
51-
* @param \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken|string|null $includeToken
49+
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
5250
* @param list<\SimpleSAML\XML\SerializableElementInterface> $elts
5351
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
5452
*/
5553
final public function __construct(
5654
protected RequestSecurityTokenTemplate $requestSecurityTokenTemplate,
5755
protected ?Issuer $issuer = null,
58-
IncludeToken|string|null $includeToken = null,
56+
?IncludeTokenValue $includeToken = null,
5957
array $elts = [],
6058
array $namespacedAttributes = [],
6159
) {
@@ -114,16 +112,10 @@ public static function fromXML(DOMElement $xml): static
114112
Assert::minCount($requestSecurityTokenTemplate, 1, MissingElementException::class);
115113
Assert::maxCount($requestSecurityTokenTemplate, 1, TooManyElementsException::class);
116114

117-
$includeToken = self::getOptionalAttribute($xml, 'IncludeToken', StringValue::class, null);
118-
try {
119-
$includeToken = IncludeToken::from($includeToken->getValue());
120-
} catch (ValueError) {
121-
}
122-
123115
return new static(
124116
$requestSecurityTokenTemplate[0],
125117
array_pop($issuer),
126-
$includeToken,
118+
self::getOptionalAttribute($xml, 'IncludeToken', IncludeTokenValue::class, null),
127119
self::getChildElementsFromXML($xml),
128120
self::getAttributesNSFromXML($xml),
129121
);
@@ -141,10 +133,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
141133
$e = $this->instantiateParentElement($parent);
142134

143135
if ($this->getIncludeToken() !== null) {
144-
$e->setAttribute(
145-
'IncludeToken',
146-
is_string($this->getIncludeToken()) ? $this->getIncludeToken() : $this->getIncludeToken()->value,
147-
);
136+
$e->setAttribute('IncludeToken', $this->getIncludeToken()->getValue());
148137
}
149138

150139
if ($this->getIssuer() !== null) {
@@ -154,7 +143,6 @@ public function toXML(?DOMElement $parent = null): DOMElement
154143
$this->getRequestSecurityTokenTemplate()->toXML($e);
155144

156145
foreach ($this->getElements() as $elt) {
157-
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $elt */
158146
$elt->toXML($e);
159147
}
160148

src/XML/sp_200507/AbstractSecureConversationTokenType.php

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

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9+
use SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue;
910
use SimpleSAML\XML\ExtendableAttributesTrait;
1011
use SimpleSAML\XML\ExtendableElementTrait;
1112
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12-
use SimpleSAML\XMLSchema\Type\StringValue;
1313
use SimpleSAML\XMLSchema\XML\Constants\NS;
14-
use ValueError;
1514

1615
use function array_pop;
17-
use function is_string;
1816
use function sprintf;
1917

2018
/**
@@ -45,13 +43,13 @@ abstract class AbstractSecureConversationTokenType extends AbstractSpElement
4543
* SecureConversationTokenType constructor.
4644
*
4745
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Issuer|null $issuer
48-
* @param \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken|string|null $includeToken
46+
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
4947
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts
5048
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
5149
*/
5250
final public function __construct(
5351
protected ?Issuer $issuer,
54-
IncludeToken|string|null $includeToken = null,
52+
?IncludeTokenValue $includeToken = null,
5553
array $elts = [],
5654
array $namespacedAttributes = [],
5755
) {
@@ -109,15 +107,9 @@ public static function fromXML(DOMElement $xml): static
109107

110108
$issuer = Issuer::getChildrenOfClass($xml);
111109

112-
$includeToken = self::getOptionalAttribute($xml, 'IncludeToken', StringValue::class, null);
113-
try {
114-
$includeToken = IncludeToken::from($includeToken->getValue());
115-
} catch (ValueError) {
116-
}
117-
118110
return new static(
119111
array_pop($issuer),
120-
$includeToken,
112+
self::getOptionalAttribute($xml, 'IncludeToken', IncludeTokenValue::class, null),
121113
self::getChildElementsFromXML($xml),
122114
self::getAttributesNSFromXML($xml),
123115
);
@@ -135,18 +127,14 @@ public function toXML(?DOMElement $parent = null): DOMElement
135127
$e = $this->instantiateParentElement($parent);
136128

137129
if ($this->getIncludeToken() !== null) {
138-
$e->setAttribute(
139-
'IncludeToken',
140-
is_string($this->getIncludeToken()) ? $this->getIncludeToken() : $this->getIncludeToken()->value,
141-
);
130+
$e->setAttribute('IncludeToken', $this->getIncludeToken()->getValue());
142131
}
143132

144133
if ($this->getIssuer() !== null) {
145134
$this->getIssuer()->toXML($e);
146135
}
147136

148137
foreach ($this->getElements() as $elt) {
149-
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $elt */
150138
$elt->toXML($e);
151139
}
152140

src/XML/sp_200507/AbstractSpnegoContextTokenType.php

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

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9+
use SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue;
910
use SimpleSAML\XML\ExtendableAttributesTrait;
1011
use SimpleSAML\XML\ExtendableElementTrait;
1112
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12-
use SimpleSAML\XMLSchema\Type\StringValue;
1313
use SimpleSAML\XMLSchema\XML\Constants\NS;
14-
use ValueError;
1514

1615
use function array_pop;
17-
use function is_string;
1816
use function sprintf;
1917

2018
/**
@@ -45,13 +43,13 @@ abstract class AbstractSpnegoContextTokenType extends AbstractSpElement
4543
* SpnegoContextTokenType constructor.
4644
*
4745
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Issuer|null $issuer
48-
* @param \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken|string|null $includeToken
46+
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
4947
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts
5048
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
5149
*/
5250
final public function __construct(
5351
protected ?Issuer $issuer,
54-
IncludeToken|string|null $includeToken = null,
52+
?IncludeTokenValue $includeToken = null,
5553
array $elts = [],
5654
array $namespacedAttributes = [],
5755
) {
@@ -109,15 +107,9 @@ public static function fromXML(DOMElement $xml): static
109107

110108
$issuer = Issuer::getChildrenOfClass($xml);
111109

112-
$includeToken = self::getOptionalAttribute($xml, 'IncludeToken', StringValue::class, null);
113-
try {
114-
$includeToken = IncludeToken::from($includeToken->getValue());
115-
} catch (ValueError) {
116-
}
117-
118110
return new static(
119111
array_pop($issuer),
120-
$includeToken,
112+
self::getOptionalAttribute($xml, 'IncludeToken', IncludeTokenValue::class, null),
121113
self::getChildElementsFromXML($xml),
122114
self::getAttributesNSFromXML($xml),
123115
);
@@ -135,10 +127,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
135127
$e = $this->instantiateParentElement($parent);
136128

137129
if ($this->getIncludeToken() !== null) {
138-
$e->setAttribute(
139-
'IncludeToken',
140-
is_string($this->getIncludeToken()) ? $this->getIncludeToken() : $this->getIncludeToken()->value,
141-
);
130+
$e->setAttribute('IncludeToken', $this->getIncludeToken()->getValue());
142131
}
143132

144133
if ($this->getIssuer() !== null) {

src/XML/sp_200507/IncludeTokenTypeTrait.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace SimpleSAML\WSSecurity\XML\sp_200507;
66

7-
use SimpleSAML\WSSecurity\Assert\Assert;
8-
9-
use function is_string;
7+
use SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue;
108

119
/**
1210
* Trait grouping common functionality for elements that can hold IncludeToken attributes.
@@ -18,17 +16,17 @@ trait IncludeTokenTypeTrait
1816
/**
1917
* The included token.
2018
*
21-
* @var \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken|string|null
19+
* @var \SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue|null
2220
*/
23-
protected IncludeToken|string|null $includeToken;
21+
protected ?IncludeTokenValue $includeToken;
2422

2523

2624
/**
2725
* Collect the value of the includeToken-property
2826
*
29-
* @return \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken|string|null
27+
* @return \SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue|null
3028
*/
31-
public function getIncludeToken(): IncludeToken|string|null
29+
public function getIncludeToken(): ?IncludeTokenValue
3230
{
3331
return $this->includeToken;
3432
}
@@ -37,14 +35,10 @@ public function getIncludeToken(): IncludeToken|string|null
3735
/**
3836
* Set the value of the includeToken-property
3937
*
40-
* @param \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken|string|null $includeToken
38+
* @param \SimpleSAML\WSSecurity\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
4139
*/
42-
protected function setIncludeToken(IncludeToken|string|null $includeToken): void
40+
protected function setIncludeToken(?IncludeTokenValue $includeToken = null): void
4341
{
44-
if (is_string($includeToken)) {
45-
Assert::validURI($includeToken);
46-
}
47-
4842
$this->includeToken = $includeToken;
4943
}
5044
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WSSecurity\XML\sp_200507\Type;
6+
7+
use SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken;
8+
use SimpleSAML\XMLSchema\Type\AnyURIValue as BaseAnyURIValue;
9+
10+
/**
11+
* @package simplesaml/ws-security
12+
*/
13+
class IncludeTokenValue extends BaseAnyURIValue
14+
{
15+
/**
16+
* @param \SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken $value
17+
* @return static
18+
*/
19+
public static function fromEnum(IncludeToken $value): static
20+
{
21+
return new static($value->value);
22+
}
23+
}

src/XML/sp_200702/IncludeTokenTypeTrait.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace SimpleSAML\WSSecurity\XML\sp_200702;
66

7-
use SimpleSAML\WSSecurity\Assert\Assert;
8-
9-
use function is_string;
7+
use SimpleSAML\WSSecurity\XML\sp_200702\Type\IncludeTokenValue;
108

119
/**
1210
* Trait grouping common functionality for elements that can hold IncludeToken attributes.
@@ -20,17 +18,17 @@ trait IncludeTokenTypeTrait
2018
/**
2119
* The included token.
2220
*
23-
* @var \SimpleSAML\WSSecurity\XML\sp_200702\IncludeToken|string|null
21+
* @var \SimpleSAML\WSSecurity\XML\sp_200702\Type\IncludeTokenValue|null
2422
*/
25-
protected IncludeToken|string|null $includeToken;
23+
protected ?IncludeTokenValue $includeToken;
2624

2725

2826
/**
2927
* Collect the value of the includeToken-property
3028
*
31-
* @return \SimpleSAML\WSSecurity\XML\sp_200702\IncludeToken|string|null
29+
* @return \SimpleSAML\WSSecurity\XML\sp_200702\Type\IncludeTokenValue|null
3230
*/
33-
public function getIncludeToken(): IncludeToken|string|null
31+
public function getIncludeToken(): ?IncludeTokenValue
3432
{
3533
return $this->includeToken;
3634
}
@@ -39,14 +37,10 @@ public function getIncludeToken(): IncludeToken|string|null
3937
/**
4038
* Set the value of the includeToken-property
4139
*
42-
* @param \SimpleSAML\WSSecurity\XML\sp_200702\IncludeToken|string|null $includeToken
40+
* @param \SimpleSAML\WSSecurity\XML\sp_200702\Type\IncludeTokenValue|null $includeToken
4341
*/
44-
protected function setIncludeToken(IncludeToken|string|null $includeToken): void
42+
protected function setIncludeToken(?IncludeTokenValue $includeToken): void
4543
{
46-
if (is_string($includeToken)) {
47-
Assert::validURI($includeToken);
48-
}
49-
5044
$this->includeToken = $includeToken;
5145
}
5246
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WSSecurity\XML\sp_200702\Type;
6+
7+
use SimpleSAML\WSSecurity\XML\sp_200702\IncludeToken;
8+
use SimpleSAML\XMLSchema\Type\AnyURIValue as BaseAnyURIValue;
9+
10+
/**
11+
* @package simplesaml/ws-security
12+
*/
13+
class IncludeTokenValue extends BaseAnyURIValue
14+
{
15+
/**
16+
* @param \SimpleSAML\WSSecurity\XML\sp_200702\IncludeToken $value
17+
* @return static
18+
*/
19+
public static function fromEnum(IncludeToken $value): static
20+
{
21+
return new static($value->value);
22+
}
23+
}

tests/resources/xml/auth_ConstrainedValueWithValueInRangen.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<auth:ConstrainedValue xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" AssertConstraint="true">
1+
<auth:ConstrainedValue xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" xmlns:ssp="urn:x-simplesamlphp:namespace" AssertConstraint="true">
22
<auth:ValueInRangen>
33
<auth:ValueUpperBound>
4-
<auth:StructuredValue xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">
4+
<auth:StructuredValue ssp:attr1="testval1">
55
<ssp:Chunk>SomeChunk</ssp:Chunk>
66
</auth:StructuredValue>
77
</auth:ValueUpperBound>

tests/resources/xml/auth_ConstrainedValueWithValueOneOf.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<auth:ConstrainedValue xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" AssertConstraint="true">
1+
<auth:ConstrainedValue xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" xmlns:ssp="urn:x-simplesamlphp:namespace" AssertConstraint="true">
22
<auth:ValueOneOf>
3-
<auth:StructuredValue xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">
3+
<auth:StructuredValue ssp:attr1="testval1">
44
<ssp:Chunk>SomeChunk</ssp:Chunk>
55
</auth:StructuredValue>
6-
<auth:StructuredValue xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr2="testval2">
6+
<auth:StructuredValue ssp:attr2="testval2">
77
<ssp:Chunk>SomeOtherChunk</ssp:Chunk>
88
</auth:StructuredValue>
99
</auth:ValueOneOf>

tests/resources/xml/auth_EncryptedValue.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<auth:EncryptedValue xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" DescriptionCondition="urn:some:uri">
2-
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="MyID" Type="http://www.w3.org/2001/04/xmlenc#Element" MimeType="text/plain" Encoding="urn:x-simplesamlphp:encoding">
1+
<auth:EncryptedValue xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" DescriptionCondition="urn:some:uri">
2+
<xenc:EncryptedData Id="MyID" Type="http://www.w3.org/2001/04/xmlenc#Element" MimeType="text/plain" Encoding="urn:x-simplesamlphp:encoding">
33
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
4-
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
4+
<ds:KeyInfo>
55
<xenc:EncryptedKey>
66
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
77
<xenc:CipherData>

0 commit comments

Comments
 (0)