|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of web-stack |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Slick\WebStack\Domain\Security\Http\SecurityProfile; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
15
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
16
|
|
|
use Slick\Http\Session\SessionDriverInterface; |
|
17
|
|
|
use Slick\WebStack\Domain\Security\Authentication\Token\TokenStorageInterface; |
|
18
|
|
|
use Slick\WebStack\Domain\Security\Authentication\Token\TokenValidatorInterface; |
|
19
|
|
|
use Slick\WebStack\Domain\Security\Authentication\TokenInterface; |
|
20
|
|
|
use Slick\WebStack\Domain\Security\Http\SecurityProfile\StatefulSecurityProfile\SessionSecurityProfile; |
|
21
|
|
|
use Slick\WebStack\Domain\Security\Http\SecurityProfileInterface; |
|
22
|
|
|
use Slick\WebStack\Domain\Security\UserInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* DisabledSecurityProfile |
|
26
|
|
|
* |
|
27
|
|
|
* @package Slick\WebStack\Domain\Security\Http\SecurityProfile |
|
28
|
|
|
* @implements StatefulSecurityProfileInterface<UserInterface> |
|
29
|
|
|
*/ |
|
30
|
|
|
final class DisabledSecurityProfile implements SecurityProfileInterface, StatefulSecurityProfileInterface |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
use SecurityProfileTrait; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Creates a Disabled Security Profile |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $matchExp The match expression. |
|
39
|
|
|
* @param TokenStorageInterface<UserInterface>|null $tokenStorage |
|
40
|
|
|
* @param SessionDriverInterface|null $session |
|
41
|
|
|
* @param TokenValidatorInterface|null $tokenValidator |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
string $matchExp, |
|
45
|
|
|
private readonly ?TokenStorageInterface $tokenStorage = null, |
|
46
|
|
|
private readonly ?SessionDriverInterface $session = null, |
|
47
|
|
|
private readonly ?TokenValidatorInterface $tokenValidator = null |
|
48
|
|
|
) { |
|
49
|
|
|
$this->matchExp = $matchExp; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritDoc |
|
54
|
|
|
*/ |
|
55
|
|
|
|
|
56
|
|
|
public function process(ServerRequestInterface $request): ?ResponseInterface |
|
57
|
|
|
{ |
|
58
|
|
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritDoc |
|
63
|
|
|
*/ |
|
64
|
|
|
|
|
65
|
|
|
public function authenticationErrors(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return []; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function restoreToken(): ?TokenInterface |
|
71
|
|
|
{ |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
if (!$token = $this->session?->get(SessionSecurityProfile::SESSION_KEY)) { |
|
75
|
|
|
return null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ($this->tokenValidator && !$this->tokenValidator->validate($token)) { |
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$this->tokenStorage?->setToken($token); |
|
84
|
|
|
return $token; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @inheritDoc |
|
89
|
|
|
*/ |
|
90
|
|
|
public function logout(): void |
|
91
|
|
|
{ |
|
92
|
|
|
// nothing to do here. |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @inheritDoc |
|
97
|
|
|
*/ |
|
98
|
|
|
public function processEntryPoint(ServerRequestInterface $request): ?ResponseInterface |
|
99
|
|
|
{ |
|
100
|
|
|
return null; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @inheritDoc |
|
105
|
|
|
*/ |
|
106
|
|
|
public function acl(): array |
|
107
|
|
|
{ |
|
108
|
|
|
return []; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function login(TokenInterface $token): void |
|
112
|
|
|
{ |
|
113
|
|
|
// Tdo nothing |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|