1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DataFlowServer\Authentication; |
5
|
|
|
|
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Controller\CreatePasswordAction; |
8
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Controller\GenerateTemporaryTokenAction; |
9
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Controller\GetTokenAction; |
10
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Controller\InvalidateTokenAction; |
11
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Controller\InvalidateTokensAction; |
12
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Controller\UpdatePasswordAction; |
13
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Factory\PasswordHydratorFactory; |
14
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Factory\TokenHydratorFactory; |
15
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Factory\TokenResourceMiddlewareFactory; |
16
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Hydrator\Strategy\HashStrategy; |
17
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Middleware\ActivePasswordMiddleware; |
18
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Middleware\PasswordConfirmationMiddleware; |
19
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Middleware\TokenMiddleware; |
20
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Repository\PasswordRepository; |
21
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Repository\TokenRepository; |
22
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Service\PasswordManager; |
23
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Service\TokenManager; |
24
|
|
|
use SlayerBirden\DataFlowServer\Authorization\PermissionManagerInterface; |
25
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry; |
26
|
|
|
use SlayerBirden\DataFlowServer\Domain\Repository\UserRepository; |
27
|
|
|
use SlayerBirden\DataFlowServer\Zend\InputFilter\ProxyFilterManagerFactory; |
28
|
|
|
use Zend\Expressive\Application; |
29
|
|
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; |
30
|
|
|
|
31
|
|
|
class ConfigProvider |
32
|
|
|
{ |
33
|
|
|
public function __invoke(): array |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
ConfigAbstractFactory::class => $this->getAbstractFactoryConfig(), |
37
|
|
|
'doctrine' => $this->getDoctrineConfig(), |
38
|
|
|
'dependencies' => $this->getDependenciesConfig(), |
39
|
|
|
'input_filter_specs' => [ |
40
|
|
|
'TokenInputFilter' => $this->getTokenInputFilterSpec(), |
41
|
|
|
'PasswordInputFilter' => $this->getPasswordInputFilterSpec(), |
42
|
|
|
'UpdatePasswordInputFilter' => $this->getUpdatePasswordInputFilterSpec(), |
43
|
|
|
'GetTokenInputFilter' => $this->getGetTokenInputFilterSpec(), |
44
|
|
|
], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function getTokenInputFilterSpec(): array |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
'resources' => [ |
52
|
|
|
'required' => true, |
53
|
|
|
'validators' => [ |
54
|
|
|
[ |
55
|
|
|
'name' => 'resourcesValidator', |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function getPasswordInputFilterSpec(): array |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
'password' => [ |
66
|
|
|
'required' => true, |
67
|
|
|
'validators' => [ |
68
|
|
|
[ |
69
|
|
|
'name' => 'stringLength', |
70
|
|
|
'options' => [ |
71
|
|
|
'min' => 10, |
72
|
|
|
], |
73
|
|
|
], |
74
|
|
|
], |
75
|
|
|
], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function getUpdatePasswordInputFilterSpec(): array |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
'new_password' => [ |
83
|
|
|
'required' => true, |
84
|
|
|
'validators' => [ |
85
|
|
|
[ |
86
|
|
|
'name' => 'stringLength', |
87
|
|
|
'options' => [ |
88
|
|
|
'min' => 10, |
89
|
|
|
], |
90
|
|
|
], |
91
|
|
|
], |
92
|
|
|
], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private function getGetTokenInputFilterSpec(): array |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
'resources' => [ |
100
|
|
|
'validators' => [ |
101
|
|
|
[ |
102
|
|
|
'name' => 'notempty', |
103
|
|
|
'break_chain_on_failure' => true, |
104
|
|
|
], |
105
|
|
|
[ |
106
|
|
|
'name' => 'resourcesValidator', |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
'password' => [ |
111
|
|
|
'validators' => [ |
112
|
|
|
[ |
113
|
|
|
'name' => 'notempty', |
114
|
|
|
], |
115
|
|
|
] |
116
|
|
|
], |
117
|
|
|
'user' => [ |
118
|
|
|
'validators' => [ |
119
|
|
|
[ |
120
|
|
|
'name' => 'notempty', |
121
|
|
|
], |
122
|
|
|
], |
123
|
|
|
], |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
private function getAbstractFactoryConfig(): array |
128
|
|
|
{ |
129
|
|
|
return [ |
130
|
|
|
TokenRepository::class => [ |
131
|
|
|
EntityManagerRegistry::class, |
132
|
|
|
], |
133
|
|
|
PasswordRepository::class => [ |
134
|
|
|
EntityManagerRegistry::class, |
135
|
|
|
], |
136
|
|
|
GenerateTemporaryTokenAction::class => [ |
137
|
|
|
'TokenInputFilter', |
138
|
|
|
TokenManagerInterface::class, |
139
|
|
|
LoggerInterface::class, |
140
|
|
|
'TokenHydrator', |
141
|
|
|
], |
142
|
|
|
TokenMiddleware::class => [ |
143
|
|
|
TokenRepository::class, |
144
|
|
|
], |
145
|
|
|
ActivePasswordMiddleware::class => [ |
146
|
|
|
PasswordRepository::class, |
147
|
|
|
], |
148
|
|
|
HashStrategy::class => [ |
149
|
|
|
PasswordManager::class, |
150
|
|
|
], |
151
|
|
|
PasswordConfirmationMiddleware::class => [ |
152
|
|
|
PasswordManager::class, |
153
|
|
|
], |
154
|
|
|
PasswordManager::class => [ |
155
|
|
|
PasswordRepository::class, |
156
|
|
|
LoggerInterface::class, |
157
|
|
|
], |
158
|
|
|
TokenManager::class => [ |
159
|
|
|
EntityManagerRegistry::class, |
160
|
|
|
UserRepository::class, |
161
|
|
|
PasswordManagerInterface::class, |
162
|
|
|
PermissionManagerInterface::class, |
163
|
|
|
], |
164
|
|
|
CreatePasswordAction::class => [ |
165
|
|
|
EntityManagerRegistry::class, |
166
|
|
|
'PasswordInputFilter', |
167
|
|
|
LoggerInterface::class, |
168
|
|
|
'PasswordHydrator', |
169
|
|
|
], |
170
|
|
|
UpdatePasswordAction::class => [ |
171
|
|
|
EntityManagerRegistry::class, |
172
|
|
|
PasswordRepository::class, |
173
|
|
|
'UpdatePasswordInputFilter', |
174
|
|
|
LoggerInterface::class, |
175
|
|
|
PasswordManager::class, |
176
|
|
|
'PasswordHydrator', |
177
|
|
|
], |
178
|
|
|
GetTokenAction::class => [ |
179
|
|
|
TokenManager::class, |
180
|
|
|
'TokenHydrator', |
181
|
|
|
'GetTokenInputFilter', |
182
|
|
|
LoggerInterface::class, |
183
|
|
|
], |
184
|
|
|
InvalidateTokenAction::class => [ |
185
|
|
|
EntityManagerRegistry::class, |
186
|
|
|
LoggerInterface::class, |
187
|
|
|
'TokenHydrator', |
188
|
|
|
], |
189
|
|
|
InvalidateTokensAction::class => [ |
190
|
|
|
EntityManagerRegistry::class, |
191
|
|
|
TokenRepository::class, |
192
|
|
|
UserRepository::class, |
193
|
|
|
LoggerInterface::class, |
194
|
|
|
'TokenHydrator', |
195
|
|
|
], |
196
|
|
|
]; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
private function getDoctrineConfig(): array |
200
|
|
|
{ |
201
|
|
|
return [ |
202
|
|
|
'entity_managers' => [ |
203
|
|
|
'default' => [ |
204
|
|
|
'paths' => [ |
205
|
|
|
'src/Authentication/Entities', |
206
|
|
|
], |
207
|
|
|
], |
208
|
|
|
], |
209
|
|
|
]; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
private function getDependenciesConfig(): array |
213
|
|
|
{ |
214
|
|
|
return [ |
215
|
|
|
'delegators' => [ |
216
|
|
|
Application::class => [ |
217
|
|
|
Factory\RoutesDelegator::class, |
218
|
|
|
], |
219
|
|
|
], |
220
|
|
|
'factories' => [ |
221
|
|
|
'TokenHydrator' => TokenHydratorFactory::class, |
222
|
|
|
'PasswordHydrator' => PasswordHydratorFactory::class, |
223
|
|
|
'TokenInputFilter' => ProxyFilterManagerFactory::class, |
224
|
|
|
'PasswordInputFilter' => ProxyFilterManagerFactory::class, |
225
|
|
|
'UpdatePasswordInputFilter' => ProxyFilterManagerFactory::class, |
226
|
|
|
'GetTokenInputFilter' => ProxyFilterManagerFactory::class, |
227
|
|
|
'TokenResourceMiddleware' => TokenResourceMiddlewareFactory::class, |
228
|
|
|
], |
229
|
|
|
'aliases' => [ |
230
|
|
|
TokenManagerInterface::class => TokenManager::class, |
231
|
|
|
PasswordManagerInterface::class => PasswordManager::class, |
232
|
|
|
], |
233
|
|
|
]; |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|