|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AerialShip\SamlSPBundle\State\Request; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
|
6
|
|
|
|
|
7
|
|
|
class SessionStore implements RequestStateStoreInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var \Symfony\Component\HttpFoundation\Session\SessionInterface */ |
|
10
|
|
|
protected $session; |
|
11
|
|
|
|
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
protected $providerID; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param SessionInterface $session |
|
18
|
|
|
* @param string $providerID |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(SessionInterface $session, $providerID) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->session = $session; |
|
23
|
|
|
$this->providerID = $providerID; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param RequestState $state |
|
29
|
|
|
* @throws \InvalidArgumentException |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function set(RequestState $state) |
|
33
|
|
|
{ |
|
34
|
|
|
$key = "saml_state_{$this->providerID}"; |
|
35
|
|
|
$arr = $this->session->get($key, array()); |
|
36
|
|
|
$arr[$state->getId()] = $state; |
|
37
|
|
|
$this->session->set($key, $arr); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $id |
|
42
|
|
|
* @return RequestState|null |
|
43
|
|
|
*/ |
|
44
|
|
|
public function get($id) |
|
45
|
|
|
{ |
|
46
|
|
|
$result = null; |
|
47
|
|
|
$key = "saml_state_{$this->providerID}"; |
|
48
|
|
|
$arr = $this->session->get($key); |
|
49
|
|
|
if (!is_array($arr)) { |
|
50
|
|
|
$arr = array(); |
|
51
|
|
|
$this->session->set($key, $arr); |
|
52
|
|
|
} |
|
53
|
|
|
if (isset($arr[$id])) { |
|
54
|
|
|
$result = $arr[$id]; |
|
55
|
|
|
} |
|
56
|
|
|
if ($result instanceof RequestState) { |
|
57
|
|
|
return $result; |
|
58
|
|
|
} |
|
59
|
|
|
return null; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param RequestState $state |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function remove(RequestState $state) |
|
67
|
|
|
{ |
|
68
|
|
|
$key = "saml_state_{$this->providerID}"; |
|
69
|
|
|
$arr = $this->session->get($key, array()); |
|
70
|
|
|
$result = isset($arr[$state->getId()]); |
|
71
|
|
|
unset($arr[$state->getId()]); |
|
72
|
|
|
$this->session->set($key, $arr); |
|
73
|
|
|
return $result; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function clear() |
|
80
|
|
|
{ |
|
81
|
|
|
$key = "saml_state_{$this->providerID}"; |
|
82
|
|
|
$this->session->set($key, array()); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|