1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 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\Bundle\Server\Security\Factory; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\Server\Security\Authentication\Provider\OAuth2Provider; |
17
|
|
|
use OAuth2Framework\Bundle\Server\Security\EntryPoint\OAuth2EntryPoint; |
18
|
|
|
use OAuth2Framework\Bundle\Server\Security\Firewall\OAuth2Listener; |
19
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
22
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
23
|
|
|
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; |
24
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
25
|
|
|
|
26
|
|
|
final class OAuth2SecurityFactory implements SecurityFactoryInterface |
27
|
|
|
{ |
28
|
|
|
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) |
29
|
|
|
{ |
30
|
|
|
$providerId = 'security.authentication.provider.oauth2.'.$id; |
31
|
|
|
$container |
32
|
|
|
->setDefinition($providerId, new ChildDefinition(OAuth2Provider::class)) |
33
|
|
|
->setAutowired(true) |
34
|
|
|
; |
35
|
|
|
|
36
|
|
|
$listenerId = 'security.authentication.listener.oauth2.'.$id; |
37
|
|
|
$listener = $container |
|
|
|
|
38
|
|
|
->setDefinition($listenerId, new ChildDefinition(OAuth2Listener::class)) |
39
|
|
|
->setArguments([ |
40
|
|
|
new Reference(TokenStorageInterface::class), |
41
|
|
|
new Reference('security.authentication.manager') |
42
|
|
|
]) |
43
|
|
|
; |
44
|
|
|
|
45
|
|
|
return array($providerId, $listenerId, OAuth2EntryPoint::class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getPosition() |
52
|
|
|
{ |
53
|
|
|
return 'pre_auth'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getKey() |
60
|
|
|
{ |
61
|
|
|
return 'oauth2'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function addConfiguration(NodeDefinition $node) |
68
|
|
|
{ |
69
|
|
|
$node |
|
|
|
|
70
|
|
|
->children() |
71
|
|
|
->scalarNode('access_token_handler_manager') |
72
|
|
|
->info('The access token handler manager has to retrieve access tokens on demand. Access token can be find from a database, the introspection or any other method.') |
73
|
|
|
->isRequired() |
74
|
|
|
->end() |
75
|
|
|
->end(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.