Skip to content

Commit f22862d

Browse files
committed
Fix namespaced IncludeToken-attribute
1 parent 4c1a544 commit f22862d

11 files changed

Lines changed: 37 additions & 63 deletions

src/XML/sp_200507/AbstractIssuedTokenType.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ abstract class AbstractIssuedTokenType extends AbstractSpElement
3535
/** The namespace-attribute for the xs:anyAttribute element */
3636
public const string XS_ANY_ATTR_NAMESPACE = NS::ANY;
3737

38-
/** The exclusions for the xs:anyAttribute element */
39-
public const array XS_ANY_ATTR_EXCLUSIONS = [
40-
['http://schemas.xmlsoap.org/ws/2005/07/securitypolicy', 'IncludeToken'],
41-
];
42-
4338

4439
/**
4540
* IssuedTokenType constructor.
@@ -48,18 +43,16 @@ abstract class AbstractIssuedTokenType extends AbstractSpElement
4843
* \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\RequestSecurityTokenTemplate
4944
* ) $requestSecurityTokenTemplate
5045
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Issuer|null $issuer
51-
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
5246
* @param \SimpleSAML\XML\SerializableElementInterface[] $elts
5347
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
5448
*/
5549
final public function __construct(
5650
protected RequestSecurityTokenTemplate $requestSecurityTokenTemplate,
5751
protected ?Issuer $issuer = null,
58-
?IncludeTokenValue $includeToken = null,
5952
array $elts = [],
6053
array $namespacedAttributes = [],
6154
) {
62-
$this->setIncludeToken($includeToken);
55+
$this->setIncludeToken($namespacedAttributes);
6356
$this->setElements($elts);
6457
$this->setAttributesNS($namespacedAttributes);
6558
}
@@ -114,7 +107,6 @@ public static function fromXML(DOMElement $xml): static
114107
return new static(
115108
$requestSecurityTokenTemplate[0],
116109
array_pop($issuer),
117-
self::getOptionalAttribute($xml, 'IncludeToken', IncludeTokenValue::class, null),
118110
self::getChildElementsFromXML($xml),
119111
self::getAttributesNSFromXML($xml),
120112
);
@@ -128,10 +120,6 @@ public function toXML(?DOMElement $parent = null): DOMElement
128120
{
129121
$e = $this->instantiateParentElement($parent);
130122

131-
if ($this->getIncludeToken() !== null) {
132-
$e->setAttribute('IncludeToken', $this->getIncludeToken()->getValue());
133-
}
134-
135123
if ($this->getIssuer() !== null) {
136124
$this->getIssuer()->toXML($e);
137125
}

src/XML/sp_200507/AbstractSecureConversationTokenType.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,20 @@ abstract class AbstractSecureConversationTokenType extends AbstractSpElement
3333
/** The namespace-attribute for the xs:anyAttribute element */
3434
public const string XS_ANY_ATTR_NAMESPACE = NS::ANY;
3535

36-
/** The exclusions for the xs:anyAttribute element */
37-
public const array XS_ANY_ATTR_EXCLUSIONS = [
38-
['http://schemas.xmlsoap.org/ws/2005/07/securitypolicy', 'IncludeToken'],
39-
];
40-
4136

4237
/**
4338
* SecureConversationTokenType constructor.
4439
*
4540
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Issuer|null $issuer
46-
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
4741
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts
4842
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
4943
*/
5044
final public function __construct(
5145
protected ?Issuer $issuer,
52-
?IncludeTokenValue $includeToken = null,
5346
array $elts = [],
5447
array $namespacedAttributes = [],
5548
) {
56-
$this->setIncludeToken($includeToken);
49+
$this->setIncludeToken($namespacedAttributes);
5750
$this->setElements($elts);
5851
$this->setAttributesNS($namespacedAttributes);
5952
}
@@ -76,7 +69,6 @@ public function getIssuer(): ?Issuer
7669
public function isEmptyElement(): bool
7770
{
7871
return empty($this->getIssuer())
79-
&& empty($this->getIncludeToken())
8072
&& empty($this->getAttributesNS())
8173
&& empty($this->getElements());
8274
}
@@ -104,7 +96,6 @@ public static function fromXML(DOMElement $xml): static
10496

10597
return new static(
10698
array_pop($issuer),
107-
self::getOptionalAttribute($xml, 'IncludeToken', IncludeTokenValue::class, null),
10899
self::getChildElementsFromXML($xml),
109100
self::getAttributesNSFromXML($xml),
110101
);
@@ -118,10 +109,6 @@ public function toXML(?DOMElement $parent = null): DOMElement
118109
{
119110
$e = $this->instantiateParentElement($parent);
120111

121-
if ($this->getIncludeToken() !== null) {
122-
$e->setAttribute('IncludeToken', $this->getIncludeToken()->getValue());
123-
}
124-
125112
if ($this->getIssuer() !== null) {
126113
$this->getIssuer()->toXML($e);
127114
}

src/XML/sp_200507/AbstractSpnegoContextTokenType.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,20 @@ abstract class AbstractSpnegoContextTokenType extends AbstractSpElement
3333
/** The namespace-attribute for the xs:anyAttribute element */
3434
public const string XS_ANY_ATTR_NAMESPACE = NS::ANY;
3535

36-
/** The exclusions for the xs:anyAttribute element */
37-
public const array XS_ANY_ATTR_EXCLUSIONS = [
38-
['http://schemas.xmlsoap.org/ws/2005/07/securitypolicy', 'IncludeToken'],
39-
];
40-
4136

4237
/**
4338
* SpnegoContextTokenType constructor.
4439
*
4540
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Issuer|null $issuer
46-
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
4741
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts
4842
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
4943
*/
5044
final public function __construct(
5145
protected ?Issuer $issuer,
52-
?IncludeTokenValue $includeToken = null,
5346
array $elts = [],
5447
array $namespacedAttributes = [],
5548
) {
56-
$this->setIncludeToken($includeToken);
49+
$this->setIncludeToken($namespacedAttributes);
5750
$this->setElements($elts);
5851
$this->setAttributesNS($namespacedAttributes);
5952
}
@@ -76,7 +69,6 @@ public function getIssuer(): ?Issuer
7669
public function isEmptyElement(): bool
7770
{
7871
return empty($this->getIssuer())
79-
&& empty($this->getIncludeToken())
8072
&& empty($this->getAttributesNS())
8173
&& empty($this->getElements());
8274
}
@@ -104,7 +96,6 @@ public static function fromXML(DOMElement $xml): static
10496

10597
return new static(
10698
array_pop($issuer),
107-
self::getOptionalAttribute($xml, 'IncludeToken', IncludeTokenValue::class, null),
10899
self::getChildElementsFromXML($xml),
109100
self::getAttributesNSFromXML($xml),
110101
);
@@ -118,10 +109,6 @@ public function toXML(?DOMElement $parent = null): DOMElement
118109
{
119110
$e = $this->instantiateParentElement($parent);
120111

121-
if ($this->getIncludeToken() !== null) {
122-
$e->setAttribute('IncludeToken', $this->getIncludeToken()->getValue());
123-
}
124-
125112
if ($this->getIssuer() !== null) {
126113
$this->getIssuer()->toXML($e);
127114
}

src/XML/sp_200507/IncludeTokenTypeTrait.php

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

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7+
use SimpleSAML\WebServices\SecurityPolicy\Constants as C;
78
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue;
89

910
/**
@@ -18,7 +19,7 @@ trait IncludeTokenTypeTrait
1819
*
1920
* @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue|null
2021
*/
21-
protected ?IncludeTokenValue $includeToken;
22+
protected ?IncludeTokenValue $includeToken = null;
2223

2324

2425
/**
@@ -35,10 +36,15 @@ public function getIncludeToken(): ?IncludeTokenValue
3536
/**
3637
* Set the value of the includeToken-property
3738
*
38-
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue|null $includeToken
39+
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
3940
*/
40-
protected function setIncludeToken(?IncludeTokenValue $includeToken = null): void
41+
protected function setIncludeToken(array $namespacedAttributes = []): void
4142
{
42-
$this->includeToken = $includeToken;
43+
foreach ($namespacedAttributes as $attr) {
44+
if ($attr->getNamespaceURI() === C::NS_SEC_POLICY_11 && $attr->getAttrName() === 'IncludeToken') {
45+
$this->includeToken = IncludeTokenValue::fromString($attr->getAttrValue()->getValue());
46+
return;
47+
}
48+
}
4349
}
4450
}

src/XML/sp_200702/IncludeTokenTypeTrait.php

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

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702;
66

7+
use SimpleSAML\WebServices\SecurityPolicy\Constants as C;
78
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\Type\IncludeTokenValue;
89

910
/**
@@ -37,10 +38,15 @@ public function getIncludeToken(): ?IncludeTokenValue
3738
/**
3839
* Set the value of the includeToken-property
3940
*
40-
* @param \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\Type\IncludeTokenValue|null $includeToken
41+
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
4142
*/
42-
protected function setIncludeToken(?IncludeTokenValue $includeToken): void
43+
protected function setIncludeToken(array $namespacedAttributes = []): void
4344
{
44-
$this->includeToken = $includeToken;
45+
foreach ($namespacedAttributes as $attr) {
46+
if ($attr->getNamespaceURI() === C::NS_SEC_POLICY_12 && $attr->getAttrName() === 'IncludeToken') {
47+
$this->includeToken = IncludeTokenValue::fromString($attr->getAttrValue()->getValue());
48+
return;
49+
}
50+
}
4551
}
4652
}

tests/SecurityPolicy/XML/sp_200507/IssuedTokenTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public function testMarshallingElementOrdering(): void
114114
[$attr1],
115115
);
116116

117+
$includeToken = IncludeTokenValue::fromEnum(IncludeToken::Always)->toAttribute();
117118
$issuedToken = new IssuedToken(
118119
$requestSecurityTokenTemplate,
119120
$issuer,
120-
IncludeTokenValue::fromEnum(IncludeToken::Always),
121121
[$chunk],
122-
[$attr1],
122+
[$includeToken, $attr1],
123123
);
124124
$issuedTokenElement = $issuedToken->toXML();
125125

@@ -181,12 +181,12 @@ public function testMarshalling(): void
181181
[$attr1],
182182
);
183183

184+
$includeToken = IncludeTokenValue::fromEnum(IncludeToken::Always)->toAttribute();
184185
$issuedToken = new IssuedToken(
185186
$requestSecurityTokenTemplate,
186187
$issuer,
187-
IncludeTokenValue::fromEnum(IncludeToken::Always),
188188
[$chunk],
189-
[$attr1],
189+
[$includeToken, $attr1],
190190
);
191191

192192
$this->assertEquals(

tests/SecurityPolicy/XML/sp_200507/SecureConversationTokenTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public function testMarshallingElementOrdering(): void
107107
[$attr2],
108108
);
109109

110+
$includeToken = IncludeTokenValue::fromEnum(IncludeToken::Always)->toAttribute();
110111
$secureConversationToken = new SecureConversationToken(
111112
$issuer,
112-
IncludeTokenValue::fromEnum(IncludeToken::Always),
113113
[$chunk],
114-
[$attr1],
114+
[$includeToken, $attr1],
115115
);
116116
$secureConversationTokenElement = $secureConversationToken->toXML();
117117

@@ -170,11 +170,11 @@ public function testMarshalling(): void
170170
[$attr2],
171171
);
172172

173+
$includeToken = IncludeTokenValue::fromEnum(IncludeToken::Always)->toAttribute();
173174
$secureConversationToken = new SecureConversationToken(
174175
$issuer,
175-
IncludeTokenValue::fromEnum(IncludeToken::Always),
176176
[$chunk],
177-
[$attr1],
177+
[$includeToken, $attr1],
178178
);
179179

180180
$this->assertEquals(

tests/SecurityPolicy/XML/sp_200507/SpnegoContextTokenTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public function testMarshallingElementOrdering(): void
107107
[$attr2],
108108
);
109109

110+
$includeToken = IncludeTokenValue::fromEnum(IncludeToken::Always)->toAttribute();
110111
$spnegoContextToken = new SpnegoContextToken(
111112
$issuer,
112-
IncludeTokenValue::fromEnum(IncludeToken::Always),
113113
[$chunk],
114-
[$attr1],
114+
[$includeToken, $attr1],
115115
);
116116
$spnegoContextTokenElement = $spnegoContextToken->toXML();
117117

@@ -170,11 +170,11 @@ public function testMarshalling(): void
170170
[$attr2],
171171
);
172172

173+
$includeToken = IncludeTokenValue::fromEnum(IncludeToken::Always)->toAttribute();
173174
$spnegoContextToken = new SpnegoContextToken(
174175
$issuer,
175-
IncludeTokenValue::fromEnum(IncludeToken::Always),
176176
[$chunk],
177-
[$attr1],
177+
[$includeToken, $attr1],
178178
);
179179

180180
$this->assertEquals(

tests/resources/xml/sp/200507/IssuedToken.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<sp:IssuedToken xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:m="https://www.w3schools.com/prices" IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" ssp:test1="value1">
1+
<sp:IssuedToken xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:m="https://www.w3schools.com/prices" sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" ssp:test1="value1">
22
<sp:Issuer ssp:test2="value2">
33
<wsa:Address ssp:test2="value2">https://login.microsoftonline.com/login.srf</wsa:Address>
44
<wsa:ReferenceProperties>

tests/resources/xml/sp/200507/SecureConversationToken.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<sp:SecureConversationToken xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:m="https://www.w3schools.com/prices" IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" ssp:test1="value1">
1+
<sp:SecureConversationToken xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:m="https://www.w3schools.com/prices" sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" ssp:test1="value1">
22
<sp:Issuer ssp:test2="value2">
33
<wsa:Address ssp:test2="value2">https://login.microsoftonline.com/login.srf</wsa:Address>
44
<wsa:ReferenceProperties>

0 commit comments

Comments
 (0)