Completed
Push — 8.7 ( b6d8c1...3ac046 )
by Markus
06:49
created

SessionSsoStateStore   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
c 1
b 0
f 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 5 1
A __construct() 0 3 1
A get() 0 25 3
1
<?php
2
3
namespace DMK\MKSamlAuth\Store;
4
5
use DMK\MKSamlAuth\Session\PhpSession;
6
use LightSaml\Meta\ParameterBag;
7
use LightSaml\State\Sso\SsoSessionState;
8
use LightSaml\State\Sso\SsoState;
9
use LightSaml\Store\Sso\SsoStateStoreInterface;
10
use TYPO3\CMS\Core\SingletonInterface;
11
12
class SessionSsoStateStore implements SsoStateStoreInterface, SingletonInterface
13
{
14
    private const SESSION_KEY = 'sso_state';
15
16
    /**
17
     * @var PhpSession
18
     */
19
    private $session;
20
21
    public function __construct(PhpSession $session)
22
    {
23
        $this->session = $session;
24
    }
25
26
    public function set(SsoState $ssoState)
27
    {
28
        $this->session->set(self::SESSION_KEY, serialize($ssoState));
29
30
        $ssoState->setLocalSessionId($this->session->getId());
31
    }
32
33
    public function get()
34
    {
35
        $data = $this->session->get(self::SESSION_KEY);
36
37
        if (!is_string($data)) {
38
            $state = new SsoState();
39
            $this->set($state);
40
41
            return $state;
42
        }
43
44
        $data = unserialize($data, [
45
            'allowed_classes' => [
46
                SsoState::class,
47
                ParameterBag::class,
48
                SsoSessionState::class
49
            ]
50
        ]);
51
52
        if (false === $data) {
53
            $state = new SsoState();
54
            $this->set($state);
55
        }
56
57
        return $data;
58
    }
59
}
60