Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e6962e

Browse files
committed
feature #7420 Added query_string LDAP config option (nietonfir, javiereguiluz, lsmith77)
This PR was merged into the master branch. Discussion ---------- Added query_string LDAP config option docs for symfony/symfony#21402 Commits ------- b82cafd clean up 446ba38 added query_string LDAP config option ed58da8 Minor reword f133269 Explain the query_string ldap authentication provider configuration key
2 parents 1b4eab4 + b82cafd commit 6e6962e

File tree

2 files changed

+97
-12
lines changed

2 files changed

+97
-12
lines changed

reference/configuration/security.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ Each part will be explained in the next section.
142142
http_basic:
143143
provider: some_key_from_above
144144
http_basic_ldap:
145-
provider: some_key_from_above
146-
service: ldap
147-
dn_string: '{username}'
145+
provider: some_key_from_above
146+
service: ldap
147+
dn_string: '{username}'
148+
query_string: ~
148149
http_digest:
149150
provider: some_key_from_above
150151
guard:
@@ -237,8 +238,9 @@ Each part will be explained in the next section.
237238
# new in Symfony 2.3
238239
require_previous_session: true
239240
240-
service: ~
241-
dn_string: '{username}'
241+
service: ~
242+
dn_string: '{username}'
243+
query_string: ~
242244
243245
remember_me:
244246
token_provider: name
@@ -446,6 +448,17 @@ placeholder will be replaced with the user-provided value (his login).
446448
Depending on your LDAP server's configuration, you may need to override
447449
this value.
448450

451+
query_string
452+
............
453+
454+
**type**: ``string`` **default**: ``null``
455+
456+
This is the string which will be used to query for the DN. The ``{username}``
457+
placeholder will be replaced with the user-provided value (their login).
458+
Depending on your LDAP server's configuration, you will need to override
459+
this value. This setting is only necessary if the user's DN cannot be derived
460+
statically using the ``dn_string`` config option.
461+
449462
User provider
450463
~~~~~~~~~~~~~
451464

security/ldap.rst

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Authenticating against an LDAP server can be done using either the form
246246
login or the HTTP Basic authentication providers.
247247

248248
They are configured exactly as their non-LDAP counterparts, with the
249-
addition of two configuration keys:
249+
addition of two configuration keys and one optional key:
250250

251251
service
252252
.......
@@ -270,6 +270,28 @@ For example, if your users have DN strings in the form
270270
``uid=einstein,dc=example,dc=com``, then the ``dn_string`` will be
271271
``uid={username},dc=example,dc=com``.
272272

273+
query_string
274+
............
275+
276+
**type**: ``string`` **default**: ``null``
277+
278+
This (optional) key makes the user provider search for a user and then use the
279+
found DN for the bind process. This is useful when using multiple LDAP user
280+
providers with different ``base_dn``. The value of this option must be a valid
281+
search string (e.g. ``uid="{username}"``). The placeholder value will be
282+
replaced by the actual username.
283+
284+
When this option is used, ``dn_string`` has to be updated accordingly. Following
285+
the previous example, if your users have the following two DN:
286+
``dc=companyA,dc=example,dc=com`` and ``dc=companyB,dc=example,dc=com``, then
287+
``dn_string`` should be ``dc=example,dc=com``. If the ``query_string`` option is
288+
``uid="{username}"``, then the authentication provider can authenticate users
289+
from both DN.
290+
291+
Bear in mind that usernames must be unique across both DN, as the authentication
292+
provider won't be able to select the correct user for the bind process if more
293+
than one is found.
294+
273295
Examples are provided below, for both ``form_login_ldap`` and
274296
``http_basic_ldap``.
275297

@@ -288,8 +310,6 @@ Configuration example for form login
288310
main:
289311
# ...
290312
form_login_ldap:
291-
login_path: login
292-
check_path: login_check
293313
# ...
294314
service: ldap
295315
dn_string: 'uid={username},dc=example,dc=com'
@@ -307,8 +327,6 @@ Configuration example for form login
307327
<config>
308328
<firewall name="main">
309329
<form-login-ldap
310-
login-path="login"
311-
check-path="login_check"
312330
service="ldap"
313331
dn-string="uid={username},dc=example,dc=com" />
314332
</firewall>
@@ -321,8 +339,6 @@ Configuration example for form login
321339
'firewalls' => array(
322340
'main' => array(
323341
'form_login_ldap' => array(
324-
'login_path' => 'login',
325-
'check_path' => 'login_check',
326342
'service' => 'ldap',
327343
'dn_string' => 'uid={username},dc=example,dc=com',
328344
// ...
@@ -382,5 +398,61 @@ Configuration example for HTTP Basic
382398
),
383399
);
384400
401+
Configuration example for form login and query_string
402+
.....................................................
403+
404+
.. configuration-block::
405+
406+
.. code-block:: yaml
407+
408+
# app/config/security.yml
409+
security:
410+
# ...
411+
412+
firewalls:
413+
main:
414+
# ...
415+
form_login_ldap:
416+
# ...
417+
service: ldap
418+
dn_string: 'dc=example,dc=com'
419+
query_string: '(&(uid={username})(memberOf=cn=users,ou=Services,dc=example,dc=com))'
420+
421+
.. code-block:: xml
422+
423+
<!-- app/config/security.xml -->
424+
<?xml version="1.0" encoding="UTF-8"?>
425+
<srv:container xmlns="http://symfony.com/schema/dic/security"
426+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
427+
xmlns:srv="http://symfony.com/schema/dic/services"
428+
xsi:schemaLocation="http://symfony.com/schema/dic/services
429+
http://symfony.com/schema/dic/services/services-1.0.xsd">
430+
431+
<config>
432+
<firewall name="main">
433+
<form-login-ldap
434+
service="ldap"
435+
dn-string="dc=example,dc=com"
436+
query-string="(&amp;(uid={username})(memberOf=cn=users,ou=Services,dc=example,dc=com))" />
437+
</firewall>
438+
</config>
439+
</srv:container>
440+
441+
.. code-block:: php
442+
443+
// app/config/security.php
444+
$container->loadFromExtension('security', array(
445+
'firewalls' => array(
446+
'main' => array(
447+
'form_login_ldap' => array(
448+
'service' => 'ldap',
449+
'dn_string' => 'dc=example,dc=com',
450+
'query_string' => '(&(uid={username})(memberOf=cn=users,ou=Services,dc=example,dc=com))',
451+
// ...
452+
),
453+
),
454+
)
455+
);
456+
385457
.. _`RFC4515`: http://www.faqs.org/rfcs/rfc4515.html
386458
.. _`LDAP injection`: http://projects.webappsec.org/w/page/13246947/LDAP%20Injection

0 commit comments

Comments
 (0)