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
|
|
|
$this->setGuardConfiguration($container, $config['security']['guard'], $config['security']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ContainerBuilder $container |
45
|
|
|
* @param array $config |
46
|
|
|
*/ |
47
|
|
|
protected function setDoctrineConfiguration(ContainerBuilder $container, array $config) |
48
|
|
|
{ |
49
|
|
|
// If they explicitly disabled doctrine integration, do nothing... |
50
|
|
|
if (!$config['doctrine']['integration_enabled']) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
// We only tag the doctrine event subscriber if there are domains listed in the config... |
54
|
|
|
if (!(isset($config['domains']) && !empty($config['domains']))) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$connections = array_filter($config['doctrine']['connections']); |
59
|
|
|
if (empty($connections)) { |
60
|
|
|
$container->getDefinition('ldap_tools.doctrine.event_listener.ldap_object')->addTag( |
61
|
|
|
'doctrine.event_subscriber' |
62
|
|
|
); |
63
|
|
|
} else { |
64
|
|
|
foreach ($connections as $connection) { |
65
|
|
|
$container->getDefinition('ldap_tools.doctrine.event_listener.ldap_object')->addTag( |
66
|
|
|
'doctrine.event_subscriber', |
67
|
|
|
['connection' => $connection] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Pass the configuration to be loaded for the LdapTools Configuration class. |
75
|
|
|
* |
76
|
|
|
* @param ContainerBuilder $container |
77
|
|
|
* @param array $config |
78
|
|
|
*/ |
79
|
|
|
protected function setLdapConfigDefinition(ContainerBuilder $container, array $config) |
80
|
|
|
{ |
81
|
|
|
$ldapCfg = ['general' => $config['general']]; |
82
|
|
|
|
83
|
|
|
// Only tag the cache warmer if there are domains listed in the config... |
84
|
|
|
if (isset($config['domains']) && !empty($config['domains'])) { |
85
|
|
|
$ldapCfg['domains'] = $config['domains']; |
86
|
|
|
$container->getDefinition('ldap_tools.cache_warmer.ldap_tools_cache_warmer')->addTag('kernel.cache_warmer'); |
87
|
|
|
} else { |
88
|
|
|
$container->getDefinition('data_collector.ldap_tools')->replaceArgument(0, null); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$definition = $container->getDefinition('LdapTools\Configuration'); |
92
|
|
|
$definition->addMethodCall('loadFromArray', [$ldapCfg]); |
93
|
|
|
$definition->addMethodCall('setEventDispatcher', [new Reference('ldap_tools.event_dispatcher')]); |
94
|
|
|
|
95
|
|
|
$loggerChain = $container->getDefinition('ldap_tools.log.logger_chain'); |
96
|
|
|
if ($config['logging']) { |
97
|
|
|
$loggerChain->addMethodCall('addLogger', [new Reference('ldap_tools.log.logger')]); |
98
|
|
|
} |
99
|
|
|
if ($config['profiling']) { |
100
|
|
|
$loggerChain->addMethodCall('addLogger', [new Reference('ldap_tools.log.profiler')]); |
101
|
|
|
} |
102
|
|
|
if ($config['logging'] || $config['profiling']) { |
103
|
|
|
$definition->addMethodCall('setLogger', [new Reference('ldap_tools.log.logger_chain')]); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param ContainerBuilder $container |
109
|
|
|
* @param array $config |
110
|
|
|
*/ |
111
|
|
|
protected function setSecurityConfiguration(ContainerBuilder $container, array $config) |
112
|
|
|
{ |
113
|
|
|
$container->setParameter('ldap_tools.security.role_mapper.options', [ |
114
|
|
|
'check_groups_recursively' => $config['check_groups_recursively'], |
115
|
|
|
'roles' => isset($config['roles']) ? $config['roles'] : [], |
116
|
|
|
'role_attributes' => $config['role_attributes'], |
117
|
|
|
'role_ldap_type' => $config['role_ldap_type'], |
118
|
|
|
'default_role' => $config['default_role'], |
119
|
|
|
]); |
120
|
|
|
$container->setParameter('ldap_tools.security.user.ldap_user_provider.options', [ |
121
|
|
|
'additional_attributes' => isset($config['additional_attributes']) ? $config['additional_attributes'] : [], |
122
|
|
|
'user' => $config['user'], |
123
|
|
|
'ldap_object_type' => $config['ldap_object_type'], |
124
|
|
|
'search_base' => $config['search_base'], |
125
|
|
|
'refresh_user_attributes' => $config['refresh_user_attributes'], |
126
|
|
|
'refresh_user_roles' => $config['refresh_user_roles'] |
127
|
|
|
]); |
128
|
|
|
$container->setParameter('ldap_tools.security.authentication.ldap_authentication_provider.options', [ |
129
|
|
|
'login_query_attribute' => $config['login_query_attribute'], |
130
|
|
|
]); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
protected function setGuardConfiguration(ContainerBuilder $container, array $config, array $security) |
134
|
|
|
{ |
135
|
|
|
$container->setParameter('ldap_tools.security.guard.auth_success', [ |
136
|
|
|
'default_target_path' => $config['default_target_path'], |
137
|
|
|
'always_use_target_path' => $config['always_use_target_path'], |
138
|
|
|
'target_path_parameter' => $config['target_path_parameter'], |
139
|
|
|
'use_referer' => $config['use_referer'], |
140
|
|
|
'login_path' => $config['login_path'], |
141
|
|
|
]); |
142
|
|
|
$container->setParameter('ldap_tools.security.guard.auth_failure', [ |
143
|
|
|
'failure_path' => $config['failure_path'], |
144
|
|
|
'failure_forward' => $config['failure_forward'], |
145
|
|
|
'failure_path_parameter' => $config['failure_path_parameter'], |
146
|
|
|
'login_path' => $config['login_path'], |
147
|
|
|
]); |
148
|
|
|
$container->setParameter('ldap_tools.security.guard.options', [ |
149
|
|
|
'username_parameter' => $config['username_parameter'], |
150
|
|
|
'password_parameter' => $config['password_parameter'], |
151
|
|
|
'domain_parameter' => $config['domain_parameter'], |
152
|
|
|
'post_only' => $config['post_only'], |
153
|
|
|
'remember_me' => $config['remember_me'], |
154
|
|
|
'login_query_attribute' => $security['login_query_attribute'], |
155
|
|
|
'http_basic' => $config['http_basic'], |
156
|
|
|
'http_basic_domain' => $config['http_basic_domain'], |
157
|
|
|
'http_basic_realm' => $config['http_basic_realm'], |
158
|
|
|
]); |
159
|
|
|
$container->getDefinition('ldap_tools.security.authentication.form_entry_point') |
160
|
|
|
->addArgument(new Reference('security.http_utils')) |
161
|
|
|
->addArgument($config['login_path']) |
162
|
|
|
->addArgument($config['use_forward']); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|