You are here

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

Derives the Drupal user name from server configuration.

Return value

bool Success of deriving Drupal user name.

2 calls to LoginValidatorBase::deriveDrupalUserName()
LoginValidatorLoginForm::processLogin in ldap_authentication/src/Controller/LoginValidatorLoginForm.php
Perform the actual logging in.
LoginValidatorSso::processLogin in ldap_authentication/src/Controller/LoginValidatorSso.php
Perform the actual logging in.

File

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

Class

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

Namespace

Drupal\ldap_authentication\Controller

Code

protected function deriveDrupalUserName() : bool {

  // If account_name_attr is set, Drupal username is different than authName.
  if ($this->serverDrupalUser
    ->hasAccountNameAttribute()) {
    $user_name_from_attribute = $this->ldapEntry
      ->getAttribute($this->serverDrupalUser
      ->getAccountNameAttribute(), FALSE)[0];
    if (!$user_name_from_attribute) {
      $this->logger
        ->error('Derived Drupal username from attribute %account_name_attr returned no username for authname %authname.', [
        '%authname' => $this->authName,
        '%account_name_attr' => $this->serverDrupalUser
          ->getAccountNameAttribute(),
      ]);
      return FALSE;
    }
    $this->drupalUserName = $user_name_from_attribute;
  }
  else {
    $this->drupalUserName = $this->authName;
  }
  $this
    ->prepareEmailTemplateToken();
  return TRUE;
}