X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/0821672e70cf9eb81091032514634b299cc5900b..refs/pull/234/head:/app/Services/LdapService.php diff --git a/app/Services/LdapService.php b/app/Services/LdapService.php index d33f8c378..40b24f141 100644 --- a/app/Services/LdapService.php +++ b/app/Services/LdapService.php @@ -36,6 +36,7 @@ class LdapService public function getUserDetails($userName) { $ldapConnection = $this->getConnection(); + $this->bindSystemUser($ldapConnection); // Find user $userFilter = $this->buildFilter($this->config['user_filter'], ['user' => $userName]); @@ -45,7 +46,7 @@ class LdapService $user = $users[0]; return [ - 'uid' => $user['uid'][0], + 'uid' => (isset($user['uid'])) ? $user['uid'][0] : $user['dn'], 'name' => $user['cn'][0], 'dn' => $user['dn'], 'email' => (isset($user['mail'])) ? $user['mail'][0] : null @@ -93,7 +94,7 @@ class LdapService $ldapBind = $this->ldap->bind($connection, $ldapDn, $ldapPass); } - if (!$ldapBind) throw new LdapException('LDAP access failed using ' . $isAnonymous ? ' anonymous bind.' : ' given dn & pass details'); + if (!$ldapBind) throw new LdapException(($isAnonymous ? trans('errors.ldap_fail_anonymous') : trans('errors.ldap_fail_authed'))); } /** @@ -108,7 +109,7 @@ class LdapService // Check LDAP extension in installed if (!function_exists('ldap_connect') && config('app.env') !== 'testing') { - throw new LdapException('LDAP PHP extension not installed'); + throw new LdapException(trans('errors.ldap_extension_not_installed')); } // Get port from server string if specified. @@ -116,12 +117,12 @@ class LdapService $ldapConnection = $this->ldap->connect($ldapServer[0], count($ldapServer) > 1 ? $ldapServer[1] : 389); if ($ldapConnection === false) { - throw new LdapException('Cannot connect to ldap server, Initial connection failed'); + throw new LdapException(trans('errors.ldap_cannot_connect')); } // Set any required options if ($this->config['version']) { - $this->ldap->setOption($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, $this->config['version']); + $this->ldap->setVersion($ldapConnection, $this->config['version']); } $this->ldapConnection = $ldapConnection;