|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Krtv\Bundle\SingleSignOnIdentityProviderBundle\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
|
6
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class LogoutManager |
|
10
|
|
|
* @package Krtv\Bundle\SingleSignOnIdentityProviderBundle\Manager |
|
11
|
|
|
*/ |
|
12
|
|
|
class LogoutManager |
|
13
|
|
|
{ |
|
14
|
|
|
const SERVICE_SESSION_NS = '_logout/processed'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var RouterInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $router; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var SessionInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $session; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ServiceManager |
|
28
|
|
|
*/ |
|
29
|
|
|
private $serviceManager; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param ServiceManager $serviceManager |
|
33
|
|
|
* @param SessionInterface $session |
|
34
|
|
|
* @param RouterInterface $router |
|
35
|
|
|
*/ |
|
36
|
4 |
|
public function __construct(ServiceManager $serviceManager, SessionInterface $session, RouterInterface $router) |
|
37
|
|
|
{ |
|
38
|
4 |
|
$this->serviceManager = $serviceManager; |
|
39
|
4 |
|
$this->session = $session; |
|
40
|
4 |
|
$this->router = $router; |
|
41
|
4 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
6 |
|
public function getNextLogoutUrl() |
|
47
|
|
|
{ |
|
48
|
6 |
|
$referrerService = $this->serviceManager->getRequestService(); |
|
49
|
|
|
|
|
50
|
6 |
|
if ($referrerService !== null) { |
|
51
|
5 |
|
$this->addProcessedService($referrerService); |
|
52
|
5 |
|
} |
|
53
|
|
|
|
|
54
|
6 |
|
$availableServices = $this->serviceManager->getServices(); |
|
55
|
6 |
|
$completedServices = $this->getCompletedServices(); |
|
56
|
|
|
|
|
57
|
6 |
|
$nextService = null; |
|
58
|
6 |
|
foreach ($availableServices as $service) { |
|
59
|
6 |
|
if (in_array($service, $completedServices)) { |
|
60
|
5 |
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
5 |
|
$nextService = $service; |
|
64
|
|
|
|
|
65
|
5 |
|
break; |
|
66
|
6 |
|
} |
|
67
|
|
|
|
|
68
|
6 |
|
if ($nextService !== null) { |
|
69
|
5 |
|
$serviceManager = $this->serviceManager->getServiceManager($nextService); |
|
70
|
|
|
|
|
71
|
5 |
|
return $serviceManager->getServiceLogoutUrl(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
return $this->router->generate('_security_logout'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $service |
|
79
|
|
|
*/ |
|
80
|
5 |
|
private function addProcessedService($service) |
|
81
|
|
|
{ |
|
82
|
5 |
|
$services = $this->getCompletedServices(); |
|
83
|
5 |
|
$services[$service] = $service; |
|
84
|
|
|
|
|
85
|
5 |
|
$this->session->set($this->getSessionKey(), $services); |
|
86
|
5 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return mixed |
|
90
|
|
|
*/ |
|
91
|
6 |
|
private function getCompletedServices() |
|
92
|
|
|
{ |
|
93
|
6 |
|
return $this->session->get($this->getSessionKey(), array()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
6 |
|
private function getSessionKey() |
|
100
|
|
|
{ |
|
101
|
6 |
|
return static::SERVICE_SESSION_NS; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|