Skip to content

Commit 582ec54

Browse files
author
epriestley
committed
Add a checkbox to the LDAP auth configuration UI to "Always Search"
Summary: Fixes T3208. This forces us to bind+search even if there are no anonymous credentials. Test Plan: Checked the box, saved the form. Unchecked the box, saved the form. LDAP?? Reviewers: Firehed Reviewed By: Firehed Subscribers: epriestley Maniphest Tasks: T3208 Differential Revision: https://secure.phabricator.com/D8723
1 parent 58ba8e7 commit 582ec54

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

resources/sql/patches/20130619.authconf.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
=> 'ldap.port',
121121
PhabricatorAuthProviderLDAP::KEY_DISTINGUISHED_NAME
122122
=> 'ldap.base_dn',
123-
PhabricatorAuthProviderLDAP::KEY_SEARCH_ATTRIBUTE
123+
PhabricatorAuthProviderLDAP::KEY_SEARCH_ATTRIBUTES
124124
=> 'ldap.search_attribute',
125125
PhabricatorAuthProviderLDAP::KEY_USERNAME_ATTRIBUTE
126126
=> 'ldap.username-attribute',
@@ -136,7 +136,9 @@
136136
=> 'ldap.anonymous-user-name',
137137
PhabricatorAuthProviderLDAP::KEY_ANONYMOUS_PASSWORD
138138
=> 'ldap.anonymous-user-password',
139-
PhabricatorAuthProviderLDAP::KEY_SEARCH_FIRST
139+
// Update the old "search first" setting to the newer but similar
140+
// "always search" setting.
141+
PhabricatorAuthProviderLDAP::KEY_ALWAYS_SEARCH
140142
=> 'ldap.search-first',
141143
PhabricatorAuthProviderLDAP::KEY_ACTIVEDIRECTORY_DOMAIN
142144
=> 'ldap.activedirectory_domain',

src/applications/auth/provider/PhabricatorAuthProviderLDAP.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getAdapter() {
5151
$conf->getProperty(self::KEY_REFERRALS))
5252
->setLDAPStartTLS(
5353
$conf->getProperty(self::KEY_START_TLS))
54+
->setAlwaysSearch($conf->getProperty(self::KEY_ALWAYS_SEARCH))
5455
->setAnonymousUsername(
5556
$conf->getProperty(self::KEY_ANONYMOUS_USERNAME))
5657
->setAnonymousPassword(
@@ -194,6 +195,7 @@ public function processLoginRequest(
194195
const KEY_START_TLS = 'ldap:start-tls';
195196
const KEY_ANONYMOUS_USERNAME = 'ldap:anoynmous-username';
196197
const KEY_ANONYMOUS_PASSWORD = 'ldap:anonymous-password';
198+
const KEY_ALWAYS_SEARCH = 'ldap:always-search';
197199
const KEY_ACTIVEDIRECTORY_DOMAIN = 'ldap:activedirectory-domain';
198200

199201
private function getPropertyKeys() {
@@ -206,6 +208,7 @@ private function getPropertyLabels() {
206208
self::KEY_PORT => pht('LDAP Port'),
207209
self::KEY_DISTINGUISHED_NAME => pht('Base Distinguished Name'),
208210
self::KEY_SEARCH_ATTRIBUTES => pht('Search Attributes'),
211+
self::KEY_ALWAYS_SEARCH => pht('Always Search'),
209212
self::KEY_ANONYMOUS_USERNAME => pht('Anonymous Username'),
210213
self::KEY_ANONYMOUS_PASSWORD => pht('Anonymous Password'),
211214
self::KEY_USERNAME_ATTRIBUTE => pht('Username Attribute'),
@@ -276,10 +279,8 @@ public function extendEditForm(
276279
pht('Follow referrals. Disable this for Windows AD 2003.'),
277280
self::KEY_START_TLS =>
278281
pht('Start TLS after binding to the LDAP server.'),
279-
self::KEY_ANONYMOUS_USERNAME =>
280-
pht('Username to bind with before searching.'),
281-
self::KEY_ANONYMOUS_PASSWORD =>
282-
pht('Password to bind with before searching.'),
282+
self::KEY_ALWAYS_SEARCH =>
283+
pht('Always bind and search, even without a username and password.'),
283284
);
284285

285286
$types = array(
@@ -288,6 +289,7 @@ public function extendEditForm(
288289
self::KEY_SEARCH_ATTRIBUTES => 'textarea',
289290
self::KEY_REALNAME_ATTRIBUTES => 'list',
290291
self::KEY_ANONYMOUS_PASSWORD => 'password',
292+
self::KEY_ALWAYS_SEARCH => 'checkbox',
291293
);
292294

293295
$instructions = array(
@@ -308,15 +310,16 @@ public function extendEditForm(
308310
" - Your LDAP server is configured in some other way that prevents ".
309311
" direct binding from working correctly.\n\n".
310312
"**To bind directly**, enter the LDAP attribute corresponding to the ".
311-
"login name into this box. Often, this is something like `sn` or ".
312-
"`uid`. This is the simplest configuration, but will only work if the ".
313-
"username is part of the distinguished name, and won't let you apply ".
314-
"complex restrictions to logins.\n\n".
313+
"login name into the **Search Attributes** box below. Often, this is ".
314+
"something like `sn` or `uid`. This is the simplest configuration, ".
315+
"but will only work if the username is part of the distinguished ".
316+
"name, and won't let you apply complex restrictions to logins.\n\n".
315317
" lang=text,name=Simple Direct Binding\n".
316318
" sn\n\n".
317319
"**To search first**, provide an anonymous username and password ".
318-
"below, then enter one or more search queries into this field, one ".
319-
"per line. After binding, these queries will be used to identify the ".
320+
"below (or check the **Always Search** checkbox), then enter one ".
321+
"or more search queries into this field, one per line. ".
322+
"After binding, these queries will be used to identify the ".
320323
"record associated with the login name the user typed.\n\n".
321324
"Searches will be tried in order until a matching record is found. ".
322325
"Each query can be a simple attribute name (like `sn` or `mail`), ".
@@ -333,7 +336,7 @@ public function extendEditForm(
333336
" mail\n".
334337
" sn\n\n".
335338
"If your LDAP directory is more complex, or you want to perform ".
336-
"sophisticated filtering, you can use one or more queries. Depending ".
339+
"sophisticated filtering, you can use more complex queries. Depending ".
337340
"on your directory structure, this example might allow users to login ".
338341
"with either their email address or username, but only if they're in ".
339342
"specific departments:\n\n".
@@ -342,6 +345,10 @@ public function extendEditForm(
342345
" (&(sn=\${login})(|(departmentNumber=1)(departmentNumber=2)))\n\n".
343346
"All of the attribute names used here are just examples: your LDAP ".
344347
"server may use different attribute names."),
348+
self::KEY_ALWAYS_SEARCH => pht(
349+
"To search for an LDAP record before authenticating, either check ".
350+
"the **Always Search** checkbox or enter an anonymous ".
351+
"username and password to use to perform the search."),
345352
self::KEY_USERNAME_ATTRIBUTE => pht(
346353
"Optionally, specify a username attribute to use to prefill usernames ".
347354
"when registering a new account. This is purely cosmetic and does not ".

0 commit comments

Comments
 (0)