|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\saml; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\SAML2\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\SAML2\Constants as C; |
|
10
|
|
|
use SimpleSAML\SAML2\Exception\ProtocolViolationException; |
|
11
|
|
|
use SimpleSAML\SAML2\Type\SAMLAnyURIValue; |
|
12
|
|
|
use SimpleSAML\SAML2\Type\SAMLStringValue; |
|
13
|
|
|
use SimpleSAML\XML\TypedTextContentTrait; |
|
14
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
|
15
|
|
|
|
|
16
|
|
|
use function array_column; |
|
17
|
|
|
use function strval; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class representing SAML2 Action |
|
21
|
|
|
* |
|
22
|
|
|
* @package simplesamlphp/saml2 |
|
23
|
|
|
*/ |
|
24
|
|
|
final class Action extends AbstractSamlElement |
|
25
|
|
|
{ |
|
26
|
|
|
use TypedTextContentTrait; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
public const string TEXTCONTENT_TYPE = SAMLStringValue::class; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Initialize an Action. |
|
34
|
|
|
* |
|
35
|
|
|
* NOTE: The namespace-attribute was marked REQUIRED in the 2012 SAML errata (E36) |
|
36
|
|
|
* |
|
37
|
|
|
* @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $namespace |
|
38
|
|
|
* @param \SimpleSAML\SAML2\Type\SAMLStringValue $content |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
protected SAMLAnyURIValue $namespace, |
|
42
|
|
|
SAMLStringValue $content, |
|
43
|
|
|
) { |
|
44
|
|
|
if ($namespace->equals(C::ACTION_RWEDC)) { |
|
45
|
|
|
Assert::oneOf( |
|
46
|
|
|
$content->getValue(), |
|
47
|
|
|
array_column(RWEDCEnum::cases(), 'value'), |
|
48
|
|
|
ProtocolViolationException::class, |
|
49
|
|
|
); |
|
50
|
|
|
} elseif ($namespace->equals(C::ACTION_RWEDC_NEGATION)) { |
|
51
|
|
|
Assert::oneOf( |
|
52
|
|
|
$content->getValue(), |
|
53
|
|
|
array_column(RWEDCNegationEnum::cases(), 'value'), |
|
54
|
|
|
ProtocolViolationException::class, |
|
55
|
|
|
); |
|
56
|
|
|
} elseif ($namespace->equals(C::ACTION_GHPP)) { |
|
57
|
|
|
Assert::oneOf( |
|
58
|
|
|
$content->getValue(), |
|
59
|
|
|
array_column(GHPPEnum::cases(), 'value'), |
|
60
|
|
|
ProtocolViolationException::class, |
|
61
|
|
|
); |
|
62
|
|
|
} elseif ($namespace->equals(C::ACTION_UNIX)) { |
|
63
|
|
|
Assert::regex( |
|
64
|
|
|
$content->getValue(), |
|
65
|
|
|
'/^[0-7]{4}$/', |
|
66
|
|
|
ProtocolViolationException::class, |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->setContent($content); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Collect the value of the namespace-property |
|
76
|
|
|
* |
|
77
|
|
|
* @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getNamespace(): SAMLAnyURIValue |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->namespace; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Convert XML into a Action |
|
87
|
|
|
* |
|
88
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
89
|
|
|
* if the qualified name of the supplied element is wrong |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function fromXML(DOMElement $xml): static |
|
92
|
|
|
{ |
|
93
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
94
|
|
|
Assert::same($xml->namespaceURI, Action::NS, InvalidDOMElementException::class); |
|
95
|
|
|
|
|
96
|
|
|
return new self( |
|
97
|
|
|
self::getAttribute($xml, 'Namespace', SAMLAnyURIValue::class), |
|
98
|
|
|
SAMLStringValue::fromString($xml->textContent), |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Convert this Action to XML. |
|
105
|
|
|
*/ |
|
106
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
107
|
|
|
{ |
|
108
|
|
|
$e = $this->instantiateParentElement($parent); |
|
109
|
|
|
|
|
110
|
|
|
$e->setAttribute('Namespace', strval($this->getNamespace())); |
|
111
|
|
|
$e->textContent = strval($this->getContent()); |
|
112
|
|
|
|
|
113
|
|
|
return $e; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|