|
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\State\Sso; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Error\LightSamlException; |
|
15
|
|
|
use LightSaml\Meta\ParameterBag; |
|
16
|
|
|
|
|
17
|
|
|
class SsoSessionState |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
protected $idpEntityId; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $spEntityId; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
protected $nameId; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $nameIdFormat; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
protected $sessionIndex; |
|
33
|
|
|
|
|
34
|
|
|
/** @var \DateTime */ |
|
35
|
|
|
protected $sessionInstant; |
|
36
|
|
|
|
|
37
|
|
|
/** @var \DateTime */ |
|
38
|
|
|
protected $firstAuthOn; |
|
39
|
|
|
|
|
40
|
|
|
/** @var \DateTime */ |
|
41
|
|
|
protected $lastAuthOn; |
|
42
|
|
|
|
|
43
|
|
|
/** @var ParameterBag */ |
|
44
|
|
|
protected $parameters; |
|
45
|
|
|
|
|
46
|
|
|
public function __construct() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->parameters = new ParameterBag(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getIdpEntityId() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->idpEntityId; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $idpEntityId |
|
61
|
|
|
* |
|
62
|
|
|
* @return SsoSessionState |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setIdpEntityId($idpEntityId) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->idpEntityId = $idpEntityId; |
|
67
|
|
|
|
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getSpEntityId() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->spEntityId; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $spEntityId |
|
81
|
|
|
* |
|
82
|
|
|
* @return SsoSessionState |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setSpEntityId($spEntityId) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->spEntityId = $spEntityId; |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getNameId() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->nameId; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $nameId |
|
101
|
|
|
* |
|
102
|
|
|
* @return SsoSessionState |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setNameId($nameId) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->nameId = $nameId; |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getNameIdFormat() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->nameIdFormat; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param string $nameIdFormat |
|
121
|
|
|
* |
|
122
|
|
|
* @return SsoSessionState |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setNameIdFormat($nameIdFormat) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->nameIdFormat = $nameIdFormat; |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getSessionIndex() |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->sessionIndex; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param string $sessionIndex |
|
141
|
|
|
* |
|
142
|
|
|
* @return SsoSessionState |
|
143
|
|
|
*/ |
|
144
|
|
|
public function setSessionIndex($sessionIndex) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->sessionIndex = $sessionIndex; |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return \DateTime |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getFirstAuthOn() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->firstAuthOn; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param \DateTime $firstAuthOn |
|
161
|
|
|
* |
|
162
|
|
|
* @return SsoSessionState |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setFirstAuthOn($firstAuthOn) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->firstAuthOn = $firstAuthOn; |
|
167
|
|
|
|
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return \DateTime |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getLastAuthOn() |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->lastAuthOn; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param \DateTime $lastAuthOn |
|
181
|
|
|
* |
|
182
|
|
|
* @return SsoSessionState |
|
183
|
|
|
*/ |
|
184
|
|
|
public function setLastAuthOn($lastAuthOn) |
|
185
|
|
|
{ |
|
186
|
|
|
$this->lastAuthOn = $lastAuthOn; |
|
187
|
|
|
|
|
188
|
|
|
return $this; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return \DateTime |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getSessionInstant() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->sessionInstant; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param \DateTime $sessionInstant |
|
201
|
|
|
* |
|
202
|
|
|
* @return SsoSessionState |
|
203
|
|
|
*/ |
|
204
|
|
|
public function setSessionInstant($sessionInstant) |
|
205
|
|
|
{ |
|
206
|
|
|
$this->sessionInstant = $sessionInstant; |
|
207
|
|
|
|
|
208
|
|
|
return $this; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return ParameterBag |
|
213
|
|
|
*/ |
|
214
|
|
|
public function getParameters() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->parameters; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @deprecated Since 1.2, will be removed in 2.0. Use getParameters() instead |
|
221
|
|
|
* |
|
222
|
|
|
* @return array |
|
223
|
|
|
*/ |
|
224
|
|
|
public function getOptions() |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->parameters->all(); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @deprecated Since 1.2, will be removed in 2.0. Use getParameters() instead |
|
231
|
|
|
* |
|
232
|
|
|
* @param string $name |
|
233
|
|
|
* @param mixed $value |
|
234
|
|
|
* |
|
235
|
|
|
* @return SsoSessionState |
|
236
|
|
|
*/ |
|
237
|
|
|
public function addOption($name, $value) |
|
238
|
|
|
{ |
|
239
|
|
|
$this->parameters->set($name, $value); |
|
240
|
|
|
|
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @deprecated Since 1.2, will be removed in 2.0. Use getParameters() instead |
|
246
|
|
|
* |
|
247
|
|
|
* @param string $name |
|
248
|
|
|
* |
|
249
|
|
|
* @return SsoSessionState |
|
250
|
|
|
*/ |
|
251
|
|
|
public function removeOption($name) |
|
252
|
|
|
{ |
|
253
|
|
|
$this->parameters->remove($name); |
|
254
|
|
|
|
|
255
|
|
|
return $this; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @deprecated Since 1.2, will be removed in 2.0. Use getParameters() instead |
|
260
|
|
|
* |
|
261
|
|
|
* @param string $name |
|
262
|
|
|
* |
|
263
|
|
|
* @return bool |
|
264
|
|
|
*/ |
|
265
|
|
|
public function hasOption($name) |
|
266
|
|
|
{ |
|
267
|
|
|
return $this->parameters->has($name); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @param string $partyId |
|
272
|
|
|
* |
|
273
|
|
|
* @return string Other party id |
|
274
|
|
|
* |
|
275
|
|
|
* @throws \LightSaml\Error\LightSamlException If $partyId does not match sp or idp entity id |
|
276
|
|
|
*/ |
|
277
|
|
|
public function getOtherPartyId($partyId) |
|
278
|
|
|
{ |
|
279
|
|
|
if ($partyId == $this->idpEntityId) { |
|
280
|
|
|
return $this->spEntityId; |
|
281
|
|
|
} elseif ($partyId == $this->spEntityId) { |
|
282
|
|
|
return $this->idpEntityId; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
throw new LightSamlException(sprintf('Party "%s" is not included in sso session between "%s" and "%s"', $partyId, $this->idpEntityId, $this->spEntityId)); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
public function __serialize(): array { |
|
289
|
|
|
return [ |
|
290
|
|
|
'idp_entity_id' => $this->idpEntityId, |
|
291
|
|
|
'sp_entity_id' => $this->spEntityId, |
|
292
|
|
|
'name_id' => $this->nameId, |
|
293
|
|
|
'name_id_format' => $this->nameIdFormat, |
|
294
|
|
|
'session_index' => $this->sessionIndex, |
|
295
|
|
|
'session_instant' => $this->sessionInstant, |
|
296
|
|
|
'first_auth_on' => $this->firstAuthOn, |
|
297
|
|
|
'last_auth_on' => $this->lastAuthOn, |
|
298
|
|
|
'parameters' => $this->parameters->all() |
|
299
|
|
|
]; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
public function __unserialize(array $data): void { |
|
303
|
|
|
$this->idpEntityId = $data['idp_entity_id']; |
|
304
|
|
|
$this->spEntityId = $data['sp_entity_id']; |
|
305
|
|
|
$this->nameId = $data['name_id']; |
|
306
|
|
|
$this->nameIdFormat = $data['name_id_format']; |
|
307
|
|
|
$this->sessionIndex = $data['session_index']; |
|
308
|
|
|
$this->sessionInstant = $data['session_instant']; |
|
309
|
|
|
$this->firstAuthOn = $data['first_auth_on']; |
|
310
|
|
|
$this->lastAuthOn = $data['last_auth_on']; |
|
311
|
|
|
$this->parameters = new ParameterBag($data['parameters']); |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
|