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\SecurityBundle\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\BearerTokenType\BearerToken; |
17
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessTokenHandler; |
18
|
|
|
use OAuth2Framework\Component\MacTokenType\MacToken; |
19
|
|
|
use OAuth2Framework\SecurityBundle\Annotation\Checker\Checker; |
20
|
|
|
use Symfony\Component\Config\Definition\Processor; |
21
|
|
|
use Symfony\Component\Config\FileLocator; |
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
23
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
24
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
25
|
|
|
|
26
|
|
|
final class OAuth2FrameworkSecurityExtension extends Extension |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $alias; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* OAuth2FrameworkSecurityExtension constructor. |
35
|
|
|
* |
36
|
|
|
* @param string $alias |
37
|
|
|
*/ |
38
|
|
|
public function __construct(string $alias) |
39
|
|
|
{ |
40
|
|
|
$this->alias = $alias; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function getAlias() |
47
|
|
|
{ |
48
|
|
|
return $this->alias; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function load(array $configs, ContainerBuilder $container) |
55
|
|
|
{ |
56
|
|
|
$processor = new Processor(); |
57
|
|
|
$config = $processor->processConfiguration($this->getConfiguration($configs, $container), $configs); |
58
|
|
|
|
59
|
|
|
$container->setAlias('oauth2_security.psr7_message_factory', $config['psr7_message_factory']); |
60
|
|
|
|
61
|
|
|
$container->registerForAutoconfiguration(Checker::class)->addTag('oauth2_security_annotation_checker'); |
62
|
|
|
$container->registerForAutoconfiguration(AccessTokenHandler::class)->addTag('oauth2_security_token_handler'); |
63
|
|
|
|
64
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/')); |
65
|
|
|
$loader->load('security.php'); |
66
|
|
|
|
67
|
|
|
if (class_exists(BearerToken::class) && $config['bearer_token']['enabled']) { |
68
|
|
|
$container->setParameter('oauth2_security.token_type.bearer_token.realm', $config['bearer_token']['realm']); |
69
|
|
|
$container->setParameter('oauth2_security.token_type.bearer_token.authorization_header', $config['bearer_token']['authorization_header']); |
70
|
|
|
$container->setParameter('oauth2_security.token_type.bearer_token.request_body', $config['bearer_token']['request_body']); |
71
|
|
|
$container->setParameter('oauth2_security.token_type.bearer_token.query_string', $config['bearer_token']['query_string']); |
72
|
|
|
$loader->load('bearer_token.php'); |
73
|
|
|
} |
74
|
|
|
if (class_exists(MacToken::class) && $config['mac_token']['enabled']) { |
75
|
|
|
$container->setParameter('oauth2_security.token_type.mac_token.min_length', $config['mac_token']['min_length']); |
76
|
|
|
$container->setParameter('oauth2_security.token_type.mac_token.max_length', $config['mac_token']['max_length']); |
77
|
|
|
$container->setParameter('oauth2_security.token_type.mac_token.algorithm', $config['mac_token']['algorithm']); |
78
|
|
|
$container->setParameter('oauth2_security.token_type.mac_token.timestamp_lifetime', $config['mac_token']['timestamp_lifetime']); |
79
|
|
|
$loader->load('mac_token.php'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function getConfiguration(array $configs, ContainerBuilder $container): Configuration |
87
|
|
|
{ |
88
|
|
|
return new Configuration($this->getAlias()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|