|
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.additional_attributes', $additionalAttributes); |
|
116
|
|
|
$container->setParameter('ldap_tools.security.check_groups_recursively', $config['check_groups_recursively']); |
|
117
|
|
|
$container->setParameter('ldap_tools.security.user', $config['user']); |
|
118
|
|
|
$container->setParameter('ldap_tools.security.roles', $roles); |
|
119
|
|
|
$container->setParameter('ldap_tools.security.default_role', $config['default_role']); |
|
120
|
|
|
$container->setParameter('ldap_tools.security.guard.auth_success', [ |
|
121
|
|
|
'default_target_path' => $config['guard']['default_target_path'], |
|
122
|
|
|
'always_use_target_path' => $config['guard']['always_use_target_path'], |
|
123
|
|
|
'target_path_parameter' => $config['guard']['target_path_parameter'], |
|
124
|
|
|
'use_referrer' => $config['guard']['use_referrer'], |
|
125
|
|
|
'login_path' => $config['guard']['login_path'], |
|
126
|
|
|
]); |
|
127
|
|
|
$container->setParameter('ldap_tools.security.guard.auth_failure', [ |
|
128
|
|
|
'failure_path' => $config['guard']['failure_path'], |
|
129
|
|
|
'failure_forward' => $config['guard']['failure_forward'], |
|
130
|
|
|
'failure_path_parameter' => $config['guard']['failure_path_parameter'], |
|
131
|
|
|
'login_path' => $config['guard']['login_path'], |
|
132
|
|
|
]); |
|
133
|
|
|
$container->setParameter('ldap_tools.security.guard.options', [ |
|
134
|
|
|
'username_parameter' => $config['guard']['username_parameter'], |
|
135
|
|
|
'password_parameter' => $config['guard']['password_parameter'], |
|
136
|
|
|
'domain_parameter' => $config['guard']['domain_parameter'], |
|
137
|
|
|
]); |
|
138
|
|
|
$container->getDefinition('ldap_tools.security.authentication.form_entry_point') |
|
139
|
|
|
->addArgument(new Reference('security.http_utils')) |
|
140
|
|
|
->addArgument($config['guard']['login_path']) |
|
141
|
|
|
->addArgument($config['guard']['use_forward']); |
|
142
|
|
|
|
|
143
|
|
|
$container->getDefinition('ldap_tools.security.user.ldap_user_provider')->addMethodCall( |
|
144
|
|
|
'setLdapObjectType', |
|
145
|
|
|
[$config['ldap_object_type']] |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
$userProviderDef = $container->getDefinition('ldap_tools.security.user.ldap_user_provider'); |
|
149
|
|
|
if (isset($config['search_base'])) { |
|
150
|
|
|
$userProviderDef->addMethodCall( |
|
151
|
|
|
'setSearchBase', |
|
152
|
|
|
[$config['search_base']] |
|
153
|
|
|
); |
|
154
|
|
|
} |
|
155
|
|
|
$userProviderDef->addMethodCall( |
|
156
|
|
|
'setRoleLdapType', |
|
157
|
|
|
[$config['role_ldap_type']] |
|
158
|
|
|
); |
|
159
|
|
|
$userProviderDef->addMethodCall( |
|
160
|
|
|
'setRoleAttributeMap', |
|
161
|
|
|
[$config['role_attributes']] |
|
162
|
|
|
); |
|
163
|
|
|
$userProviderDef->addMethodCall( |
|
164
|
|
|
'setRefreshAttributes', |
|
165
|
|
|
[$config['refresh_user_attributes']] |
|
166
|
|
|
); |
|
167
|
|
|
$userProviderDef->addMethodCall( |
|
168
|
|
|
'setRefreshRoles', |
|
169
|
|
|
[$config['refresh_user_roles']] |
|
170
|
|
|
); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|