]> source.dussan.org Git - nextcloud-server.git/commitdiff
LDAP: attempt to connect to backup server again, if main server is not available...
authorArthur Schiwon <blizzz@owncloud.com>
Tue, 3 Nov 2015 16:17:00 +0000 (17:17 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Fri, 6 Nov 2015 11:59:08 +0000 (12:59 +0100)
apps/user_ldap/lib/connection.php

index 2bb2e1f8cb67b05731b1c6e88daa78b5c5760dcd..baa5ffb2d472af11c644588b5f44feae9e348643 100644 (file)
@@ -534,30 +534,41 @@ class Connection extends LDAPUtility {
                                                                                \OCP\Util::WARN);
                                }
                        }
-                       if(!$this->configuration->ldapOverrideMainServer
-                          && !$this->getFromCache('overrideMainServer')) {
-                               $this->doConnect($this->configuration->ldapHost,
-                                                                $this->configuration->ldapPort);
-                               $bindStatus = $this->bind();
-                               $error = $this->ldap->isResource($this->ldapConnectionRes) ?
-                                                       $this->ldap->errno($this->ldapConnectionRes) : -1;
-                       } else {
-                               $bindStatus = false;
-                               $error = null;
+
+                       $bindStatus = false;
+                       $error = null;
+                       try {
+                               if (!$this->configuration->ldapOverrideMainServer
+                                       && !$this->getFromCache('overrideMainServer')
+                               ) {
+                                       $this->doConnect($this->configuration->ldapHost,
+                                               $this->configuration->ldapPort);
+                                       $bindStatus = $this->bind();
+                                       $error = $this->ldap->isResource($this->ldapConnectionRes) ?
+                                               $this->ldap->errno($this->ldapConnectionRes) : -1;
+                               }
+                               if($bindStatus === true) {
+                                       return $bindStatus;
+                               }
+                       } catch (\OC\ServerNotAvailableException $e) {
+                               if(trim($this->configuration->ldapBackupHost) === "") {
+                                       throw $e;
+                               }
                        }
 
                        //if LDAP server is not reachable, try the Backup (Replica!) Server
-                       if((!$bindStatus && ($error !== 0))
+                       if(    $error !== 0
                                || $this->configuration->ldapOverrideMainServer
-                               || $this->getFromCache('overrideMainServer')) {
-                                       $this->doConnect($this->configuration->ldapBackupHost,
-                                                                        $this->configuration->ldapBackupPort);
-                                       $bindStatus = $this->bind();
-                                       if(!$bindStatus && $error === -1) {
-                                               //when bind to backup server succeeded and failed to main server,
-                                               //skip contacting him until next cache refresh
-                                               $this->writeToCache('overrideMainServer', true);
-                                       }
+                               || $this->getFromCache('overrideMainServer'))
+                       {
+                               $this->doConnect($this->configuration->ldapBackupHost,
+                                                                $this->configuration->ldapBackupPort);
+                               $bindStatus = $this->bind();
+                               if($bindStatus && $error === -1) {
+                                       //when bind to backup server succeeded and failed to main server,
+                                       //skip contacting him until next cache refresh
+                                       $this->writeToCache('overrideMainServer', true);
+                               }
                        }
                        return $bindStatus;
                }