You are here

protected function LoginValidatorBase::bindToServerAsUser in Lightweight Directory Access Protocol (LDAP) 8.4

Bind to server.

Return value

int Success or failure result.

1 call to LoginValidatorBase::bindToServerAsUser()
LoginValidatorBase::bindToServer in ldap_authentication/src/Controller/LoginValidatorBase.php
Bind to server.
1 method overrides LoginValidatorBase::bindToServerAsUser()
LoginValidatorSso::bindToServerAsUser in ldap_authentication/src/Controller/LoginValidatorSso.php
Bind to server.

File

ldap_authentication/src/Controller/LoginValidatorBase.php, line 929

Class

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

Namespace

Drupal\ldap_authentication\Controller

Code

protected function bindToServerAsUser() : int {
  $bindResult = FALSE;
  foreach ($this->serverDrupalUser
    ->getBaseDn() as $base_dn) {
    $search = [
      '%basedn',
      '%username',
    ];
    $replace = [
      $base_dn,
      $this->authName,
    ];
    CredentialsStorage::storeUserDn(str_replace($search, $replace, $this->serverDrupalUser
      ->getUserDnExpression()));
    CredentialsStorage::testCredentials(TRUE);
    $bindResult = $this->ldapBridge
      ->bind();
    if ($bindResult) {
      break;
    }
  }
  if (!$bindResult) {
    $this->detailLog
      ->log('%username: Unsuccessful with server %id (bind method: %bind_method)', [
      '%username' => $this->authName,
      '%id' => $this->serverDrupalUser
        ->id(),
      '%bind_method' => $this->serverDrupalUser
        ->get('bind_method'),
    ], 'ldap_authentication');
    return self::AUTHENTICATION_FAILURE_CREDENTIALS;
  }
  return self::AUTHENTICATION_SUCCESS;
}