|
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\SamlConstants; |
|
17
|
|
|
|
|
18
|
|
|
class SpSsoDescriptor extends SSODescriptor |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var bool|null */ |
|
21
|
|
|
protected $authnRequestsSigned; |
|
22
|
|
|
|
|
23
|
|
|
/** @var bool|null */ |
|
24
|
|
|
protected $wantAssertionsSigned; |
|
25
|
|
|
|
|
26
|
|
|
/** @var AssertionConsumerService[]|null */ |
|
27
|
|
|
protected $assertionConsumerServices; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return SpSsoDescriptor |
|
31
|
|
|
*/ |
|
32
|
|
|
public function addAssertionConsumerService(AssertionConsumerService $assertionConsumerService) |
|
33
|
|
|
{ |
|
34
|
|
|
if (false == is_array($this->assertionConsumerServices)) { |
|
|
|
|
|
|
35
|
|
|
$this->assertionConsumerServices = []; |
|
36
|
|
|
} |
|
37
|
|
|
if (null === $assertionConsumerService->getIndex()) { |
|
|
|
|
|
|
38
|
|
|
$assertionConsumerService->setIndex(count($this->assertionConsumerServices)); |
|
39
|
|
|
} |
|
40
|
|
|
$this->assertionConsumerServices[] = $assertionConsumerService; |
|
41
|
|
|
|
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return AssertionConsumerService[]|null |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getAllAssertionConsumerServices() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->assertionConsumerServices; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $binding |
|
55
|
|
|
* |
|
56
|
|
|
* @return AssertionConsumerService[] |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getAllAssertionConsumerServicesByBinding($binding) |
|
59
|
|
|
{ |
|
60
|
|
|
$result = []; |
|
61
|
|
|
foreach ($this->getAllAssertionConsumerServices() as $svc) { |
|
62
|
|
|
if ($svc->getBinding() == $binding) { |
|
63
|
|
|
$result[] = $svc; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $result; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $url |
|
72
|
|
|
* |
|
73
|
|
|
* @return AssertionConsumerService[] |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getAllAssertionConsumerServicesByUrl($url) |
|
76
|
|
|
{ |
|
77
|
|
|
$result = []; |
|
78
|
|
|
foreach ($this->getAllAssertionConsumerServices() as $svc) { |
|
79
|
|
|
if ($svc->getLocation() == $url) { |
|
80
|
|
|
$result[] = $svc; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $result; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param int $index |
|
89
|
|
|
* |
|
90
|
|
|
* @return AssertionConsumerService|null |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getAssertionConsumerServicesByIndex($index) |
|
93
|
|
|
{ |
|
94
|
|
|
foreach ($this->getAllAssertionConsumerServices() as $svc) { |
|
95
|
|
|
if ($svc->getIndex() == $index) { |
|
96
|
|
|
return $svc; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return null; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string|null $binding |
|
105
|
|
|
* |
|
106
|
|
|
* @return AssertionConsumerService|null |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getFirstAssertionConsumerService($binding = null) |
|
109
|
|
|
{ |
|
110
|
|
|
foreach ($this->getAllAssertionConsumerServices() as $svc) { |
|
111
|
|
|
if (null == $binding || $svc->getBinding() == $binding) { |
|
|
|
|
|
|
112
|
|
|
return $svc; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return null; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param bool|null $authnRequestsSigned |
|
121
|
|
|
* |
|
122
|
|
|
* @return SpSsoDescriptor |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setAuthnRequestsSigned($authnRequestsSigned) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->authnRequestsSigned = filter_var($authnRequestsSigned, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]); |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return bool|null |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getAuthnRequestsSigned() |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->authnRequestsSigned; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param bool|null $wantAssertionsSigned |
|
141
|
|
|
* |
|
142
|
|
|
* @return SpSsoDescriptor |
|
143
|
|
|
*/ |
|
144
|
|
|
public function setWantAssertionsSigned($wantAssertionsSigned) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->wantAssertionsSigned = filter_var($wantAssertionsSigned, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]); |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return bool|null |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getWantAssertionsSigned() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->wantAssertionsSigned; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function serialize(\DOMNode $parent, SerializationContext $context) |
|
160
|
|
|
{ |
|
161
|
|
|
$result = $this->createElement('SPSSODescriptor', SamlConstants::NS_METADATA, $parent, $context); |
|
162
|
|
|
|
|
163
|
|
|
parent::serialize($result, $context); |
|
164
|
|
|
|
|
165
|
|
|
$this->attributesToXml(['AuthnRequestsSigned', 'WantAssertionsSigned'], $result); |
|
166
|
|
|
|
|
167
|
|
|
$this->manyElementsToXml($this->getAllAssertionConsumerServices(), $result, $context, null); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function deserialize(\DOMNode $node, DeserializationContext $context) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->checkXmlNodeName($node, 'SPSSODescriptor', SamlConstants::NS_METADATA); |
|
173
|
|
|
|
|
174
|
|
|
parent::deserialize($node, $context); |
|
175
|
|
|
|
|
176
|
|
|
$this->attributesFromXml($node, ['AuthnRequestsSigned', 'WantAssertionsSigned']); |
|
177
|
|
|
|
|
178
|
|
|
$this->manyElementsFromXml( |
|
179
|
|
|
$node, |
|
180
|
|
|
$context, |
|
181
|
|
|
'AssertionConsumerService', |
|
182
|
|
|
'md', |
|
183
|
|
|
'LightSaml\Model\Metadata\AssertionConsumerService', |
|
184
|
|
|
'addAssertionConsumerService' |
|
185
|
|
|
); |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.