|
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\Config\Definition\Builder\ArrayNodeDefinition; |
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* LdapToolsBundle configuration options. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Chad Sikorra <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Configuration implements ConfigurationInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var bool Whether or not debug mode is in use. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $debug; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param bool $debug |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($debug) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->debug = (bool) $debug; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritDoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getConfigTreeBuilder() |
|
41
|
|
|
{ |
|
42
|
|
|
$treeBuilder = new TreeBuilder(); |
|
43
|
|
|
$rootNode = $treeBuilder->root('ldap_tools'); |
|
44
|
|
|
$this->addMainSection($rootNode); |
|
45
|
|
|
$this->addGeneralSection($rootNode); |
|
46
|
|
|
$this->addLdapDomainsSection($rootNode); |
|
47
|
|
|
$this->addSecuritySection($rootNode); |
|
48
|
|
|
|
|
49
|
|
|
return $treeBuilder; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ArrayNodeDefinition $node |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function addMainSection(ArrayNodeDefinition $node) |
|
56
|
|
|
{ |
|
57
|
|
|
$node->children() |
|
58
|
|
|
->booleanNode('logging')->defaultValue($this->debug)->end() |
|
59
|
|
|
->booleanNode('profiling')->defaultValue($this->debug)->end() |
|
60
|
|
|
->end(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param ArrayNodeDefinition $node |
|
65
|
|
|
*/ |
|
66
|
|
|
private function addGeneralSection(ArrayNodeDefinition $node) |
|
67
|
|
|
{ |
|
68
|
|
|
$node |
|
69
|
|
|
->children() |
|
70
|
|
|
->arrayNode('general') |
|
71
|
|
|
->addDefaultsIfNotSet() |
|
72
|
|
|
->children() |
|
73
|
|
|
->scalarNode('default_domain') |
|
74
|
|
|
->info('If more than one domain is defined, explicitly set which is the default context for the LdapManager (by domain_name)')->end() |
|
75
|
|
|
->scalarNode('schema_format')->end() |
|
76
|
|
|
->scalarNode('schema_folder')->end() |
|
77
|
|
|
->scalarNode('cache_type')->defaultValue('doctrine')->end() |
|
78
|
|
|
->arrayNode('cache_options') |
|
79
|
|
|
->addDefaultsIfNotSet() |
|
80
|
|
|
->children() |
|
81
|
|
|
->scalarNode('cache_folder')->defaultValue('%kernel.cache_dir%/ldaptools')->end() |
|
82
|
|
|
->booleanNode('cache_auto_refresh')->defaultFalse()->end() |
|
83
|
|
|
->end() |
|
84
|
|
|
->end() |
|
85
|
|
|
->arrayNode('attribute_converters')->end() |
|
86
|
|
|
->end() |
|
87
|
|
|
->end() |
|
88
|
|
|
->end(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param ArrayNodeDefinition $node |
|
93
|
|
|
*/ |
|
94
|
|
|
private function addLdapDomainsSection(ArrayNodeDefinition $node) |
|
95
|
|
|
{ |
|
96
|
|
|
$node |
|
97
|
|
|
->children() |
|
98
|
|
|
->arrayNode('domains') |
|
99
|
|
|
->prototype('array') |
|
100
|
|
|
->children() |
|
101
|
|
|
->scalarNode('domain_name')->isRequired() |
|
102
|
|
|
->info('The FQDN (ie. example.com)')->end() |
|
103
|
|
|
->scalarNode('username')->isRequired() |
|
104
|
|
|
->info('The username/DN/SID/GUID to used to connect to LDAP.')->end() |
|
105
|
|
|
->scalarNode('password')->isRequired() |
|
106
|
|
|
->info('The password for the username used to connect to LDAP.')->end() |
|
107
|
|
|
->scalarNode('base_dn') |
|
108
|
|
|
->info('The base DN used for searches (ie. dc=example,dc=com). This is queried from the RootDSE if not provided.')->end() |
|
109
|
|
|
->integerNode('port') |
|
110
|
|
|
->info('The default port number to connect to LDAP on.')->end() |
|
111
|
|
|
->booleanNode('use_paging') |
|
112
|
|
|
->info('Whether or not search results should be paged')->end() |
|
113
|
|
|
->integerNode('page_size') |
|
114
|
|
|
->info('The size for paged result searches.')->end() |
|
115
|
|
|
->booleanNode('use_tls') |
|
116
|
|
|
->info('Encrypt the connection with TLS. This is required when modifying LDAP passwords.')->end() |
|
117
|
|
|
->booleanNode('use_ssl') |
|
118
|
|
|
->info('Encrypt the connection with SSL. Typically you want to use "use_tls" and not this option.')->end() |
|
119
|
|
|
->scalarNode('ldap_type') |
|
120
|
|
|
->info('The LDAP type for this domain. Choices are ad or openldap.')->end() |
|
121
|
|
|
->arrayNode('servers') |
|
122
|
|
|
->info('The LDAP servers to connect to. This is queried from DNS if not provided.') |
|
123
|
|
|
->beforeNormalization() |
|
124
|
|
|
->ifTrue(function ($v) { |
|
125
|
|
|
return !is_array($v); |
|
126
|
|
|
}) |
|
127
|
|
|
->then(function ($v) { |
|
128
|
|
|
return [$v]; |
|
129
|
|
|
}) |
|
130
|
|
|
->end() |
|
131
|
|
|
->prototype('scalar')->end() |
|
132
|
|
|
->end() |
|
133
|
|
|
->booleanNode('lazy_bind') |
|
134
|
|
|
->info('If set to true, then the connection will not automatically connect and bind when first created.')->end() |
|
135
|
|
|
->integerNode('idle_reconnect') |
|
136
|
|
|
->info('The elapsed time (in seconds) when an idle connection will attempt to reconnect to LDAP.')->end() |
|
137
|
|
|
->integerNode('connect_timeout') |
|
138
|
|
|
->info('The elapsed time (in seconds) to wait while attempting the initial connection to LDAP.')->end() |
|
139
|
|
|
->scalarNode('server_selection') |
|
140
|
|
|
->info('Determines how the LDAP server is selected. Can be "order" or "random".')->end() |
|
141
|
|
|
->scalarNode('encoding')->end() |
|
142
|
|
|
->scalarNode('schema_name') |
|
143
|
|
|
->info('The schema name to use for this domain')->end() |
|
144
|
|
|
->scalarNode('bind_format') |
|
145
|
|
|
->info('Set to a string that determines where the username is placed in a bind attempt: %%username%%,ou=users,dc=foo,dc=bar')->end() |
|
146
|
|
|
->arrayNode('ldap_options') |
|
147
|
|
|
->info('Set specific LDAP_OPT_* constants to use. Specify them using their string name as keys along with their values.') |
|
148
|
|
|
->useAttributeAsKey('name') |
|
149
|
|
|
->prototype('variable') |
|
150
|
|
|
->end() |
|
151
|
|
|
->end() |
|
152
|
|
|
->end(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param ArrayNodeDefinition $node |
|
157
|
|
|
*/ |
|
158
|
|
|
protected function addSecuritySection(ArrayNodeDefinition $node) |
|
159
|
|
|
{ |
|
160
|
|
|
$node |
|
161
|
|
|
->children() |
|
162
|
|
|
->arrayNode('security') |
|
163
|
|
|
->addDefaultsIfNotSet() |
|
164
|
|
|
->children() |
|
165
|
|
|
->scalarNode('search_base') |
|
166
|
|
|
->info('The default DN to start the user search from.')->end() |
|
167
|
|
|
->scalarNode('ldap_object_type')->defaultValue('user') |
|
168
|
|
|
->info('The LdapTools object type for the user provider to search for.')->end() |
|
169
|
|
|
->scalarNode('default_role')->defaultValue('ROLE_USER') |
|
170
|
|
|
->info('Regardless of group membership this role will be assigned to the loaded user. Set it to null for no roles to be assigned by default.')->end() |
|
171
|
|
|
->booleanNode('check_groups_recursively') |
|
172
|
|
|
->info('If set to true then group membership will contain all groups, and nested groups, the user belongs to.')->defaultTrue()->end() |
|
173
|
|
|
->scalarNode('user')->defaultValue('\LdapTools\Bundle\LdapToolsBundle\Security\User\LdapUser') |
|
174
|
|
|
->info('The user class that the LDAP user provider will instantiate. If you change this the class must extend the default one.')->end() |
|
175
|
|
|
->arrayNode('default_attributes') |
|
176
|
|
|
->info('Set the default LDAP attributes mapped for the LDAP user provider class.') |
|
177
|
|
|
->addDefaultsIfNotSet() |
|
178
|
|
|
->children() |
|
179
|
|
|
->scalarNode('username')->defaultValue('username')->end() |
|
180
|
|
|
->scalarNode('accountNonLocked')->defaultValue('locked')->end() |
|
181
|
|
|
->scalarNode('accountNonExpired')->defaultValue('accountExpirationDate')->end() |
|
182
|
|
|
->scalarNode('enabled')->defaultValue('disabled')->end() |
|
183
|
|
|
->scalarNode('credentialsNonExpired')->defaultValue('passwordMustChange')->end() |
|
184
|
|
|
->scalarNode('groups')->defaultValue('groups')->end() |
|
185
|
|
|
->scalarNode('guid')->defaultValue('guid')->end() |
|
186
|
|
|
->scalarNode('stringRepresentation')->defaultValue('username')->end() |
|
187
|
|
|
->end() |
|
188
|
|
|
->end() |
|
189
|
|
|
->arrayNode('guard') |
|
190
|
|
|
->info('Guard specific configuration options.') |
|
191
|
|
|
->addDefaultsIfNotSet() |
|
192
|
|
|
->children() |
|
193
|
|
|
->scalarNode('start_path')->defaultValue('login') |
|
194
|
|
|
->info('The default entry point/starting path as a route name.')->end() |
|
195
|
|
|
->end() |
|
196
|
|
|
->end() |
|
197
|
|
|
->arrayNode('additional_attributes') |
|
198
|
|
|
->info('Any additional attribute values that should be available when the user is loaded.') |
|
199
|
|
|
->prototype('scalar')->end() |
|
200
|
|
|
->end() |
|
201
|
|
|
->arrayNode('roles') |
|
202
|
|
|
->info('Map LDAP group names to specific roles. If a user is a member of the group they will get the role mapped to it.') |
|
203
|
|
|
->useAttributeAsKey('name') |
|
204
|
|
|
->prototype('array') |
|
205
|
|
|
->beforeNormalization() |
|
206
|
|
|
->ifTrue(function ($v) { |
|
207
|
|
|
return !is_array($v); |
|
208
|
|
|
}) |
|
209
|
|
|
->then(function ($v) { |
|
210
|
|
|
return [$v]; |
|
211
|
|
|
}) |
|
212
|
|
|
->end() |
|
213
|
|
|
->prototype('scalar')->end() |
|
214
|
|
|
->end() |
|
215
|
|
|
->end() |
|
216
|
|
|
->scalarNode('role_ldap_type')->defaultValue('group') |
|
217
|
|
|
->info('The LdapTools object type for the groups used to check for roles.')->end() |
|
218
|
|
|
->arrayNode('role_attributes') |
|
219
|
|
|
->info('When searching for groups/roles for a user, map to these attributes for GUID, SID, members, or name.') |
|
220
|
|
|
->addDefaultsIfNotSet() |
|
221
|
|
|
->children() |
|
222
|
|
|
->scalarNode('name')->defaultValue('name')->end() |
|
223
|
|
|
->scalarNode('sid')->defaultValue('sid')->end() |
|
224
|
|
|
->scalarNode('guid')->defaultValue('guid')->end() |
|
225
|
|
|
->scalarNode('members')->defaultValue('members')->end() |
|
226
|
|
|
->end() |
|
227
|
|
|
->end() |
|
228
|
|
|
->booleanNode('refresh_user_attributes') |
|
229
|
|
|
->info('Set this to true if you want user attributes re-queried on a user refresh.')->defaultFalse()->end() |
|
230
|
|
|
->booleanNode('refresh_user_roles') |
|
231
|
|
|
->info('Set this to true if you want user roles re-queried on a user refresh.')->defaultFalse()->end() |
|
232
|
|
|
->end() |
|
233
|
|
|
->end() |
|
234
|
|
|
->end(); |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|