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\Action\Profile\Outbound\LogoutRequest; |
13
|
|
|
|
14
|
|
|
use LightSaml\Action\ActionInterface; |
15
|
|
|
use LightSaml\Action\Profile\AbstractProfileAction; |
16
|
|
|
use LightSaml\Context\Profile\Helper\LogHelper; |
17
|
|
|
use LightSaml\Context\Profile\ProfileContext; |
18
|
|
|
use LightSaml\Logout\Resolver\Logout\LogoutSessionResolverInterface; |
19
|
|
|
use Psr\Log\LoggerInterface; |
20
|
|
|
|
21
|
|
|
class LogoutResolveAction extends AbstractProfileAction |
22
|
|
|
{ |
23
|
|
|
/** @var LogoutSessionResolverInterface */ |
24
|
|
|
protected $logoutSessionResolver; |
25
|
|
|
|
26
|
|
|
/** @var ActionInterface */ |
27
|
|
|
protected $logoutProceedAction; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param LoggerInterface $logger |
31
|
|
|
* @param LogoutSessionResolverInterface $logoutSessionResolver |
32
|
|
|
* @param ActionInterface $logoutProceedAction |
33
|
3 |
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
LoggerInterface $logger, |
36
|
|
|
LogoutSessionResolverInterface $logoutSessionResolver, |
37
|
|
|
ActionInterface $logoutProceedAction |
38
|
3 |
|
) { |
39
|
|
|
parent::__construct($logger); |
40
|
3 |
|
|
41
|
3 |
|
$this->logoutSessionResolver = $logoutSessionResolver; |
42
|
3 |
|
$this->logoutProceedAction = $logoutProceedAction; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ProfileContext $context |
47
|
2 |
|
*/ |
48
|
|
|
protected function doExecute(ProfileContext $context) |
49
|
2 |
|
{ |
50
|
2 |
|
$logoutContext = $context->getLogoutContext(); |
51
|
2 |
|
$ssoSessionState = $logoutContext->getSsoSessionState(); |
52
|
1 |
View Code Duplication |
if ($ssoSessionState) { |
|
|
|
|
53
|
1 |
|
$this->logger->debug( |
54
|
1 |
|
'SSO session already set', |
55
|
1 |
|
LogHelper::getActionContext($context, $this, array( |
56
|
|
|
'sso_session' => $ssoSessionState, |
57
|
2 |
|
)) |
58
|
|
|
); |
59
|
|
|
} else { |
60
|
|
|
$this->logger->debug( |
61
|
|
|
'SSO session not defined, about to resolve it', |
62
|
|
|
LogHelper::getActionContext($context, $this, array()) |
63
|
|
|
); |
64
|
|
|
$ssoSessionState = $this->logoutSessionResolver->resolve($context->getOwnEntityDescriptor()->getEntityID()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
if ($ssoSessionState) { |
|
|
|
|
68
|
|
|
$this->logger->debug( |
69
|
|
|
'SSO session resolved and being used for logout profile', |
70
|
|
|
LogHelper::getActionContext($context, $this, array( |
71
|
|
|
'sso_session' => $ssoSessionState, |
72
|
|
|
)) |
73
|
|
|
); |
74
|
|
|
$logoutContext->setSsoSessionState($ssoSessionState); |
75
|
|
|
$this->logoutProceedAction->execute($context); |
76
|
|
|
} else { |
77
|
|
|
$this->logger->debug( |
78
|
|
|
'There is no SSO session for logout', |
79
|
|
|
LogHelper::getActionContext($context, $this, array()) |
80
|
|
|
); |
81
|
|
|
$logoutContext->setAllSsoSessionsTerminated(true); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.