Skip to content

Commit 886e2a5

Browse files
committed
Use local versions of StringElementTrait and URIElementTrait to comply with stricter SAML 1.1 specs
1 parent e48584f commit 886e2a5

9 files changed

Lines changed: 92 additions & 60 deletions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML11\XML;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\SAML11\Exception\ProtocolViolationException;
9+
use SimpleSAML\XML\StringElementTrait as BaseStringElementTrait;
10+
11+
/**
12+
* Trait extending the default StringElementTrait to comply with the restrictions added by the SAML 1.1 specifications.
13+
*
14+
* @package simplesamlphp/saml11
15+
*/
16+
trait StringElementTrait
17+
{
18+
use BaseStringElementTrait;
19+
20+
/**
21+
* Validate the content of the element.
22+
*
23+
* @param string $content The value to go in the XML textContent
24+
* @throws \Exception on failure
25+
* @return void
26+
*/
27+
protected function validateContent(/** @scrutinizer ignore-unused */ string $content): void
28+
{
29+
/**
30+
* 1.2.1 String and URI Values
31+
*
32+
* All SAML string and URI reference values have the types xsd:string and xsd:anyURI respectively, which
33+
* are built in to the W3C XML Schema Datatypes specification [Schema2]. All strings in SAML messages
34+
* MUST consist of at least one non-whitespace character (whitespace is defined in the XML
35+
* Recommendation [XML] §2.3). Empty and whitespace-only values are disallowed.
36+
*/
37+
Assert::notWhitespaceOnly($content, ProtocolViolationException::class);
38+
}
39+
}

src/SAML11/XML/URIElementTrait.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML11\XML;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\SAML11\Exception\ProtocolViolationException;
9+
use SimpleSAML\XML\Exception\SchemaViolationException;
10+
use SimpleSAML\XML\URIElementTrait as BaseURIElementTrait;
11+
12+
/**
13+
* Trait extending the default URIElementTrait to comply with the restrictions added by the SAML 1.1 specifications.
14+
*
15+
* @package simplesamlphp/saml11
16+
*/
17+
trait URIElementTrait
18+
{
19+
use BaseURIElementTrait;
20+
21+
/**
22+
* Validate the content of the element.
23+
*
24+
* @param string $content The value to go in the XML textContent
25+
* @throws \Exception on failure
26+
* @return void
27+
*/
28+
protected function validateContent(string $content): void
29+
{
30+
/**
31+
* 1.2.1 String and URI Values
32+
*
33+
* All SAML string and URI reference values have the types xsd:string and xsd:anyURI respectively, which
34+
* are built in to the W3C XML Schema Datatypes specification [Schema2]. All strings in SAML messages
35+
* MUST consist of at least one non-whitespace character (whitespace is defined in the XML
36+
* Recommendation [XML] §2.3). Empty and whitespace-only values are disallowed. Also, unless otherwise
37+
* indicated in this specification, all URI reference values MUST consist of at least one non-whitespace
38+
* character, and are strongly RECOMMENDED to be absolute [RFC 2396].
39+
*/
40+
Assert::notWhitespaceOnly($content, ProtocolViolationException::class);
41+
Assert::validURI($content, SchemaViolationException::class);
42+
}
43+
}

src/SAML11/XML/saml/AbstractActionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\SAML11\XML\StringElementTrait;
910
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1011
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
use SimpleSAML\XML\StringElementTrait;
1212

1313
/**
1414
* SAML ActionType abstract data type.

src/SAML11/XML/saml/AbstractNameIdentifierType.php

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

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\SAML11\XML\StringElementTrait;
910
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\StringElementTrait;
1111

1212
/**
1313
* SAML NameIdentifierType abstract data type.

src/SAML11/XML/saml/AssertionIDReference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\SAML11\XML\StringElementTrait;
910
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1011
use SimpleSAML\XML\Exception\SchemaViolationException;
1112
use SimpleSAML\XML\SchemaValidatableElementInterface;
1213
use SimpleSAML\XML\SchemaValidatableElementTrait;
13-
use SimpleSAML\XML\StringElementTrait;
1414

1515
/**
1616
* Class representing a saml:AssertionIDReference element.

src/SAML11/XML/saml/Audience.php

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

55
namespace SimpleSAML\SAML11\XML\saml;
66

7+
use SimpleSAML\SAML11\XML\URIElementTrait;
78
use SimpleSAML\XML\SchemaValidatableElementInterface;
89
use SimpleSAML\XML\SchemaValidatableElementTrait;
9-
use SimpleSAML\XML\StringElementTrait;
1010

1111
/**
1212
* SAML Audience element.
@@ -16,7 +16,7 @@
1616
final class Audience extends AbstractSamlElement implements SchemaValidatableElementInterface
1717
{
1818
use SchemaValidatableElementTrait;
19-
use StringElementTrait;
19+
use URIElementTrait;
2020

2121

2222
/**

src/SAML11/XML/saml/ConfirmationMethod.php

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

55
namespace SimpleSAML\SAML11\XML\saml;
66

7-
use DOMElement;
8-
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\SchemaViolationException;
7+
use SimpleSAML\SAML11\XML\URIElementTrait;
118
use SimpleSAML\XML\SchemaValidatableElementInterface;
129
use SimpleSAML\XML\SchemaValidatableElementTrait;
13-
use SimpleSAML\XML\StringElementTrait;
1410

1511
/**
1612
* Class representing a saml:ConfirmationMethod element.
@@ -20,7 +16,7 @@
2016
final class ConfirmationMethod extends AbstractSamlElement implements SchemaValidatableElementInterface
2117
{
2218
use SchemaValidatableElementTrait;
23-
use StringElementTrait;
19+
use URIElementTrait;
2420

2521

2622
/**
@@ -30,50 +26,4 @@ public function __construct(string $content)
3026
{
3127
$this->setContent($content);
3228
}
33-
34-
35-
/**
36-
* Validate the content of the element.
37-
*
38-
* @param string $content The value to go in the XML textContent
39-
* @throws \Exception on failure
40-
* @return void
41-
*/
42-
protected function validateContent(string $content): void
43-
{
44-
Assert::validNCName($content, SchemaViolationException::class); // Covers the empty string
45-
}
46-
47-
48-
/**
49-
* Convert XML into an ConfirmationMethod
50-
*
51-
* @param \DOMElement $xml The XML element we should load
52-
* @return static
53-
*
54-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
55-
* If the qualified name of the supplied element is wrong
56-
*/
57-
public static function fromXML(DOMElement $xml): static
58-
{
59-
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
60-
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
61-
62-
return new static($xml->textContent);
63-
}
64-
65-
66-
/**
67-
* Convert this ConfirmationMethod to XML.
68-
*
69-
* @param \DOMElement $parent The element we are converting to XML.
70-
* @return \DOMElement The XML element after adding the data corresponding to this ConfirmationMethod.
71-
*/
72-
public function toXML(?DOMElement $parent = null): DOMElement
73-
{
74-
$element = $this->instantiateParentElement($parent);
75-
$element->textContent = $this->getContent();
76-
77-
return $element;
78-
}
7929
}

src/SAML11/XML/samlp/AssertionArtifact.php

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

55
namespace SimpleSAML\SAML11\XML\samlp;
66

7+
use SimpleSAML\SAML11\XML\StringElementTrait;
78
use SimpleSAML\XML\SchemaValidatableElementInterface;
89
use SimpleSAML\XML\SchemaValidatableElementTrait;
9-
use SimpleSAML\XML\StringElementTrait;
1010

1111
/**
1212
* SAML AssertionArtifact element.
@@ -21,7 +21,7 @@ final class AssertionArtifact extends AbstractSamlpElement implements SchemaVali
2121

2222

2323
/**
24-
* Initialize a saml:AssertionArtifac from scratch
24+
* Initialize a saml:AssertionArtifact from scratch
2525
*
2626
* @param string $value
2727
*/

src/SAML11/XML/samlp/StatusMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\SAML11\XML\StringElementTrait;
910
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1011
use SimpleSAML\XML\SchemaValidatableElementInterface;
1112
use SimpleSAML\XML\SchemaValidatableElementTrait;
12-
use SimpleSAML\XML\StringElementTrait;
1313

1414
/**
1515
* Class representing a samlp:StatusMessage element.

0 commit comments

Comments
 (0)