You are here

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

Derives the Drupal user name from server configuration.

Return value

bool Success of deriving Drupal user name.

2 calls to LoginValidator::deriveDrupalUserName()
LoginValidator::processLogin in ldap_authentication/src/Controller/LoginValidator.php
Perform the actual logging in.
LoginValidator::processSsoLogin in ldap_authentication/src/Controller/LoginValidator.php
Processes an SSO login.

File

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

Class

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

Namespace

Drupal\ldap_authentication\Controller

Code

private function deriveDrupalUserName() {

  // If account_name_attr is set, Drupal username is different than authName.
  if (!empty($this->serverDrupalUser
    ->get('account_name_attr'))) {
    $processedName = mb_strtolower($this->serverDrupalUser
      ->get('account_name_attr'));
    $userNameFromAttribute = $this->ldapUser['attr'][$processedName][0];
    if (!$userNameFromAttribute) {
      $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
          ->get('account_name_attr'),
      ]);
      return FALSE;
    }
    else {
      $this->drupalUserName = $userNameFromAttribute;
    }
  }
  else {
    $this->drupalUserName = $this->authName;
  }
  $this
    ->prepareEmailTemplateToken();
  return TRUE;
}