You are here

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

Update the authName if it's no longer valid.

Drupal account does not exist for authName used to logon, but puid exists in another Drupal account; this means username has changed and needs to be saved in Drupal account.

2 calls to LoginValidatorBase::updateAuthNameFromPuid()
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 633

Class

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

Namespace

Drupal\ldap_authentication\Controller

Code

protected function updateAuthNameFromPuid() : void {
  $puid = $this->serverDrupalUser
    ->derivePuidFromLdapResponse($this->ldapEntry);
  if (!empty($puid)) {
    $this->drupalUser = $this->ldapUserManager
      ->getUserAccountFromPuid($puid);

    /** @var \Drupal\user\Entity\User $userMatchingPuid */
    if ($this->drupalUser) {
      $oldName = $this->drupalUser
        ->getAccountName();
      $this->drupalUser
        ->setUsername($this->drupalUserName);
      $this->drupalUser
        ->save();
      $this->externalAuth
        ->save($this->drupalUser, 'ldap_user', $this->authName);
      $this->drupalUserAuthMapped = TRUE;
      $this->messenger
        ->addStatus($this
        ->t('Your existing account %username has been updated to %new_username.', [
        '%username' => $oldName,
        '%new_username' => $this->drupalUserName,
      ]));
    }
  }
}