Completed
Push — master ( e96383...13486f )
by
unknown
06:11
created

ProxyStateHandler::getRequestId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * @return string|null
105
     */
106
    public function getRequestAssertionConsumerServiceUrl()
107
    {
108
        return $this->get('assertion_consumer_service_url');
109
    }
110
111
    /**
112
     * @param string $relayState
113
     * @return $this
114
     */
115
    public function setRelayState($relayState)
116
    {
117
        $this->set('relay_state', $relayState);
118
119
        return $this;
120
    }
121
122
    /**
123
     * @return string|null
124
     */
125
    public function getRelayState()
126
    {
127
        return $this->get('relay_state');
128
    }
129
130
    /**
131
     * @param string $loaIdentifier
132
     * @return $this
133
     */
134
    public function setRequiredLoaIdentifier($loaIdentifier)
135
    {
136
        $this->set('loa_identifier', $loaIdentifier);
137
138
        return $this;
139
    }
140
141
    /**
142
     * @return string|null
143
     */
144
    public function getRequiredLoaIdentifier()
145
    {
146
        return $this->get('loa_identifier');
147
    }
148
149
    /**
150
     * @param string $requestId
151
     * @return $this
152
     */
153
    public function setGatewayRequestId($requestId)
154
    {
155
        $this->set('gateway_request_id', $requestId);
156
157
        return $this;
158
    }
159
160
    /**
161
     * @return string|null
162
     */
163
    public function getGatewayRequestId()
164
    {
165
        return $this->get('gateway_request_id');
166
    }
167
168
    /**
169
     * @param string $assertionAsXmlString
170
     * @return $this
171
     */
172
    public function saveAssertion($assertionAsXmlString)
173
    {
174
        $this->set('response_assertion', $assertionAsXmlString);
175
176
        return $this;
177
    }
178
179
    /**
180
     * @return null|string
181
     */
182
    public function getAssertion()
183
    {
184
        return $this->get('response_assertion');
185
    }
186
187
    /**
188
     * @param $nameId
189
     * @return $this
190
     */
191
    public function saveIdentityNameId($nameId)
192
    {
193
        $this->set('name_id', $nameId);
194
195
        return $this;
196
    }
197
198
    /**
199
     * @return null|string
200
     */
201
    public function getIdentityNameId()
202
    {
203
        return $this->get('name_id');
204
    }
205
206
    /**
207
     * @param string $idpEntityId
208
     * @return $this
209
     */
210
    public function setAuthenticatingIdp($idpEntityId)
211
    {
212
        $this->set('authenticating_idp', $idpEntityId);
213
214
        return $this;
215
    }
216
217
    /**
218
     * @return null|string
219
     */
220
    public function getAuthenticatingIdp()
221
    {
222
        return $this->get('authenticating_idp');
223
    }
224
225
    /**
226
     * @param string|null $secondFactorId
227
     * @return $this
228
     */
229
    public function setSelectedSecondFactorId($secondFactorId)
230
    {
231
        $this->set('selected_second_factor', $secondFactorId);
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return null|string
238
     */
239
    public function getSelectedSecondFactorId()
240
    {
241
        return $this->get('selected_second_factor');
242
    }
243
244
    /**
245
     * @param bool $verified
246
     * @return $this
247
     */
248
    public function setSecondFactorVerified($verified)
249
    {
250
        $this->set('selected_second_factor_verified', $verified);
251
252
        return $this;
253
    }
254
255
    /**
256
     * @return bool
257
     */
258
    public function isSecondFactorVerified()
259
    {
260
        return $this->get('selected_second_factor_verified') === true;
261
    }
262
263
    /**
264
     * @param string $controllerName
265
     * @return $this
266
     */
267
    public function setResponseAction($controllerName)
268
    {
269
        $this->set('response_controller', $controllerName);
270
        return $this;
271
    }
272
    /**
273
     * @return string|null
274
     */
275
    public function getResponseAction()
276
    {
277
        return $this->get('response_controller');
278
    }
279
    /**
280
     * @param string $serviceId
281
     * @return $this
282
     */
283
    public function setResponseContextServiceId($serviceId)
284
    {
285
        $this->set('response_context_service_id', $serviceId);
286
        return $this;
287
    }
288
289
    /**
290
     * @return string|null
291
     */
292
    public function getResponseContextServiceId()
293
    {
294
        return $this->get('response_context_service_id');
295
    }
296
297
    /**
298
     * @param $organization
299
     * @return $this
300
     */
301
    public function setSchacHomeOrganization($organization)
302
    {
303
        $this->set('schac_home_organization', $organization);
304
        return $this;
305
    }
306
307
    /**
308
     * @return string|null
309
     */
310
    public function getSchacHomeOrganization()
311
    {
312
        return $this->get('schac_home_organization');
313
    }
314
315
    /**
316
     * @param string $locale
317
     * @return $this
318
     */
319
    public function setPreferredLocale($locale)
320
    {
321
        $this->set('locale', $locale);
322
        return $this;
323
    }
324
325
    /**
326
     * @return string|null
327
     */
328
    public function getPreferredLocale()
329
    {
330
        return $this->get('locale');
331
    }
332
333
    /**
334
     * @param string $key
335
     * @param mixed $value Any scalar
336
     */
337
    protected function set($key, $value)
338
    {
339
        $this->session->set(self::SESSION_PATH . $key, $value);
340
    }
341
342
    /**
343
     * @param string $key
344
     * @return mixed|null Any scalar
345
     */
346
    protected function get($key)
347
    {
348
        return $this->session->get(self::SESSION_PATH . $key);
349
    }
350
}
351