|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\ServerBundle\Component\Firewall; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessTokenHandler; |
|
17
|
|
|
use OAuth2Framework\ServerBundle\Annotation\Checker\Checker; |
|
18
|
|
|
use OAuth2Framework\ServerBundle\Component\Component; |
|
19
|
|
|
use OAuth2Framework\ServerBundle\Security\Factory\OAuth2SecurityFactory; |
|
20
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
21
|
|
|
use Symfony\Component\Config\FileLocator; |
|
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
|
24
|
|
|
|
|
25
|
|
|
final class FirewallSource implements Component |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function name(): string |
|
31
|
|
|
{ |
|
32
|
|
|
return 'firewall'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
39
|
|
|
{ |
|
40
|
|
|
$config = $configs['firewall']; |
|
41
|
|
|
$container->setParameter('oauth2_server.firewall.enabled', $config['enabled']); |
|
42
|
|
|
if (!$config['enabled']) { |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$container->registerForAutoconfiguration(Checker::class)->addTag('oauth2_security_annotation_checker'); |
|
47
|
|
|
$container->registerForAutoconfiguration(AccessTokenHandler::class)->addTag('oauth2_access_token_handler'); |
|
48
|
|
|
|
|
49
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config/firewall')); |
|
50
|
|
|
$loader->load('security.php'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function build(ContainerBuilder $container) |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var \Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension $extension */ |
|
59
|
|
|
$extension = $container->getExtension('security'); |
|
60
|
|
|
$extension->addSecurityListenerFactory(new OAuth2SecurityFactory()); |
|
61
|
|
|
|
|
62
|
|
|
$container->addCompilerPass(new SecurityAnnotationCheckerCompilerPass()); |
|
63
|
|
|
$container->addCompilerPass(new AccessTokenHandlerCompilerPass()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode) |
|
70
|
|
|
{ |
|
71
|
|
|
$node->children() |
|
72
|
|
|
->arrayNode($this->name()) |
|
73
|
|
|
->canBeEnabled() |
|
74
|
|
|
->end() |
|
75
|
|
|
->end(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
|
82
|
|
|
{ |
|
83
|
|
|
return []; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|