|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AerialShip\SamlSPBundle\Bridge; |
|
4
|
|
|
|
|
5
|
|
|
use AerialShip\SamlSPBundle\Config\ServiceInfo; |
|
6
|
|
|
use AerialShip\SamlSPBundle\Model\SSOState; |
|
7
|
|
|
use AerialShip\SamlSPBundle\State\SSO\SSOStateStoreInterface; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\Security\Http\HttpUtils; |
|
10
|
|
|
|
|
11
|
|
|
class LogoutBase |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var SSOStateStoreInterface */ |
|
14
|
|
|
protected $ssoStore; |
|
15
|
|
|
|
|
16
|
|
|
/** @var \Symfony\Component\Security\Http\HttpUtils */ |
|
17
|
|
|
protected $httpUtils; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
public function __construct(SSOStateStoreInterface $ssoStore, HttpUtils $httpUtils) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->ssoStore = $ssoStore; |
|
24
|
|
|
$this->httpUtils = $httpUtils; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param Request $request |
|
30
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function getLogoutRedirectResponse(Request $request) |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->httpUtils->createRedirectResponse($request, $request->attributes->get('local_logout_path')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param ServiceInfo $serviceInfo |
|
39
|
|
|
* @param string $nameID |
|
40
|
|
|
* @param string $sessionIndex |
|
41
|
|
|
* @return SSOState[] |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function getSSOState(ServiceInfo $serviceInfo, $nameID, $sessionIndex) |
|
44
|
|
|
{ |
|
45
|
|
|
if ($sessionIndex) { |
|
46
|
|
|
$result = array(); |
|
47
|
|
|
$state = $this->ssoStore->getOneByNameIDSessionIndex( |
|
48
|
|
|
$serviceInfo->getProviderID(), |
|
49
|
|
|
$serviceInfo->getAuthenticationService(), |
|
50
|
|
|
$nameID, |
|
51
|
|
|
$sessionIndex |
|
52
|
|
|
); |
|
53
|
|
|
if ($state) { |
|
54
|
|
|
$result[] = $state; |
|
55
|
|
|
} |
|
56
|
|
|
} else { |
|
57
|
|
|
$result = $this->ssoStore->getAllByNameID( |
|
58
|
|
|
$serviceInfo->getProviderID(), |
|
59
|
|
|
$serviceInfo->getAuthenticationService(), |
|
60
|
|
|
$nameID |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
return $result; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
protected function deleteSSOState(array $arrStates) |
|
68
|
|
|
{ |
|
69
|
|
|
foreach ($arrStates as $state) { |
|
70
|
|
|
$this->ssoStore->remove($state); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|