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

StateHandler::getAssertionConsumerServiceUrl()   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 2017 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\SecondFactorOnlyBundle\Adfs;
20
21
use Symfony\Component\HttpFoundation\Session\SessionInterface;
22
23
class StateHandler
24
{
25
    const SESSION_PATH = 'surfnet/gateway/adfs';
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
     * @param string $originalRequestId
42
     * @return $this
43
     */
44
    public function setRequestId($originalRequestId)
45
    {
46
        $this->set('request_id', $originalRequestId);
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param string $authMethod
53
     * @return $this
54
     */
55
    public function setAuthMethod($authMethod)
56
    {
57
        $this->set('auth_method', $authMethod);
58
59
        return $this;
60
    }
61
62
    /**
63
     * @param string $context
64
     * @return $this
65
     */
66
    public function setContext($context)
67
    {
68
        $this->set('context', $context);
69
70
        return $this;
71
    }
72
73
    /**
74
     * @return mixed|null
75
     */
76
    public function getRequestId()
77
    {
78
        return $this->get('request_id');
79
    }
80
81
    /**
82
     * @return mixed|null
83
     */
84
    public function getAuthMethod()
85
    {
86
        return $this->get('auth_method');
87
    }
88
89
    /**
90
     * @return mixed|null
91
     */
92
    public function getContext()
93
    {
94
        return $this->get('context');
95
    }
96
97
    /**
98
     * @param string $requestId
99
     * @return bool
100
     */
101
    public function hasMatchingRequestId($requestId)
102
    {
103
        $requestIdFromSession = $this->get('request_id');
104
        if ($requestIdFromSession && $requestIdFromSession == $requestId) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $requestIdFromSes...mSession == $requestId;.
Loading history...
105
            return true;
106
        }
107
108
        return false;
109
    }
110
111
    /**
112
     * @param string $key
113
     * @param mixed $value Any scalar
114
     */
115
    protected function set($key, $value)
116
    {
117
        $this->session->set(self::SESSION_PATH . $key, $value);
118
    }
119
120
    /**
121
     * @param string $key
122
     * @return mixed|null Any scalar
123
     */
124
    protected function get($key)
125
    {
126
        return $this->session->get(self::SESSION_PATH . $key);
127
    }
128
}
129