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