1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Krtv\Bundle\SingleSignOnServiceProviderBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Processor; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
10
|
|
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
11
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
13
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class KrtvSingleSignOnServiceProviderExtension |
17
|
|
|
* @package Krtv\Bundle\SingleSignOnServiceProviderBundle\DependencyInjection |
18
|
|
|
*/ |
19
|
|
|
class KrtvSingleSignOnServiceProviderExtension extends Extension |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @param array $configs |
23
|
|
|
* @param ContainerBuilder $container |
24
|
|
|
*/ |
25
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
26
|
|
|
{ |
27
|
1 |
|
$processor = new Processor(); |
28
|
1 |
|
$configuration = new Configuration(); |
29
|
1 |
|
$config = $processor->processConfiguration($configuration, $configs); |
30
|
|
|
|
31
|
|
|
// add config parameters to container |
32
|
1 |
|
$prefix = $this->getAlias() . '.'; |
33
|
1 |
|
foreach ($config as $name => $value) { |
34
|
1 |
|
$container->setParameter($prefix . $name, $value); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// load services |
38
|
1 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
39
|
|
|
|
40
|
1 |
|
$otpManagerConfig = $config['otp_manager']; |
41
|
1 |
|
$otpManagerName = $otpManagerConfig['name']; |
42
|
|
|
|
43
|
1 |
|
$loader->load('managers/' . $otpManagerName . '.xml'); |
44
|
1 |
|
if ($otpManagerName === 'http') { |
45
|
1 |
|
$providerName = $otpManagerConfig['managers'][$otpManagerName]['provider']; |
46
|
1 |
|
$providerConfig = $otpManagerConfig['managers'][$otpManagerName]['providers'][$providerName]; |
47
|
|
|
|
48
|
1 |
|
$otpManagerId = sprintf('krtv_single_sign_on_service_provider.security.authentication.otp_manager.%s', $otpManagerName); |
49
|
1 |
|
$providerId = sprintf('krtv_single_sign_on_service_provider.security.authentication.otp_manager.%s.provider.%s', $otpManagerName, $providerName); |
50
|
|
|
|
51
|
1 |
|
$otpManagerDefinition = $container->getDefinition($otpManagerId); |
52
|
1 |
|
$otpManagerDefinition->replaceArgument(0, new Reference($providerId)); |
53
|
|
|
|
54
|
|
|
switch ($providerName) { |
55
|
1 |
|
case 'guzzle': |
56
|
|
|
$providerDefinition = $container->getDefinition($providerId); |
57
|
|
|
$providerDefinition->replaceArgument(0, new Reference($providerConfig['client'])); |
58
|
|
|
$providerDefinition->replaceArgument(1, $providerConfig['resource']); |
59
|
|
|
|
60
|
|
|
break; |
61
|
1 |
|
case 'service': |
62
|
1 |
|
$container->setAlias($providerId, new Alias($providerConfig['id'])); |
63
|
|
|
|
64
|
1 |
|
break; |
65
|
|
|
default: |
66
|
|
|
throw new RuntimeException(sprintf('Unsupported HTTP provider %s', $providerName)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
$loader->load('services.xml'); |
72
|
|
|
|
73
|
|
|
// Set alias for OTP |
74
|
1 |
|
$container->setAlias('krtv_single_sign_on_service_provider.security.authentication.manager.otp', new Alias('krtv_single_sign_on_service_provider.security.authentication.otp_manager.' . $otpManagerName)); |
75
|
1 |
|
$container->setAlias('sso_service_provider.otp_manager', new Alias('krtv_single_sign_on_service_provider.security.authentication.manager.otp')); |
76
|
|
|
|
77
|
|
|
// Set alias for encoder |
78
|
1 |
|
$container->setAlias('sso_service_provider.encoder', new Alias('krtv_single_sign_on_service_provider.security.authentication.encoder')); |
79
|
|
|
|
80
|
|
|
// Set alias for uri_signer |
81
|
1 |
|
$container->setAlias('sso_service_provider.uri_signer', new Alias('krtv_single_sign_on_service_provider.uri_signer')); |
82
|
|
|
|
83
|
1 |
|
$authenticationProviderDefinition = $container->getDefinition('krtv_single_sign_on_service_provider.security.authentication.provider'); |
84
|
1 |
|
$authenticationProviderDefinition->replaceArgument(2, new Reference('krtv_single_sign_on_service_provider.security.authentication.manager.otp')); |
85
|
1 |
|
} |
86
|
|
|
|
87
|
2 |
|
public function getAlias() |
88
|
|
|
{ |
89
|
2 |
|
return 'krtv_single_sign_on_service_provider'; |
90
|
|
|
} |
91
|
|
|
} |