1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML2\Compat\ContainerSingleton; |
10
|
|
|
use SimpleSAML\XML\StringElementTrait; |
11
|
|
|
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend; |
12
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* SAML NameIDType abstract data type. |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/saml2 |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
abstract class NameIDType extends AbstractBaseIDType |
21
|
|
|
{ |
22
|
|
|
use StringElementTrait; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* A URI reference representing the classification of string-based identifier information. See Section 8.3 for the |
26
|
|
|
* SAML-defined URI references that MAY be used as the value of the Format attribute and their associated |
27
|
|
|
* descriptions and processing rules. Unless otherwise specified by an element based on this type, if no Format |
28
|
|
|
* value is provided, then the value urn:oasis:names:tc:SAML:1.0:nameid-format:unspecified (see Section 8.3.1) is in |
29
|
|
|
* effect. |
30
|
|
|
* |
31
|
|
|
* When a Format value other than one specified in Section 8.3 is used, the content of an element of this type is to |
32
|
|
|
* be interpreted according to the definition of that format as provided outside of this specification. If not |
33
|
|
|
* otherwise indicated by the definition of the format, issues of anonymity, pseudonymity, and the persistence of |
34
|
|
|
* the identifier with respect to the asserting and relying parties are implementation-specific. |
35
|
|
|
* |
36
|
|
|
* @var string|null |
37
|
|
|
* |
38
|
|
|
* @see saml-core-2.0-os |
39
|
|
|
*/ |
40
|
|
|
protected ?string $Format = null; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* A name identifier established by a service provider or affiliation of providers for the entity, if different from |
44
|
|
|
* the primary name identifier given in the content of the element. This attribute provides a means of integrating |
45
|
|
|
* the use of SAML with existing identifiers already in use by a service provider. For example, an existing |
46
|
|
|
* identifier can be "attached" to the entity using the Name Identifier Management protocol defined in Section 3.6. |
47
|
|
|
* |
48
|
|
|
* @var string|null |
49
|
|
|
* |
50
|
|
|
* @see saml-core-2.0-os |
51
|
|
|
*/ |
52
|
|
|
protected ?string $SPProvidedID = null; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Initialize a saml:NameIDType from scratch |
57
|
|
|
* |
58
|
|
|
* @param string $value |
59
|
|
|
* @param string|null $Format |
60
|
|
|
* @param string|null $SPProvidedID |
61
|
|
|
* @param string|null $NameQualifier |
62
|
|
|
* @param string|null $SPNameQualifier |
63
|
|
|
*/ |
64
|
|
|
protected function __construct( |
65
|
|
|
string $value, |
66
|
|
|
?string $NameQualifier = null, |
67
|
|
|
?string $SPNameQualifier = null, |
68
|
|
|
?string $Format = null, |
69
|
|
|
?string $SPProvidedID = null |
70
|
|
|
) { |
71
|
|
|
parent::__construct($NameQualifier, $SPNameQualifier); |
72
|
|
|
$this->dataType = C::XMLENC_ELEMENT; |
|
|
|
|
73
|
|
|
|
74
|
|
|
$this->setContent($value); |
75
|
|
|
$this->setFormat($Format); |
76
|
|
|
$this->setSPProvidedID($SPProvidedID); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Collect the value of the Format-property |
82
|
|
|
* |
83
|
|
|
* @return string|null |
84
|
|
|
*/ |
85
|
|
|
public function getFormat(): ?string |
86
|
|
|
{ |
87
|
|
|
return $this->Format; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set the value of the Format-property |
93
|
|
|
* |
94
|
|
|
* @param string|null $format |
95
|
|
|
*/ |
96
|
|
|
private function setFormat(?string $format): void |
97
|
|
|
{ |
98
|
|
|
Assert::nullOrValidURI($format); // Covers the empty string |
99
|
|
|
$this->Format = $format; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Collect the value of the SPProvidedID-property |
105
|
|
|
* |
106
|
|
|
* @return string|null |
107
|
|
|
*/ |
108
|
|
|
public function getSPProvidedID(): ?string |
109
|
|
|
{ |
110
|
|
|
return $this->SPProvidedID; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set the value of the SPProvidedID-property |
116
|
|
|
* |
117
|
|
|
* @param string|null $spProvidedID |
118
|
|
|
*/ |
119
|
|
|
private function setSPProvidedID(?string $spProvidedID): void |
120
|
|
|
{ |
121
|
|
|
Assert::nullOrNotWhitespaceOnly($spProvidedID); |
122
|
|
|
$this->SPProvidedID = $spProvidedID; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Validate the content of the element. |
128
|
|
|
* |
129
|
|
|
* @param string $content The value to go in the XML textContent |
130
|
|
|
* @throws \Exception on failure |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
protected function validateContent(string $content): void |
134
|
|
|
{ |
135
|
|
|
Assert::notWhitespaceOnly($content); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Convert this NameIDType to XML. |
141
|
|
|
* |
142
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
143
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this NameIDType. |
144
|
|
|
*/ |
145
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
146
|
|
|
{ |
147
|
|
|
$e = parent::toXML($parent); |
148
|
|
|
|
149
|
|
|
if ($this->getFormat() !== null) { |
150
|
|
|
$e->setAttribute('Format', $this->getFormat()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if ($this->getSPProvidedID() !== null) { |
154
|
|
|
$e->setAttribute('SPProvidedID', $this->getSPProvidedID()); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$e->textContent = $this->getContent(); |
158
|
|
|
return $e; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|