Example #1
0
 /**
  * {@inheritdoc}
  */
 public function bindUsingCredentials($username, $password, $suffix = null)
 {
     if (empty($username)) {
         // Allow binding with null username.
         $username = null;
     } else {
         // If the username isn't empty, we'll append the configured
         // account suffix to bind to the LDAP server.
         if (is_null($suffix)) {
             $suffix = $this->configuration->getAccountSuffix();
         }
         $username .= $suffix;
     }
     if (empty($password)) {
         // Allow binding with null password.
         $password = null;
     }
     try {
         $this->connection->bind($username, $password);
     } catch (Exception $e) {
         $error = $this->connection->getLastError();
         if ($this->connection->isUsingSSL() && $this->connection->isUsingTLS() === false) {
             $message = 'Bind to Active Directory failed. Either the LDAP SSL connection failed or the login credentials are incorrect. AD said: ' . $error;
         } else {
             $message = 'Bind to Active Directory failed. Check the login credentials and/or server details. AD said: ' . $error;
         }
         throw new BindException($message);
     }
 }