1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the LdapToolsBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Chad Sikorra <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace LdapTools\Bundle\LdapToolsBundle\DependencyInjection; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
16
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Load and configure the needed services/parameters for the bundle. |
21
|
|
|
* |
22
|
|
|
* @author Chad Sikorra <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class LdapToolsExtension extends Extension |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function load(array $configs, ContainerBuilder $container) |
30
|
|
|
{ |
31
|
|
|
$configuration = new Configuration($container->getParameter('kernel.debug')); |
32
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
33
|
|
|
|
34
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
35
|
|
|
$loader->load('services.xml'); |
36
|
|
|
|
37
|
|
|
$this->setLdapConfigDefinition($container, $config); |
38
|
|
|
$this->setDoctrineConfiguration($container, $config); |
39
|
|
|
$this->setSecurityConfiguration($container, $config['security']); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param ContainerBuilder $container |
44
|
|
|
* @param array $config |
45
|
|
|
*/ |
46
|
|
|
protected function setDoctrineConfiguration(ContainerBuilder $container, array $config) |
47
|
|
|
{ |
48
|
|
|
// If they explicitly disabled doctrine integration, do nothing... |
49
|
|
|
if (!$config['doctrine']['integration_enabled']) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
// We only tag the doctrine event subscriber if there are domains listed in the config... |
53
|
|
|
if (!(isset($config['domains']) && !empty($config['domains']))) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$connections = array_filter($config['doctrine']['connections']); |
58
|
|
|
if (empty($connections)) { |
59
|
|
|
$container->getDefinition('ldap_tools.doctrine.event_listener.ldap_object')->addTag( |
60
|
|
|
'doctrine.event_subscriber' |
61
|
|
|
); |
62
|
|
|
} else { |
63
|
|
|
foreach ($connections as $connection) { |
64
|
|
|
$container->getDefinition('ldap_tools.doctrine.event_listener.ldap_object')->addTag( |
65
|
|
|
'doctrine.event_subscriber', |
66
|
|
|
['connection' => $connection] |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Pass the configuration to be loaded for the LdapTools Configuration class. |
74
|
|
|
* |
75
|
|
|
* @param ContainerBuilder $container |
76
|
|
|
* @param array $config |
77
|
|
|
*/ |
78
|
|
|
protected function setLdapConfigDefinition(ContainerBuilder $container, array $config) |
79
|
|
|
{ |
80
|
|
|
$ldapCfg = ['general' => $config['general']]; |
81
|
|
|
|
82
|
|
|
// Only tag the cache warmer if there are domains listed in the config... |
83
|
|
|
if (isset($config['domains']) && !empty($config['domains'])) { |
84
|
|
|
$ldapCfg['domains'] = $config['domains']; |
85
|
|
|
$container->getDefinition('ldap_tools.cache_warmer.ldap_tools_cache_warmer')->addTag('kernel.cache_warmer'); |
86
|
|
|
} else { |
87
|
|
|
$container->getDefinition('data_collector.ldap_tools')->replaceArgument(0, null); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$definition = $container->getDefinition('ldap_tools.configuration'); |
91
|
|
|
$definition->addMethodCall('loadFromArray', [$ldapCfg]); |
92
|
|
|
$definition->addMethodCall('setEventDispatcher', [new Reference('ldap_tools.event_dispatcher')]); |
93
|
|
|
|
94
|
|
|
$loggerChain = $container->getDefinition('ldap_tools.log.logger_chain'); |
95
|
|
|
if ($config['logging']) { |
96
|
|
|
$loggerChain->addMethodCall('addLogger', [new Reference('ldap_tools.log.logger')]); |
97
|
|
|
} |
98
|
|
|
if ($config['profiling']) { |
99
|
|
|
$loggerChain->addMethodCall('addLogger', [new Reference('ldap_tools.log.profiler')]); |
100
|
|
|
} |
101
|
|
|
if ($config['logging'] || $config['profiling']) { |
102
|
|
|
$definition->addMethodCall('setLogger', [new Reference('ldap_tools.log.logger_chain')]); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param ContainerBuilder $container |
108
|
|
|
* @param array $config |
109
|
|
|
*/ |
110
|
|
|
protected function setSecurityConfiguration(ContainerBuilder $container, array $config) |
111
|
|
|
{ |
112
|
|
|
$roles = isset($config['roles']) ? $config['roles'] : []; |
113
|
|
|
$additionalAttributes = isset($config['additional_attributes']) ? $config['additional_attributes'] : []; |
114
|
|
|
|
115
|
|
|
$container->setParameter('ldap_tools.security.default_attributes', $config['default_attributes']); |
116
|
|
|
$container->setParameter('ldap_tools.security.additional_attributes', $additionalAttributes); |
117
|
|
|
$container->setParameter('ldap_tools.security.check_groups_recursively', $config['check_groups_recursively']); |
118
|
|
|
$container->setParameter('ldap_tools.security.user', $config['user']); |
119
|
|
|
$container->setParameter('ldap_tools.security.roles', $roles); |
120
|
|
|
$container->setParameter('ldap_tools.security.default_role', $config['default_role']); |
121
|
|
|
|
122
|
|
|
$container->getDefinition('ldap_tools.security.user.ldap_user_provider')->addMethodCall( |
123
|
|
|
'setLdapObjectType', |
124
|
|
|
[$config['ldap_object_type']] |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$container->getDefinition('ldap_tools.security.ldap_guard_authenticator')->addMethodCall( |
128
|
|
|
'setStartPath', |
129
|
|
|
[$config['guard']['start_path']] |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$userProviderDef = $container->getDefinition('ldap_tools.security.user.ldap_user_provider'); |
133
|
|
|
if (isset($config['search_base'])) { |
134
|
|
|
$userProviderDef->addMethodCall( |
135
|
|
|
'setSearchBase', |
136
|
|
|
[$config['search_base']] |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
$userProviderDef->addMethodCall( |
140
|
|
|
'setRoleLdapType', |
141
|
|
|
[$config['role_ldap_type']] |
142
|
|
|
); |
143
|
|
|
$userProviderDef->addMethodCall( |
144
|
|
|
'setRoleAttributeMap', |
145
|
|
|
[$config['role_attributes']] |
146
|
|
|
); |
147
|
|
|
$userProviderDef->addMethodCall( |
148
|
|
|
'setRefreshAttributes', |
149
|
|
|
[$config['refresh_user_attributes']] |
150
|
|
|
); |
151
|
|
|
$userProviderDef->addMethodCall( |
152
|
|
|
'setRefreshRoles', |
153
|
|
|
[$config['refresh_user_roles']] |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|