|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\shibmd; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\SAML2\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\SAML2\Type\SAMLStringValue; |
|
10
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
|
11
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
|
12
|
|
|
use SimpleSAML\XML\TypedTextContentTrait; |
|
13
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
|
14
|
|
|
use SimpleSAML\XMLSchema\Type\BooleanValue; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class which represents the Scope element found in Shibboleth metadata. |
|
18
|
|
|
* |
|
19
|
|
|
* @link https://wiki.shibboleth.net/confluence/display/SC/ShibMetaExt+V1.0 |
|
20
|
|
|
* @package simplesamlphp/saml2 |
|
21
|
|
|
*/ |
|
22
|
|
|
final class Scope extends AbstractShibmdElement implements SchemaValidatableElementInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use SchemaValidatableElementTrait; |
|
25
|
|
|
use TypedTextContentTrait; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
public const TEXTCONTENT_TYPE = SAMLStringValue::class; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Create a Scope. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \SimpleSAML\SAML2\Type\SAMLStringValue $scope |
|
36
|
|
|
* @param \SimpleSAML\XMLSchema\Type\BooleanValue|null $regexp |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( |
|
39
|
|
|
SAMLStringValue $scope, |
|
40
|
|
|
protected ?BooleanValue $regexp = null, |
|
41
|
|
|
) { |
|
42
|
|
|
$this->setContent($scope); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Collect the value of the regexp-property |
|
48
|
|
|
* |
|
49
|
|
|
* @return \SimpleSAML\XMLSchema\Type\BooleanValue|null |
|
50
|
|
|
*/ |
|
51
|
|
|
public function isRegexpScope(): ?BooleanValue |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->regexp; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Convert XML into a Scope |
|
59
|
|
|
* |
|
60
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
61
|
|
|
* @return static |
|
62
|
|
|
* |
|
63
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
64
|
|
|
* if the qualified name of the supplied element is wrong |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function fromXML(DOMElement $xml): static |
|
67
|
|
|
{ |
|
68
|
|
|
Assert::same($xml->localName, 'Scope', InvalidDOMElementException::class); |
|
69
|
|
|
Assert::same($xml->namespaceURI, Scope::NS, InvalidDOMElementException::class); |
|
70
|
|
|
|
|
71
|
|
|
return new static( |
|
72
|
|
|
SAMLStringValue::fromString($xml->textContent), |
|
73
|
|
|
self::getOptionalAttribute($xml, 'regexp', BooleanValue::class, null), |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Convert this Scope to XML. |
|
80
|
|
|
* |
|
81
|
|
|
* @param \DOMElement|null $parent The element we should append this Scope to. |
|
82
|
|
|
* @return \DOMElement |
|
83
|
|
|
*/ |
|
84
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
85
|
|
|
{ |
|
86
|
|
|
$e = $this->instantiateParentElement($parent); |
|
87
|
|
|
$e->textContent = strval($this->getContent()); |
|
88
|
|
|
|
|
89
|
|
|
if ($this->isRegexpScope() !== null) { |
|
90
|
|
|
$e->setAttribute('regexp', strval($this->isRegexpScope())); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $e; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|