Skip to content

Commit 728afa8

Browse files
committed
Possible fix for 504 gateway timeout on unreachable LDAP server
1 parent 6703448 commit 728afa8

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

app/Models/Ldap.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,14 @@ public static function findAndBindUserLdap($username, $password)
232232

233233
if (! $ldapbind = @ldap_bind($connection, $userDn, $password)) {
234234
Log::debug("Status of binding user: $userDn to directory: (directly!) ".($ldapbind ? "success" : "FAILURE"));
235-
if (! $ldapbind = self::bindAdminToLdap($connection)) {
236-
/*
237-
* TODO PLEASE:
238-
*
239-
* this isn't very clear, so it's important to note: the $ldapbind value is never correctly returned - we never 'return true' from self::bindAdminToLdap() (the function
240-
* just "falls off the end" without ever explicitly returning 'true')
241-
*
242-
* but it *does* have an interesting side-effect of checking for the LDAP password being incorrectly encrypted with the wrong APP_KEY, so I'm leaving it in for now.
243-
*
244-
* If it *did* correctly return 'true' on a successful bind, it would _probably_ allow users to log in with an incorrect password. Which would be horrible!
245-
*
246-
* Let's definitely fix this at the next refactor!!!!
247-
*
248-
*/
249-
Log::debug("Status of binding Admin user: $userDn to directory instead: ".($ldapbind ? "success" : "FAILURE"));
250-
return false;
235+
// replicate the old bad-decryption-key detection behavior here
236+
try {
237+
Crypt::decrypt(Setting::getSettings()->ldap_pword);
238+
} catch (\Exception $e) {
239+
throw new \Exception('Your app key has changed! Could not decrypt LDAP password using your current app key, so LDAP authentication has been disabled. Login with a local account, update the LDAP password and re-enable it in Admin > Settings.');
251240
}
241+
//regardless of anything else; stuff isn't working. Return false.
242+
return false;
252243
}
253244

254245
if (! $results = ldap_search($connection, $baseDn, $filterQuery)) {

0 commit comments

Comments
 (0)