Completed
Push — feature/clear-sso-state ( e8547b )
by
unknown
02:33
created

ProxyStateHandler::clear()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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