|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Base class corresponding to the BaseID element. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Jaime Pérez Crespo, UNINETT AS <[email protected]> |
|
6
|
|
|
* @package simplesamlphp/saml2 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace SAML2\XML\saml; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use SAML2\Constants; |
|
13
|
|
|
use SAML2\DOMDocumentFactory; |
|
14
|
|
|
|
|
15
|
|
|
abstract class BaseIDType |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The security or administrative domain that qualifies the identifier. |
|
19
|
|
|
* This attribute provides a means to federate identifiers from disparate user stores without collision. |
|
20
|
|
|
* |
|
21
|
|
|
* @see saml-core-2.0-os |
|
22
|
|
|
* |
|
23
|
|
|
* @var string|null |
|
24
|
|
|
*/ |
|
25
|
|
|
public $NameQualifier = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Further qualifies an identifier with the name of a service provider or affiliation of providers. |
|
29
|
|
|
* This attribute provides an additional means to federate identifiers on the basis of the relying party or parties. |
|
30
|
|
|
* |
|
31
|
|
|
* @see saml-core-2.0-os |
|
32
|
|
|
* |
|
33
|
|
|
* @var string|null |
|
34
|
|
|
*/ |
|
35
|
|
|
public $SPNameQualifier = null; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The name for this BaseID. |
|
39
|
|
|
* |
|
40
|
|
|
* Override in classes extending this class to get the desired name. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $nodeName; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Initialize a saml:BaseID, either from scratch or from an existing \DOMElement. |
|
49
|
|
|
* |
|
50
|
|
|
* @param \DOMElement|null $xml The XML element we should load, if any. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(\DOMElement $xml = null) |
|
53
|
|
|
{ |
|
54
|
|
|
if ($xml === null) { |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$this->element = $xml; |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
if ($xml->hasAttribute('NameQualifier')) { |
|
61
|
|
|
$this->NameQualifier = $xml->getAttribute('NameQualifier'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($xml->hasAttribute('SPNameQualifier')) { |
|
65
|
|
|
$this->SPNameQualifier = $xml->getAttribute('SPNameQualifier'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Convert this BaseID to XML. |
|
72
|
|
|
* |
|
73
|
|
|
* @param \DOMElement $element The element we are converting to XML. |
|
|
|
|
|
|
74
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this BaseID. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function toXML(\DOMElement $parent = null) |
|
77
|
|
|
{ |
|
78
|
|
|
assert('is_string($this->NameQualifier) || is_null($this->NameQualifier'); |
|
79
|
|
|
assert('is_string($this->SPNameQualifier) || is_null($this->SPNameQualifier'); |
|
80
|
|
|
|
|
81
|
|
View Code Duplication |
if ($parent === null) { |
|
|
|
|
|
|
82
|
|
|
$parent = DOMDocumentFactory::create(); |
|
83
|
|
|
$doc = $parent; |
|
84
|
|
|
} else { |
|
85
|
|
|
$doc = $parent->ownerDocument; |
|
86
|
|
|
} |
|
87
|
|
|
$element = $doc->createElementNS(Constants::NS_SAML, $this->nodeName); |
|
88
|
|
|
$parent->appendChild($element); |
|
89
|
|
|
|
|
90
|
|
|
if ($this->NameQualifier !== null) { |
|
91
|
|
|
$element->setAttribute('NameQualifier', $this->NameQualifier); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if ($this->SPNameQualifier !== null) { |
|
95
|
|
|
$element->setAttribute('SPNameQualifier', $this->SPNameQualifier); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $element; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get a string representation of this BaseIDType object. |
|
104
|
|
|
* |
|
105
|
|
|
* @return string The resulting XML, as a string. |
|
106
|
|
|
*/ |
|
107
|
|
|
public function __toString() |
|
108
|
|
|
{ |
|
109
|
|
|
assert('!is_null($this->element)'); |
|
110
|
|
|
|
|
111
|
|
|
$doc = DOMDocumentFactory::create(); |
|
112
|
|
|
$root = $doc->createElementNS(Constants::NS_SAML, 'root'); |
|
113
|
|
|
$ele = $this->toXML($root); |
|
114
|
|
|
|
|
115
|
|
|
return $doc->saveXML($ele); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: