You are here

private function LoginValidator::bindToServer in Lightweight Directory Access Protocol (LDAP) 8.3

Bind to server.

Parameters

string $password: User password.

Return value

mixed Success or failure result.

1 call to LoginValidator::bindToServer()
LoginValidator::testCredentials in ldap_authentication/src/Controller/LoginValidator.php
Credentials are tested.

File

ldap_authentication/src/Controller/LoginValidator.php, line 1048

Class

LoginValidator
Handles the actual testing of credentials and authentication of users.

Namespace

Drupal\ldap_authentication\Controller

Code

private function bindToServer($password) {
  $bindResult = FALSE;
  $bindMethod = $this->serverDrupalUser
    ->get('bind_method');
  if ($bindMethod == 'user') {
    foreach ($this->serverDrupalUser
      ->getBaseDn() as $basedn) {
      $search = [
        '%basedn',
        '%username',
      ];
      $replace = [
        $basedn,
        $this->authName,
      ];
      CredentialsStorage::storeUserDn(str_replace($search, $replace, $this->serverDrupalUser
        ->get('user_dn_expression')));
      CredentialsStorage::testCredentials(TRUE);
      $bindResult = $this->serverDrupalUser
        ->bind();
      if ($bindResult == Server::LDAP_SUCCESS) {
        break;
      }
    }
  }
  else {
    $bindResult = $this->serverDrupalUser
      ->bind();
  }
  if ($bindResult != Server::LDAP_SUCCESS) {
    $this->detailLog
      ->log('%username: Trying server %id (bind method: %bind_method). Error: %err_text', [
      '%username' => $this->authName,
      '%id' => $this->serverDrupalUser
        ->id(),
      '%err_text' => $this->serverDrupalUser
        ->formattedError($bindResult),
      '%bind_method' => $this->serverDrupalUser
        ->get('bind_method'),
    ], 'ldap_authentication');
    if ($this->serverDrupalUser
      ->get('bind_method') == 'user') {
      return self::AUTHENTICATION_FAILURE_CREDENTIALS;
    }
    else {
      return self::AUTHENTICATION_FAILURE_BIND;
    }
  }
  return 'success';
}