Passed
Push — feature/store-usage-of-sso-coo... ( 67c9e0...317e48 )
by Michiel
05:09
created

ProxyStateHandler::unsetSelectedSecondFactorId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupGateway\GatewayBundle\Saml\Proxy;
20
21
use Surfnet\StepupGateway\GatewayBundle\Saml\Exception\RuntimeException;
22
use Symfony\Component\HttpFoundation\Session\SessionInterface;
23
24
class ProxyStateHandler
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ProxyStateHandler
Loading history...
25
{
26
    private $sessionPath;
0 ignored issues
show
Coding Style introduced by
Private member variable "sessionPath" must be prefixed with an underscore
Loading history...
27
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
30
     */
31
    private $session;
0 ignored issues
show
Coding Style introduced by
Private member variable "session" must be prefixed with an underscore
Loading history...
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $sessionPath should have a doc-comment as per coding-style.
Loading history...
34
     * @param SessionInterface $session
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
35
     */
36
    public function __construct(SessionInterface $session, $sessionPath)
37
    {
38
        $this->sessionPath = $sessionPath;
39
        $this->session = $session;
40
    }
41
42
    /**
43
     * Clear the complete state, leaving other states intact.
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
45
    public function clear()
46
    {
47
        $all = $this->session->all();
48
49
        foreach (array_keys($all) as $key) {
50
            if (strpos($key, $this->sessionPath) === 0) {
51
                $this->session->remove($key);
52
            }
53
        }
54
    }
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
57
     * @param string $originalRequestId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
58
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
59
     */
60
    public function setRequestId($originalRequestId)
61
    {
62
        $this->set('request_id', $originalRequestId);
63
64
        return $this;
65
    }
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @return string|null
69
     */
70
    public function getRequestId()
71
    {
72
        return $this->get('request_id');
73
    }
74
75
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
76
     * @param string $serviceProvider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
77
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
78
     */
79
    public function setRequestServiceProvider($serviceProvider)
80
    {
81
        $this->set('service_provider', $serviceProvider);
82
83
        return $this;
84
    }
85
86
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
87
     * @return string|null
88
     */
89
    public function getRequestServiceProvider()
90
    {
91
        return $this->get('service_provider');
92
    }
93
94
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
95
     * @param string $url
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
96
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
97
     */
98
    public function setRequestAssertionConsumerServiceUrl($url)
99
    {
100
        $this->set('assertion_consumer_service_url', $url);
101
102
        return $this;
103
    }
104
105
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
106
     * @return string|null
107
     */
108
    public function getRequestAssertionConsumerServiceUrl()
109
    {
110
        return $this->get('assertion_consumer_service_url');
111
    }
112
113
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
114
     * @param string $relayState
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
115
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
116
     */
117
    public function setRelayState($relayState)
118
    {
119
        $this->set('relay_state', $relayState);
120
121
        return $this;
122
    }
123
124
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
125
     * @return string|null
126
     */
127
    public function getRelayState()
128
    {
129
        return $this->get('relay_state');
130
    }
131
132
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
133
     * @param string $loaIdentifier
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
134
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
135
     */
136
    public function setRequiredLoaIdentifier($loaIdentifier)
137
    {
138
        $this->set('loa_identifier', $loaIdentifier);
139
140
        return $this;
141
    }
142
143
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
144
     * @return string|null
145
     */
146
    public function getRequiredLoaIdentifier()
147
    {
148
        return $this->get('loa_identifier');
149
    }
150
151
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
152
     * @param string $requestId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
153
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
154
     */
155
    public function setGatewayRequestId($requestId)
156
    {
157
        $this->set('gateway_request_id', $requestId);
158
159
        return $this;
160
    }
161
162
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
163
     * @return string|null
164
     */
165
    public function getGatewayRequestId()
166
    {
167
        return $this->get('gateway_request_id');
168
    }
169
170
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
171
     * @param string $assertionAsXmlString
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
172
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
173
     */
174
    public function saveAssertion($assertionAsXmlString)
175
    {
176
        $this->set('response_assertion', $assertionAsXmlString);
177
178
        return $this;
179
    }
180
181
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
182
     * @return null|string
183
     */
184
    public function getAssertion()
185
    {
186
        return $this->get('response_assertion');
187
    }
188
189
    public function saveIdentityNameId(string $nameId)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function saveIdentityNameId()
Loading history...
190
    {
191
        $this->set('name_id', $nameId);
192
193
        return $this;
194
    }
195
196
    public function getIdentityNameId(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getIdentityNameId()
Loading history...
197
    {
198
        $nameId = $this->get('name_id');
199
        if (!$nameId) {
200
            throw new RuntimeException('Unable to retrieve NameId, it was not set on the state handler');
201
        }
202
203
        if (!is_string($nameId)) {
204
            throw new RuntimeException(
205
                sprintf('Unable to retrieve NameId, must be a string, but a %s was set', gettype($nameId))
206
            );
207
        }
208
        return $nameId;
209
    }
210
211
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
212
     * @param string $idpEntityId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
213
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
214
     */
215
    public function setAuthenticatingIdp($idpEntityId)
216
    {
217
        $this->set('authenticating_idp', $idpEntityId);
218
219
        return $this;
220
    }
221
222
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
223
     * @return null|string
224
     */
225
    public function getAuthenticatingIdp()
226
    {
227
        return $this->get('authenticating_idp');
228
    }
229
230
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
231
     * @param string|null $secondFactorId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
232
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
233
     */
234
    public function setSelectedSecondFactorId($secondFactorId)
235
    {
236
        $this->set('selected_second_factor', $secondFactorId);
237
238
        return $this;
239
    }
240
241
    public function unsetSelectedSecondFactorId(): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function unsetSelectedSecondFactorId()
Loading history...
242
    {
243
        $this->set('selected_second_factor', null);
244
    }
245
246
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
247
     * @return null|string
248
     */
249
    public function getSelectedSecondFactorId()
250
    {
251
        return $this->get('selected_second_factor');
252
    }
253
254
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
255
     * @param bool $verified
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
256
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
257
     */
258
    public function setSecondFactorVerified($verified)
259
    {
260
        $this->set('selected_second_factor_verified', $verified);
261
262
        return $this;
263
    }
264
265
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
266
     * @return bool
267
     */
268
    public function isSecondFactorVerified()
269
    {
270
        return $this->get('selected_second_factor_verified') === true;
271
    }
272
273
    public function setVerifiedBySsoOn2faCookie(bool $isVerifiedByCookie): self
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setVerifiedBySsoOn2faCookie()
Loading history...
274
    {
275
        $this->set('verified_by_sso_on_2fa_cookie', $isVerifiedByCookie);
276
277
        return $this;
278
    }
279
280
    public function unsetVerifiedBySsoOn2faCookie(): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function unsetVerifiedBySsoOn2faCookie()
Loading history...
281
    {
282
        $this->set('verified_by_sso_on_2fa_cookie', null);
283
    }
284
285
    public function isVerifiedBySsoOn2faCookie(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isVerifiedBySsoOn2faCookie()
Loading history...
286
    {
287
        return $this->get('verified_by_sso_on_2fa_cookie') === true;
288
    }
289
290
    public function setSsoOn2faCookieFingerprint(string $fingerprint)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setSsoOn2faCookieFingerprint()
Loading history...
291
    {
292
        $this->set('sso_on_2fa_cookie_fingerprint', $fingerprint);
293
294
        return $this;
295
    }
296
297
    public function getSsoOn2faCookieFingerprint()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getSsoOn2faCookieFingerprint()
Loading history...
298
    {
299
        return $this->get('sso_on_2fa_cookie_fingerprint');
300
    }
301
302
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
303
     * @param string $controllerName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
304
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
305
     */
306
    public function setResponseAction($controllerName)
307
    {
308
        $this->set('response_controller', $controllerName);
309
        return $this;
310
    }
311
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
312
     * @return string|null
313
     */
314
    public function getResponseAction()
315
    {
316
        return $this->get('response_controller');
317
    }
318
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
319
     * @param string $serviceId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
320
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
321
     */
322
    public function setResponseContextServiceId($serviceId)
323
    {
324
        $this->set('response_context_service_id', $serviceId);
325
        return $this;
326
    }
327
328
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
329
     * @return string|null
330
     */
331
    public function getResponseContextServiceId()
332
    {
333
        return $this->get('response_context_service_id');
334
    }
335
336
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
337
     * @param $organization
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
338
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
339
     */
340
    public function setSchacHomeOrganization($organization)
341
    {
342
        $this->set('schac_home_organization', $organization);
343
        return $this;
344
    }
345
346
347
    public function setIsForceAuthn(bool $forceAuthn): self
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setIsForceAuthn()
Loading history...
348
    {
349
        $this->set('force_authn', $forceAuthn);
350
        return $this;
351
    }
352
353
354
    public function isForceAuthn(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isForceAuthn()
Loading history...
355
    {
356
        return $this->get('force_authn') === true;
357
    }
358
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
359
     * @return string|null
360
     */
361
    public function getSchacHomeOrganization()
362
    {
363
        return $this->get('schac_home_organization');
364
    }
365
366
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
367
     * @param string $locale
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
368
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
369
     */
370
    public function setPreferredLocale($locale)
371
    {
372
        $this->set('locale', $locale);
373
        return $this;
374
    }
375
376
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
377
     * @return string|null
378
     */
379
    public function getPreferredLocale()
380
    {
381
        return $this->get('locale');
382
    }
383
384
    /**
385
     * note that the authentication mode is stored outside the session path, to enable other state handlers
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
386
     * to retrieve the Authentication state for a given authentication request id.
387
     *
388
     * @param $requestId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
389
     * @param $authenticationMode
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
390
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
391
    public function markAuthenticationModeForRequest($requestId, $authenticationMode)
392
    {
393
        $this->session->set('surfnet/gateway/auth_mode/' . $requestId, $authenticationMode);
394
    }
395
396
    public function getAuthenticationModeForRequestId($requestId)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getAuthenticationModeForRequestId()
Loading history...
397
    {
398
        return $this->session->get('surfnet/gateway/auth_mode/' . $requestId);
399
    }
400
401
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
402
     * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
403
     * @param mixed $value Any scalar
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
404
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
405
    protected function set($key, $value)
406
    {
407
        $this->session->set($this->sessionPath . $key, $value);
408
    }
409
410
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
411
     * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
412
     * @return mixed|null Any scalar
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
413
     */
414
    protected function get($key)
415
    {
416
        return $this->session->get($this->sessionPath . $key);
417
    }
418
}
419