You are here

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

Verifies whether the user is available or can be created.

Return value

bool Whether to allow user login and creation.

1 call to LoginValidator::verifyAccountCreation()
LoginValidator::validateCommonLoginConstraints in ldap_authentication/src/Controller/LoginValidator.php
Validate common login constraints for user.

File

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

Class

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

Namespace

Drupal\ldap_authentication\Controller

Code

private function verifyAccountCreation() {
  if (is_object($this->drupalUser)) {

    // @TODO 2914053.
    if ($this->drupalUser
      ->id() == 1) {
      $this->detailLog
        ->log('%username: Drupal user name maps to user 1, so do not authenticate with LDAP.', [
        '%username' => $this->authName,
      ], 'ldap_authentication');
      return FALSE;
    }
    else {
      $this->detailLog
        ->log('%username: Drupal user account found. Continuing on to attempt LDAP authentication.', [
        '%username' => $this->authName,
      ], 'ldap_authentication');
      return TRUE;
    }
  }
  else {
    $ldapUserConfig = $this->configFactory
      ->get('ldap_user.settings');
    if ($ldapUserConfig
      ->get('acctCreation') == self::ACCOUNT_CREATION_LDAP_BEHAVIOUR || $ldapUserConfig
      ->get('register') == USER_REGISTER_VISITORS) {
      $this->detailLog
        ->log('%username: Existing Drupal user account not found. Continuing on to attempt LDAP authentication', [
        '%username' => $this->authName,
      ], 'ldap_authentication');
      return TRUE;
    }
    else {
      $this->detailLog
        ->log('%username: Drupal user account not found and configuration is set to not create new accounts.', [
        '%username' => $this->authName,
      ], 'ldap_authentication');
      return FALSE;
    }
  }
}