|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class AuthenticationKeyFinderPass |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\SecurityBundle\DependencyInjection\Compiler; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\SecurityBundle\Authentication\Strategies\MultiStrategy; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
16
|
|
|
* @link http://swisscom.ch |
|
17
|
|
|
*/ |
|
18
|
|
|
class AuthenticationKeyFinderPass implements CompilerPassInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* You can modify the container here before it is dumped to PHP code. |
|
22
|
|
|
* |
|
23
|
|
|
* @api |
|
24
|
|
|
* |
|
25
|
|
|
* @param ContainerBuilder $container container to look for tags in |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
4 |
|
public function process(ContainerBuilder $container) |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
// Check which Strategy is loaded. |
|
33
|
4 |
|
if (!$container->hasParameter('graviton.security.authentication.strategy')) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Check which Strategy is used. |
|
38
|
|
|
$authService |
|
39
|
4 |
|
= $container->getParameter('graviton.security.authentication.strategy'); |
|
40
|
|
|
|
|
41
|
|
|
// Only load multi services if configured. |
|
42
|
4 |
|
if (strpos($authService, '.multi') === false) { |
|
43
|
2 |
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Multi Strategy Authentication injection |
|
47
|
|
|
$serviceIds |
|
48
|
2 |
|
= $container->getParameter('graviton.security.authentication.strategy.multi.services'); |
|
49
|
|
|
|
|
50
|
|
|
// Multi service class |
|
51
|
2 |
|
$multiAuth = $container->findDefinition('graviton.security.authentication.strategy.multi'); |
|
52
|
|
|
|
|
53
|
|
|
// If no service defined we use them all |
|
54
|
2 |
|
if (empty($serviceIds)) { |
|
55
|
|
|
$services = $container->findTaggedServiceIds('graviton.security.authenticationkey.finder'); |
|
56
|
|
|
$serviceIds = array_keys($services); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// Fetch service and add them to Multi |
|
60
|
2 |
|
foreach ($serviceIds as $id) { |
|
61
|
2 |
|
if ($container->hasDefinition($id)) { |
|
62
|
2 |
|
$multiAuth->addMethodCall( |
|
63
|
2 |
|
'addStrategy', |
|
64
|
|
|
array( |
|
65
|
2 |
|
new Reference($id) |
|
66
|
1 |
|
) |
|
67
|
1 |
|
); |
|
68
|
1 |
|
} else { |
|
69
|
|
|
/** @var \Psr\Log\LoggerInterface $logger*/ |
|
70
|
2 |
|
if ($container->hasDefinition('logger')) { |
|
71
|
|
|
/** @var \Psr\Log\LoggerInterface $logger */ |
|
72
|
2 |
|
$logger = $container->getDefinition('logger'); |
|
73
|
2 |
|
$logger->warning( |
|
74
|
2 |
|
sprintf( |
|
75
|
2 |
|
'The service (%s) is not registered in the application kernel.', |
|
76
|
1 |
|
$id |
|
77
|
1 |
|
) |
|
78
|
1 |
|
); |
|
79
|
1 |
|
} |
|
80
|
|
|
} |
|
81
|
1 |
|
} |
|
82
|
2 |
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|