|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Logout package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the GPL-3 license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Logout\Resolver\Logout; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\State\Sso\SsoSessionState; |
|
15
|
|
|
use LightSaml\State\Sso\SsoState; |
|
16
|
|
|
use LightSaml\Store\Sso\SsoStateStoreInterface; |
|
17
|
|
|
|
|
18
|
|
|
class LogoutSessionResolver implements LogoutSessionResolverInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var SsoStateStoreInterface */ |
|
21
|
|
|
protected $ssoStateStore; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param SsoStateStoreInterface $ssoStateStore |
|
25
|
|
|
*/ |
|
26
|
10 |
|
public function __construct(SsoStateStoreInterface $ssoStateStore) |
|
27
|
|
|
{ |
|
28
|
10 |
|
$this->ssoStateStore = $ssoStateStore; |
|
29
|
10 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $ownEntityId |
|
33
|
|
|
* |
|
34
|
|
|
* @return SsoSessionState|null |
|
35
|
|
|
*/ |
|
36
|
9 |
|
public function resolve($ownEntityId) |
|
37
|
|
|
{ |
|
38
|
9 |
|
$ssoState = $this->ssoStateStore->get(); |
|
39
|
|
|
|
|
40
|
9 |
|
$result = $this->getSpSession($ssoState, $ownEntityId); |
|
41
|
9 |
|
if ($result) { |
|
42
|
4 |
|
return $result; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
5 |
|
$result = $this->getIdpSession($ssoState, $ownEntityId); |
|
46
|
|
|
|
|
47
|
5 |
|
return $result; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function terminateSession($entityId, $nameId, $nameIdFormat, $sessionIndex = null) |
|
51
|
|
|
{ |
|
52
|
|
|
$ssoState = $this->ssoStateStore->get(); |
|
53
|
|
|
|
|
54
|
|
|
$count = 0; |
|
55
|
|
|
|
|
56
|
9 |
|
$ssoState->modify(function (SsoSessionState $session) use ($entityId, $nameId, $nameIdFormat, &$count) { |
|
|
|
|
|
|
57
|
|
|
if (($session->getIdpEntityId() == $entityId || $session->getSpEntityId() == $entityId) && |
|
58
|
9 |
|
$session->getNameId() == $nameId && |
|
59
|
|
|
$session->getNameIdFormat() == $nameIdFormat |
|
60
|
9 |
|
) { |
|
61
|
|
|
++$count; |
|
62
|
|
|
|
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return true; |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
5 |
|
$this->ssoStateStore->set($ssoState); |
|
70
|
|
|
|
|
71
|
5 |
|
return $count; |
|
72
|
|
|
} |
|
73
|
5 |
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param SsoState $ssoState |
|
76
|
|
|
* @param string $ownEntityId |
|
77
|
|
|
* |
|
78
|
|
|
* @return SsoSessionState|null |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function getSpSession(SsoState $ssoState, $ownEntityId) |
|
81
|
|
|
{ |
|
82
|
|
|
$spSessions = $ssoState->filter($ownEntityId, null, null, null, null); |
|
83
|
|
|
|
|
84
|
|
|
return array_shift($spSessions); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param SsoState $ssoState |
|
89
|
|
|
* @param string $ownEntityId |
|
90
|
|
|
* |
|
91
|
|
|
* @return SsoSessionState|null |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getIdpSession(SsoState $ssoState, $ownEntityId) |
|
94
|
|
|
{ |
|
95
|
|
|
$idpSessions = $ssoState->filter(null, $ownEntityId, null, null, null); |
|
96
|
|
|
|
|
97
|
|
|
return array_shift($idpSessions); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.