|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Model\Metadata; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Model\Context\DeserializationContext; |
|
15
|
|
|
use LightSaml\Model\Context\SerializationContext; |
|
16
|
|
|
use LightSaml\Model\Assertion\Attribute; |
|
17
|
|
|
use LightSaml\SamlConstants; |
|
18
|
|
|
|
|
19
|
|
|
class IdpSsoDescriptor extends SSODescriptor |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var bool|null */ |
|
22
|
|
|
protected $wantAuthnRequestsSigned; |
|
23
|
|
|
|
|
24
|
|
|
/** @var SingleSignOnService[]|null */ |
|
25
|
|
|
protected $singleSignOnServices; |
|
26
|
|
|
|
|
27
|
|
|
/** @var Attribute[]|null */ |
|
28
|
|
|
protected $attributes; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param bool|null $wantAuthnRequestsSigned |
|
32
|
|
|
* |
|
33
|
|
|
* @return IdpSsoDescriptor |
|
34
|
|
|
*/ |
|
35
|
6 |
|
public function setWantAuthnRequestsSigned($wantAuthnRequestsSigned) |
|
36
|
|
|
{ |
|
37
|
6 |
|
$this->wantAuthnRequestsSigned = filter_var($wantAuthnRequestsSigned, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]); |
|
38
|
|
|
|
|
39
|
6 |
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return bool|null |
|
44
|
|
|
*/ |
|
45
|
3 |
|
public function getWantAuthnRequestsSigned() |
|
46
|
|
|
{ |
|
47
|
3 |
|
return $this->wantAuthnRequestsSigned; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param SingleSignOnService $singleSignOnService |
|
52
|
|
|
* |
|
53
|
|
|
* @return IdpSsoDescriptor |
|
54
|
|
|
*/ |
|
55
|
42 |
|
public function addSingleSignOnService(SingleSignOnService $singleSignOnService) |
|
56
|
|
|
{ |
|
57
|
42 |
|
if (false == is_array($this->singleSignOnServices)) { |
|
|
|
|
|
|
58
|
3 |
|
$this->singleSignOnServices = array(); |
|
59
|
|
|
} |
|
60
|
42 |
|
$this->singleSignOnServices[] = $singleSignOnService; |
|
61
|
|
|
|
|
62
|
42 |
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return SingleSignOnService[]|null |
|
67
|
|
|
*/ |
|
68
|
14 |
|
public function getAllSingleSignOnServices() |
|
69
|
|
|
{ |
|
70
|
14 |
|
return $this->singleSignOnServices; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $url |
|
75
|
|
|
* |
|
76
|
|
|
* @return SingleSignOnService[] |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getAllSingleSignOnServicesByUrl($url) |
|
79
|
|
|
{ |
|
80
|
|
|
$result = array(); |
|
81
|
|
|
foreach ($this->getAllSingleSignOnServices() as $svc) { |
|
|
|
|
|
|
82
|
|
|
if ($svc->getLocation() == $url) { |
|
83
|
|
|
$result[] = $svc; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $result; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $binding |
|
92
|
|
|
* |
|
93
|
|
|
* @return SingleSignOnService[] |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function getAllSingleSignOnServicesByBinding($binding) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$result = array(); |
|
98
|
1 |
|
foreach ($this->getAllSingleSignOnServices() as $svc) { |
|
|
|
|
|
|
99
|
1 |
|
if ($svc->getBinding() == $binding) { |
|
100
|
1 |
|
$result[] = $svc; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
return $result; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param string|null $binding |
|
109
|
|
|
* |
|
110
|
|
|
* @return SingleSignOnService|null |
|
111
|
|
|
*/ |
|
112
|
1 |
View Code Duplication |
public function getFirstSingleSignOnService($binding = null) |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
1 |
|
foreach ($this->getAllSingleSignOnServices() as $svc) { |
|
|
|
|
|
|
115
|
1 |
|
if (null == $binding || $svc->getBinding() == $binding) { |
|
|
|
|
|
|
116
|
1 |
|
return $svc; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return null; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param \LightSaml\Model\Assertion\Attribute $attribute |
|
125
|
|
|
* |
|
126
|
|
|
* @return IdpSsoDescriptor |
|
127
|
|
|
*/ |
|
128
|
23 |
|
public function addAttribute(Attribute $attribute) |
|
129
|
|
|
{ |
|
130
|
23 |
|
if (false == is_array($this->attributes)) { |
|
|
|
|
|
|
131
|
3 |
|
$this->attributes = array(); |
|
132
|
|
|
} |
|
133
|
23 |
|
$this->attributes[] = $attribute; |
|
134
|
|
|
|
|
135
|
23 |
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return \LightSaml\Model\Assertion\Attribute[]|null |
|
140
|
|
|
*/ |
|
141
|
3 |
|
public function getAllAttributes() |
|
142
|
|
|
{ |
|
143
|
3 |
|
return $this->attributes; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param \DOMNode $parent |
|
148
|
|
|
* @param SerializationContext $context |
|
149
|
|
|
*/ |
|
150
|
2 |
|
public function serialize(\DOMNode $parent, SerializationContext $context) |
|
151
|
|
|
{ |
|
152
|
2 |
|
$result = $this->createElement('IDPSSODescriptor', SamlConstants::NS_METADATA, $parent, $context); |
|
153
|
|
|
|
|
154
|
2 |
|
parent::serialize($result, $context); |
|
155
|
|
|
|
|
156
|
2 |
|
$this->attributesToXml(array('WantAuthnRequestsSigned'), $result); |
|
157
|
|
|
|
|
158
|
2 |
|
if ($this->getAllSingleSignOnServices()) { |
|
159
|
2 |
|
foreach ($this->getAllSingleSignOnServices() as $object) { |
|
160
|
2 |
|
$object->serialize($result, $context); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
2 |
|
if ($this->getAllAttributes()) { |
|
164
|
2 |
|
foreach ($this->getAllAttributes() as $object) { |
|
165
|
2 |
|
$object->serialize($result, $context); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
2 |
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param \DOMNode $node |
|
172
|
|
|
* @param DeserializationContext $context |
|
173
|
|
|
*/ |
|
174
|
40 |
View Code Duplication |
public function deserialize(\DOMNode $node, DeserializationContext $context) |
|
|
|
|
|
|
175
|
|
|
{ |
|
176
|
40 |
|
$this->checkXmlNodeName($node, 'IDPSSODescriptor', SamlConstants::NS_METADATA); |
|
177
|
|
|
|
|
178
|
40 |
|
parent::deserialize($node, $context); |
|
179
|
|
|
|
|
180
|
40 |
|
$this->attributesFromXml($node, array('WantAuthnRequestsSigned')); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
40 |
|
$this->singleSignOnServices = array(); |
|
183
|
40 |
|
$this->manyElementsFromXml( |
|
184
|
40 |
|
$node, |
|
|
|
|
|
|
185
|
40 |
|
$context, |
|
186
|
40 |
|
'SingleSignOnService', |
|
187
|
40 |
|
'md', |
|
188
|
40 |
|
'LightSaml\Model\Metadata\SingleSignOnService', |
|
189
|
40 |
|
'addSingleSignOnService' |
|
190
|
|
|
); |
|
191
|
|
|
|
|
192
|
40 |
|
$this->attributes = array(); |
|
193
|
40 |
|
$this->manyElementsFromXml( |
|
194
|
40 |
|
$node, |
|
|
|
|
|
|
195
|
40 |
|
$context, |
|
196
|
40 |
|
'Attribute', |
|
197
|
40 |
|
'saml', |
|
198
|
40 |
|
'LightSaml\Model\Assertion\Attribute', |
|
199
|
40 |
|
'addAttribute' |
|
200
|
|
|
); |
|
201
|
40 |
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.