Completed
Pull Request — develop (#97)
by Boy
19:41 queued 16:38
created

ProxyStateHandler::setPreferredLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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
     * @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
     * @return string|null
53
     */
54
    public function getRequestId()
55
    {
56
        return $this->get('request_id');
57
    }
58
59
    /**
60
     * @param string $serviceProvider
61
     * @return $this
62
     */
63
    public function setRequestServiceProvider($serviceProvider)
64
    {
65
        $this->set('service_provider', $serviceProvider);
66
67
        return $this;
68
    }
69
70
    /**
71
     * @return string|null
72
     */
73
    public function getRequestServiceProvider()
74
    {
75
        return $this->get('service_provider');
76
    }
77
78
    /**
79
     * @param string $relayState
80
     * @return $this
81
     */
82
    public function setRelayState($relayState)
83
    {
84
        $this->set('relay_state', $relayState);
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return string|null
91
     */
92
    public function getRelayState()
93
    {
94
        return $this->get('relay_state');
95
    }
96
97
    /**
98
     * @param string $loaIdentifier
99
     * @return $this
100
     */
101
    public function setRequiredLoaIdentifier($loaIdentifier)
102
    {
103
        $this->set('loa_identifier', $loaIdentifier);
104
105
        return $this;
106
    }
107
108
    /**
109
     * @return string|null
110
     */
111
    public function getRequiredLoaIdentifier()
112
    {
113
        return $this->get('loa_identifier');
114
    }
115
116
    /**
117
     * @param string $requestId
118
     * @return $this
119
     */
120
    public function setGatewayRequestId($requestId)
121
    {
122
        $this->set('gateway_request_id', $requestId);
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return string|null
129
     */
130
    public function getGatewayRequestId()
131
    {
132
        return $this->get('gateway_request_id');
133
    }
134
135
    /**
136
     * @param string $assertionAsXmlString
137
     * @return $this
138
     */
139
    public function saveAssertion($assertionAsXmlString)
140
    {
141
        $this->set('response_assertion', $assertionAsXmlString);
142
143
        return $this;
144
    }
145
146
    /**
147
     * @return null|string
148
     */
149
    public function getAssertion()
150
    {
151
        return $this->get('response_assertion');
152
    }
153
154
    /**
155
     * @param $nameId
156
     * @return $this
157
     */
158
    public function saveIdentityNameId($nameId)
159
    {
160
        $this->set('name_id', $nameId);
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return null|string
167
     */
168
    public function getIdentityNameId()
169
    {
170
        return $this->get('name_id');
171
    }
172
173
    /**
174
     * @param string $idpEntityId
175
     * @return $this
176
     */
177
    public function setAuthenticatingIdp($idpEntityId)
178
    {
179
        $this->set('authenticating_idp', $idpEntityId);
180
181
        return $this;
182
    }
183
184
    /**
185
     * @return null|string
186
     */
187
    public function getAuthenticatingIdp()
188
    {
189
        return $this->get('authenticating_idp');
190
    }
191
192
    /**
193
     * @param string|null $secondFactorId
194
     * @return $this
195
     */
196
    public function setSelectedSecondFactorId($secondFactorId)
197
    {
198
        $this->set('selected_second_factor', $secondFactorId);
199
200
        return $this;
201
    }
202
203
    /**
204
     * @return null|string
205
     */
206
    public function getSelectedSecondFactorId()
207
    {
208
        return $this->get('selected_second_factor');
209
    }
210
211
    /**
212
     * @param bool $verified
213
     * @return $this
214
     */
215
    public function setSecondFactorVerified($verified)
216
    {
217
        $this->set('selected_second_factor_verified', $verified);
218
219
        return $this;
220
    }
221
222
    /**
223
     * @return bool
224
     */
225
    public function isSecondFactorVerified()
226
    {
227
        return $this->get('selected_second_factor_verified') === true;
228
    }
229
230
    /**
231
     * @param string $controllerName
232
     * @return $this
233
     */
234
    public function setResponseAction($controllerName)
235
    {
236
        $this->set('response_controller', $controllerName);
237
        return $this;
238
    }
239
    /**
240
     * @return string|null
241
     */
242
    public function getResponseAction()
243
    {
244
        return $this->get('response_controller');
245
    }
246
    /**
247
     * @param string $serviceId
248
     * @return $this
249
     */
250
    public function setResponseContextServiceId($serviceId)
251
    {
252
        $this->set('response_context_service_id', $serviceId);
253
        return $this;
254
    }
255
    /**
256
     * @return string|null
257
     */
258
    public function getResponseContextServiceId()
259
    {
260
        return $this->get('response_context_service_id');
261
    }
262
263
    /**
264
     * @param string $locale
265
     * @return $this
266
     */
267
    public function setPreferredLocale($locale)
268
    {
269
        $this->set('locale', $locale);
270
        return $this;
271
    }
272
273
    /**
274
     * @return string|null
275
     */
276
    public function getPreferredLocale()
277
    {
278
        return $this->get('locale');
279
    }
280
281
    /**
282
     * @param string $key
283
     * @param mixed $value Any scalar
284
     */
285
    protected function set($key, $value)
286
    {
287
        $this->session->set(self::SESSION_PATH . $key, $value);
288
    }
289
290
    /**
291
     * @param string $key
292
     * @return mixed|null Any scalar
293
     */
294
    protected function get($key)
295
    {
296
        return $this->session->get(self::SESSION_PATH . $key);
297
    }
298
}
299