refactor: AD Auth defer connection until it is needed (#7768)

* refactor: AD Auth defer connection until it is needed
Nice error if php-ldap is missing instead of http 500.

* Add the same error when ldap is missing to other auth methods.
Not as graceful looking in the authorizers since they do not defer connection.
This commit is contained in:
Tony Murray
2017-11-28 09:19:34 -06:00
committed by GitHub
parent 8d98fa5a5e
commit 6b5dccc169
6 changed files with 64 additions and 42 deletions

View File

@@ -15,6 +15,10 @@ class ADAuthorizationAuthorizer extends AuthorizerBase
$_SESSION['username'] = '';
}
if (!function_exists('ldap_connect')) {
throw new AuthenticationException("PHP does not support LDAP, please install or enable the PHP LDAP extension.");
}
// Disable certificate checking before connect if required
if (Config::has('auth_ad_check_certificates') &&
Config::get('auth_ad_check_certificates') == 0) {
@@ -24,8 +28,7 @@ class ADAuthorizationAuthorizer extends AuthorizerBase
// Set up connection to LDAP server
$this->ldap_connection = @ldap_connect(Config::get('auth_ad_url'));
if (! $this->ldap_connection) {
echo '<h2>Fatal error while connecting to AD url ' . Config::get('auth_ad_url') . ': ' . ldap_error($this->ldap_connection) . '</h2>';
exit;
throw new AuthenticationException('Fatal error while connecting to AD url ' . Config::get('auth_ad_url') . ': ' . ldap_error($this->ldap_connection));
}
// disable referrals and force ldap version to 3