]> BookStack Code Mirror - bookstack/blobdiff - app/Services/LdapService.php
Update Ldap.php
[bookstack] / app / Services / LdapService.php
index d33f8c378fdb1fc87d2878d2dfda3fff40efcb4e..b7f101ad2c3a9088357941df9c042eb973081dcb 100644 (file)
@@ -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('LDAP access failed using ' . ($isAnonymous ? ' anonymous bind.' : ' given dn & pass details'));
     }
 
     /**
@@ -121,7 +122,7 @@ class LdapService
 
         // 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;