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

Commit 10c49cf

Browse files
committed
Migrate wsse to xsd-types
1 parent 06ce0aa commit 10c49cf

24 files changed

Lines changed: 167 additions & 130 deletions

src/XML/wsse/AbstractAttributedString.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
use SimpleSAML\XML\Attribute as XMLAttribute;
1111
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1212
use SimpleSAML\XML\ExtendableAttributesTrait;
13-
use SimpleSAML\XML\StringElementTrait;
13+
use SimpleSAML\XML\TypedTextContentTrait;
1414
use SimpleSAML\XML\XsNamespace as NS;
15+
use SimpleSAML\XMLSchema\Type\IDValue;
16+
use SimpleSAML\XMLSchema\Type\StringValue;
1517

1618
use function array_unshift;
1719

@@ -25,35 +27,37 @@
2527
abstract class AbstractAttributedString extends AbstractWsseElement
2628
{
2729
use ExtendableAttributesTrait;
28-
use StringElementTrait;
30+
use TypedTextContentTrait;
31+
2932

3033
/** The namespace-attribute for the xs:anyAttribute element */
3134
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
3235

36+
/** @var string */
37+
public const TEXTCONTENT_TYPE = StringValue::class;
38+
3339

3440
/**
3541
* AbstractAttributedString constructor
3642
*
37-
* @param string $content
38-
* @param string|null $Id
43+
* @param \SimpleSAML\XMLSchema\Type\StringValue $content
44+
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
3945
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
4046
*/
4147
public function __construct(
42-
string $content,
43-
protected ?string $Id = null,
48+
StringValue $content,
49+
protected ?IDValue $Id = null,
4450
array $namespacedAttributes = [],
4551
) {
46-
Assert::nullOrValidNCName($Id);
47-
4852
$this->setContent($content);
4953
$this->setAttributesNS($namespacedAttributes);
5054
}
5155

5256

5357
/**
54-
* @return string|null
58+
* @return \SimpleSAML\XMLSchema\Type\IDValue|null
5559
*/
56-
public function getId(): ?string
60+
public function getId(): ?IDValue
5761
{
5862
return $this->Id;
5963
}
@@ -95,7 +99,7 @@ public static function fromXML(DOMElement $xml): static
9599
public function toXML(?DOMElement $parent = null): DOMElement
96100
{
97101
$e = $this->instantiateParentElement($parent);
98-
$e->textContent = $this->getContent();
102+
$e->textContent = $this->getContent()->getValue();
99103

100104
$attributes = $this->getAttributesNS();
101105
if ($this->getId() !== null) {

src/XML/wsse/AbstractBinarySecurityTokenType.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\WSSecurity\Constants as C;
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XML\Exception\SchemaViolationException;
1211
use SimpleSAML\XML\XsNamespace as NS;
12+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13+
use SimpleSAML\XMLSchema\Type\IDValue;
14+
use SimpleSAML\XMLSchema\Type\StringValue;
1315

1416
/**
1517
* Class defining the BinarySecurityTokenType element
@@ -25,29 +27,28 @@ abstract class AbstractBinarySecurityTokenType extends AbstractEncodedString
2527
/**
2628
* AbstractBinarySecurityTokenType constructor
2729
*
28-
* @param string $content
29-
* @param string|null $valueType
30-
* @param string|null $Id
31-
* @param string|null $EncodingType
30+
* @param \SimpleSAML\XMLSchema\Type\StringValue $content
31+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $valueType
32+
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
33+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $EncodingType
3234
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
3335
*/
3436
final public function __construct(
35-
string $content,
36-
protected ?string $valueType = null,
37-
?string $Id = null,
37+
StringValue $content,
38+
protected ?AnyURIValue $valueType = null,
39+
?IDValue $Id = null,
3840
?string $EncodingType = null,
3941
array $namespacedAttributes = [],
4042
) {
41-
Assert::nullOrValidURI($valueType, SchemaViolationException::class);
42-
43+
Assert::validBase64Binary($content->getValue());
4344
parent::__construct($content, $Id, $EncodingType, $namespacedAttributes);
4445
}
4546

4647

4748
/**
48-
* @return string|null
49+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
4950
*/
50-
public function getValueType(): ?string
51+
public function getValueType(): ?AnyURIValue
5152
{
5253
return $this->valueType;
5354
}
@@ -79,10 +80,10 @@ public static function fromXML(DOMElement $xml): static
7980
}
8081

8182
return new static(
82-
$xml->textContent,
83-
self::getOptionalAttribute($xml, 'ValueType', null),
83+
StringValue::fromString($xml->textContent),
84+
self::getOptionalAttribute($xml, 'ValueType', AnyURIValue::class, null),
8485
$Id,
85-
self::getOptionalAttribute($xml, 'EncodingType', null),
86+
self::getOptionalAttribute($xml, 'EncodingType', AnyURIValue::class, null),
8687
$nsAttributes,
8788
);
8889
}
@@ -99,7 +100,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
99100
$e = parent::toXML($parent);
100101

101102
if ($this->getValueType() !== null) {
102-
$e->setAttribute('ValueType', $this->getValueType());
103+
$e->setAttribute('ValueType', $this->getValueType()->getValue());
103104
}
104105

105106
return $e;

src/XML/wsse/AbstractEmbeddedType.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\SchemaViolationException;
1110
use SimpleSAML\XML\ExtendableAttributesTrait;
1211
use SimpleSAML\XML\ExtendableElementTrait;
1312
use SimpleSAML\XML\XsNamespace as NS;
13+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
1414

1515
/**
1616
* Class defining the EmbeddedType element
@@ -22,6 +22,7 @@ abstract class AbstractEmbeddedType extends AbstractWsseElement
2222
use ExtendableAttributesTrait;
2323
use ExtendableElementTrait;
2424

25+
2526
/** The namespace-attribute for the xs:anyAttribute element */
2627
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
2728

@@ -32,26 +33,24 @@ abstract class AbstractEmbeddedType extends AbstractWsseElement
3233
/**
3334
* AbstractEmbeddedType constructor
3435
*
35-
* @param string|null $valueType
36+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $valueType
3637
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children
3738
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
3839
*/
3940
final public function __construct(
40-
protected ?string $valueType = null,
41+
protected ?AnyURIValue $valueType = null,
4142
array $children = [],
4243
array $namespacedAttributes = [],
4344
) {
44-
Assert::nullOrValidURI($valueType, SchemaViolationException::class);
45-
4645
$this->setElements($children);
4746
$this->setAttributesNS($namespacedAttributes);
4847
}
4948

5049

5150
/**
52-
* @return string|null
51+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
5352
*/
54-
public function getValueType(): ?string
53+
public function getValueType(): ?AnyURIValue
5554
{
5655
return $this->valueType;
5756
}
@@ -85,7 +84,7 @@ public static function fromXML(DOMElement $xml): static
8584
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
8685

8786
return new static(
88-
self::getOptionalAttribute($xml, 'ValueType', null),
87+
self::getOptionalAttribute($xml, 'ValueType', AnyURIValue::class, null),
8988
self::getChildElementsFromXML($xml),
9089
self::getAttributesNSFromXML($xml),
9190
);
@@ -103,7 +102,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
103102
$e = parent::instantiateParentElement($parent);
104103

105104
if ($this->getValueType() !== null) {
106-
$e->setAttribute('ValueType', $this->getValueType());
105+
$e->setAttribute('ValueType', $this->getValueType()->getValue());
107106
}
108107

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

src/XML/wsse/AbstractEncodedString.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\WSSecurity\Constants as C;
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
12+
use SimpleSAML\XMLSchema\Type\IDValue;
13+
use SimpleSAML\XMLSchema\Type\StringValue;
1114

1215
/**
1316
* Abstract class defining the EncodedString type
@@ -21,27 +24,25 @@ abstract class AbstractEncodedString extends AbstractAttributedString
2124
/**
2225
* AbstractEncodedString constructor
2326
*
24-
* @param string $content
25-
* @param string|null $Id
26-
* @param string|null $EncodingType
27+
* @param \SimpleSAML\XMLSchema\Type\StringValue $content
28+
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
29+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $EncodingType
2730
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
2831
*/
2932
public function __construct(
30-
string $content,
31-
?string $Id = null,
32-
protected ?string $EncodingType = null,
33+
StringValue $content,
34+
?IDValue $Id = null,
35+
protected ?AnyURIValue $EncodingType = null,
3336
array $namespacedAttributes = [],
3437
) {
35-
Assert::nullOrValidURI($EncodingType);
36-
3738
parent::__construct($content, $Id, $namespacedAttributes);
3839
}
3940

4041

4142
/**
42-
* @return string|null
43+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
4344
*/
44-
public function getEncodingType(): ?string
45+
public function getEncodingType(): ?AnyURIValue
4546
{
4647
return $this->EncodingType;
4748
}
@@ -90,7 +91,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
9091
$e = parent::toXML($parent);
9192

9293
if ($this->getEncodingType() !== null) {
93-
$e->setAttribute('EncodingType', $this->getEncodingType());
94+
$e->setAttribute('EncodingType', $this->getEncodingType()->getValue());
9495
}
9596

9697
return $e;

src/XML/wsse/AbstractKeyIdentifierType.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\WSSecurity\Constants as C;
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XML\Exception\SchemaViolationException;
11+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
12+
use SimpleSAML\XMLSchema\Type\IDValue;
13+
use SimpleSAML\XMLSchema\Type\StringValue;
1214

1315
/**
1416
* Class defining the KeyIdentifierType element
@@ -20,29 +22,27 @@ abstract class AbstractKeyIdentifierType extends AbstractEncodedString
2022
/**
2123
* AbstractKeyIdentifierType constructor
2224
*
23-
* @param string $content
24-
* @param string|null $valueType
25-
* @param string|null $Id
26-
* @param string|null $EncodingType
25+
* @param \SimpleSAML\XMLSchema\Type\StringValue $content
26+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $valueType
27+
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
28+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $EncodingType
2729
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
2830
*/
2931
final public function __construct(
30-
string $content,
31-
protected ?string $valueType = null,
32-
?string $Id = null,
33-
?string $EncodingType = null,
32+
StringValue $content,
33+
protected ?AnyURIValue $valueType = null,
34+
?IDValue $Id = null,
35+
?AnyURIValue $EncodingType = null,
3436
array $namespacedAttributes = [],
3537
) {
36-
Assert::nullOrValidURI($valueType, SchemaViolationException::class);
37-
3838
parent::__construct($content, $Id, $EncodingType, $namespacedAttributes);
3939
}
4040

4141

4242
/**
43-
* @return string|null
43+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
4444
*/
45-
public function getValueType(): ?string
45+
public function getValueType(): ?AnyURIValue
4646
{
4747
return $this->valueType;
4848
}
@@ -74,10 +74,10 @@ public static function fromXML(DOMElement $xml): static
7474
}
7575

7676
return new static(
77-
$xml->textContent,
78-
self::getOptionalAttribute($xml, 'ValueType', null),
77+
StringValue::fromString($xml->textContent),
78+
self::getOptionalAttribute($xml, 'ValueType', AnyURIValue::class, null),
7979
$Id,
80-
self::getOptionalAttribute($xml, 'EncodingType', null),
80+
self::getOptionalAttribute($xml, 'EncodingType', AnyURIValue::class, null),
8181
$nsAttributes,
8282
);
8383
}
@@ -94,7 +94,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
9494
$e = parent::toXML($parent);
9595

9696
if ($this->getValueType() !== null) {
97-
$e->setAttribute('ValueType', $this->getValueType());
97+
$e->setAttribute('ValueType', $this->getValueType()->getValue());
9898
}
9999

100100
return $e;

0 commit comments

Comments
 (0)