1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\GatewayBundle\Saml\Proxy; |
20
|
|
|
|
21
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
22
|
|
|
|
23
|
|
|
class ProxyStateHandler |
24
|
|
|
{ |
25
|
|
|
const SESSION_PATH = 'surfnet/gateway/request'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface |
29
|
|
|
*/ |
30
|
|
|
private $session; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param SessionInterface $session |
34
|
|
|
*/ |
35
|
|
|
public function __construct(SessionInterface $session) |
36
|
|
|
{ |
37
|
|
|
$this->session = $session; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Clear the complete state, leaving other states intact. |
42
|
|
|
*/ |
43
|
|
|
public function clear() |
44
|
|
|
{ |
45
|
|
|
$all = $this->session->all(); |
46
|
|
|
|
47
|
|
|
foreach (array_keys($all) as $key) { |
48
|
|
|
if (strpos($key, self::SESSION_PATH) === 0) { |
49
|
|
|
$this->session->remove($key); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $originalRequestId |
56
|
|
|
* @return $this |
57
|
|
|
*/ |
58
|
|
|
public function setRequestId($originalRequestId) |
59
|
|
|
{ |
60
|
|
|
$this->set('request_id', $originalRequestId); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string|null |
67
|
|
|
*/ |
68
|
|
|
public function getRequestId() |
69
|
|
|
{ |
70
|
|
|
return $this->get('request_id'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $serviceProvider |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function setRequestServiceProvider($serviceProvider) |
78
|
|
|
{ |
79
|
|
|
$this->set('service_provider', $serviceProvider); |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string|null |
86
|
|
|
*/ |
87
|
|
|
public function getRequestServiceProvider() |
88
|
|
|
{ |
89
|
|
|
return $this->get('service_provider'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $url |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
|
|
public function setRequestAssertionConsumerServiceUrl($url) |
97
|
|
|
{ |
98
|
|
|
$this->set('assertion_consumer_service_url', $url); |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* WIP |
105
|
|
|
* |
106
|
|
|
* @return string|null |
107
|
|
|
*/ |
108
|
|
|
public function getRequestAssertionConsumerServiceUrl() |
109
|
|
|
{ |
110
|
|
|
return $this->get('assertion_consumer_service_url'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $relayState |
115
|
|
|
* @return $this |
116
|
|
|
*/ |
117
|
|
|
public function setRelayState($relayState) |
118
|
|
|
{ |
119
|
|
|
$this->set('relay_state', $relayState); |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string|null |
126
|
|
|
*/ |
127
|
|
|
public function getRelayState() |
128
|
|
|
{ |
129
|
|
|
return $this->get('relay_state'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $loaIdentifier |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
|
|
public function setRequiredLoaIdentifier($loaIdentifier) |
137
|
|
|
{ |
138
|
|
|
$this->set('loa_identifier', $loaIdentifier); |
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string|null |
145
|
|
|
*/ |
146
|
|
|
public function getRequiredLoaIdentifier() |
147
|
|
|
{ |
148
|
|
|
return $this->get('loa_identifier'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $requestId |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
|
public function setGatewayRequestId($requestId) |
156
|
|
|
{ |
157
|
|
|
$this->set('gateway_request_id', $requestId); |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return string|null |
164
|
|
|
*/ |
165
|
|
|
public function getGatewayRequestId() |
166
|
|
|
{ |
167
|
|
|
return $this->get('gateway_request_id'); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $assertionAsXmlString |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function saveAssertion($assertionAsXmlString) |
175
|
|
|
{ |
176
|
|
|
$this->set('response_assertion', $assertionAsXmlString); |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return null|string |
183
|
|
|
*/ |
184
|
|
|
public function getAssertion() |
185
|
|
|
{ |
186
|
|
|
return $this->get('response_assertion'); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param $nameId |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
|
|
public function saveIdentityNameId($nameId) |
194
|
|
|
{ |
195
|
|
|
$this->set('name_id', $nameId); |
196
|
|
|
|
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return null|string |
202
|
|
|
*/ |
203
|
|
|
public function getIdentityNameId() |
204
|
|
|
{ |
205
|
|
|
return $this->get('name_id'); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $idpEntityId |
210
|
|
|
* @return $this |
211
|
|
|
*/ |
212
|
|
|
public function setAuthenticatingIdp($idpEntityId) |
213
|
|
|
{ |
214
|
|
|
$this->set('authenticating_idp', $idpEntityId); |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return null|string |
221
|
|
|
*/ |
222
|
|
|
public function getAuthenticatingIdp() |
223
|
|
|
{ |
224
|
|
|
return $this->get('authenticating_idp'); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param string|null $secondFactorId |
229
|
|
|
* @return $this |
230
|
|
|
*/ |
231
|
|
|
public function setSelectedSecondFactorId($secondFactorId) |
232
|
|
|
{ |
233
|
|
|
$this->set('selected_second_factor', $secondFactorId); |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return null|string |
240
|
|
|
*/ |
241
|
|
|
public function getSelectedSecondFactorId() |
242
|
|
|
{ |
243
|
|
|
return $this->get('selected_second_factor'); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param bool $verified |
248
|
|
|
* @return $this |
249
|
|
|
*/ |
250
|
|
|
public function setSecondFactorVerified($verified) |
251
|
|
|
{ |
252
|
|
|
$this->set('selected_second_factor_verified', $verified); |
253
|
|
|
|
254
|
|
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @return bool |
259
|
|
|
*/ |
260
|
|
|
public function isSecondFactorVerified() |
261
|
|
|
{ |
262
|
|
|
return $this->get('selected_second_factor_verified') === true; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @param string $controllerName |
267
|
|
|
* @return $this |
268
|
|
|
*/ |
269
|
|
|
public function setResponseAction($controllerName) |
270
|
|
|
{ |
271
|
|
|
$this->set('response_controller', $controllerName); |
272
|
|
|
return $this; |
273
|
|
|
} |
274
|
|
|
/** |
275
|
|
|
* @return string|null |
276
|
|
|
*/ |
277
|
|
|
public function getResponseAction() |
278
|
|
|
{ |
279
|
|
|
return $this->get('response_controller'); |
280
|
|
|
} |
281
|
|
|
/** |
282
|
|
|
* @param string $serviceId |
283
|
|
|
* @return $this |
284
|
|
|
*/ |
285
|
|
|
public function setResponseContextServiceId($serviceId) |
286
|
|
|
{ |
287
|
|
|
$this->set('response_context_service_id', $serviceId); |
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @return string|null |
293
|
|
|
*/ |
294
|
|
|
public function getResponseContextServiceId() |
295
|
|
|
{ |
296
|
|
|
return $this->get('response_context_service_id'); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param $organization |
301
|
|
|
* @return $this |
302
|
|
|
*/ |
303
|
|
|
public function setSchacHomeOrganization($organization) |
304
|
|
|
{ |
305
|
|
|
$this->set('schac_home_organization', $organization); |
306
|
|
|
return $this; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @return string|null |
311
|
|
|
*/ |
312
|
|
|
public function getSchacHomeOrganization() |
313
|
|
|
{ |
314
|
|
|
return $this->get('schac_home_organization'); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @param string $locale |
319
|
|
|
* @return $this |
320
|
|
|
*/ |
321
|
|
|
public function setPreferredLocale($locale) |
322
|
|
|
{ |
323
|
|
|
$this->set('locale', $locale); |
324
|
|
|
return $this; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @return string|null |
329
|
|
|
*/ |
330
|
|
|
public function getPreferredLocale() |
331
|
|
|
{ |
332
|
|
|
return $this->get('locale'); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @param string $key |
337
|
|
|
* @param mixed $value Any scalar |
338
|
|
|
*/ |
339
|
|
|
protected function set($key, $value) |
340
|
|
|
{ |
341
|
|
|
$this->session->set(self::SESSION_PATH . $key, $value); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @param string $key |
346
|
|
|
* @return mixed|null Any scalar |
347
|
|
|
*/ |
348
|
|
|
protected function get($key) |
349
|
|
|
{ |
350
|
|
|
return $this->session->get(self::SESSION_PATH . $key); |
351
|
|
|
} |
352
|
|
|
} |
353
|
|
|
|