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
|
|
|
* @param string $acsUrl |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function setAssertionConsumerServiceUrl($acsUrl) |
78
|
|
|
{ |
79
|
|
|
$this->set('acs_url', $acsUrl); |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return mixed|null |
86
|
|
|
*/ |
87
|
|
|
public function getRequestId() |
88
|
|
|
{ |
89
|
|
|
return $this->get('request_id'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return mixed|null |
94
|
|
|
*/ |
95
|
|
|
public function getAuthMethod() |
96
|
|
|
{ |
97
|
|
|
return $this->get('auth_method'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return mixed|null |
102
|
|
|
*/ |
103
|
|
|
public function getContext() |
104
|
|
|
{ |
105
|
|
|
return $this->get('context'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return mixed|null |
110
|
|
|
*/ |
111
|
|
|
public function getAssertionConsumerServiceUrl() |
112
|
|
|
{ |
113
|
|
|
return $this->get('acs_url'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string $requestId |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function hasMatchingRequestId($requestId) |
121
|
|
|
{ |
122
|
|
|
$requestIdFromSession = $this->get('request_id'); |
123
|
|
|
if ($requestIdFromSession && $requestIdFromSession == $requestId) { |
|
|
|
|
124
|
|
|
return true; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $key |
132
|
|
|
* @param mixed $value Any scalar |
133
|
|
|
*/ |
134
|
|
|
protected function set($key, $value) |
135
|
|
|
{ |
136
|
|
|
$this->session->set(self::SESSION_PATH . $key, $value); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $key |
141
|
|
|
* @return mixed|null Any scalar |
142
|
|
|
*/ |
143
|
|
|
protected function get($key) |
144
|
|
|
{ |
145
|
|
|
return $this->session->get(self::SESSION_PATH . $key); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|