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; |
13
|
|
|
|
14
|
|
|
use Dotenv\Dotenv; |
15
|
|
|
use Psr\Container\ContainerExceptionInterface; |
16
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
17
|
|
|
use Slick\Di\ContainerInterface; |
18
|
|
|
use Slick\ModuleApi\Infrastructure\AbstractModule; |
19
|
|
|
use Slick\ModuleApi\Infrastructure\Console\ConsoleModuleInterface; |
20
|
|
|
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewareHandler; |
21
|
|
|
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewarePosition; |
|
|
|
|
22
|
|
|
use Slick\ModuleApi\Infrastructure\FrontController\Position; |
23
|
|
|
use Slick\ModuleApi\Infrastructure\FrontController\WebModuleInterface; |
24
|
|
|
use Slick\WebStack\Infrastructure\Http\AuthorizationMiddleware; |
|
|
|
|
25
|
|
|
use Slick\WebStack\Infrastructure\Http\SecurityMiddleware; |
|
|
|
|
26
|
|
|
use Slick\WebStack\UserInterface\Console\Security\GenerateSecretCommand; |
27
|
|
|
use Slick\WebStack\UserInterface\Console\Security\HashPassword; |
28
|
|
|
use Symfony\Component\Console\Application; |
29
|
|
|
use function Slick\ModuleApi\importSettingsFile; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* SecurityModule |
33
|
|
|
* |
34
|
|
|
* @package Slick\WebStack |
35
|
|
|
*/ |
36
|
|
|
final class SecurityModule extends AbstractModule implements ConsoleModuleInterface, WebModuleInterface |
37
|
|
|
{ |
38
|
|
|
public function description(): string |
39
|
|
|
{ |
40
|
|
|
return "Provides authentication and authorization support for web applications."; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @throws ContainerExceptionInterface |
46
|
|
|
* @throws NotFoundExceptionInterface |
47
|
|
|
*/ |
48
|
|
|
public function configureConsole(Application $cli, ContainerInterface $container): void |
49
|
|
|
{ |
50
|
|
|
$cli->add($container->get(HashPassword::class)); |
51
|
|
|
$cli->add($container->get(GenerateSecretCommand::class)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritDoc |
56
|
|
|
*/ |
57
|
|
|
public function services(): array |
58
|
|
|
{ |
59
|
|
|
return importSettingsFile(dirname(__DIR__) . '/config/security.php'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritDoc |
64
|
|
|
*/ |
65
|
|
|
public function settings(Dotenv $dotenv): array |
66
|
|
|
{ |
67
|
|
|
$dotenv->required('APP_SECRET'); |
68
|
|
|
return []; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function middlewareHandlers(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
new MiddlewareHandler( |
75
|
|
|
'security', |
76
|
|
|
new MiddlewarePosition(Position::Before, 'router'), |
77
|
|
|
SecurityMiddleware::class |
78
|
|
|
), |
79
|
|
|
new MiddlewareHandler( |
80
|
|
|
'authorization', |
81
|
|
|
new MiddlewarePosition(Position::Before, 'dispatcher'), |
82
|
|
|
AuthorizationMiddleware::class |
83
|
|
|
), |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths