protected function GroupUserUpdateProcessor::processAccount in Lightweight Directory Access Protocol (LDAP) 8.4
Create or update an entry in Drupal.
Parameters
\Symfony\Component\Ldap\Entry $entry: LDAP entry.
string $attribute: Authname attribute.
1 call to GroupUserUpdateProcessor::processAccount()
- GroupUserUpdateProcessor::runQuery in ldap_user/
src/ Processor/ GroupUserUpdateProcessor.php - Runs the updating mechanism.
File
- ldap_user/
src/ Processor/ GroupUserUpdateProcessor.php, line 259
Class
- GroupUserUpdateProcessor
- Provides functionality to generically update existing users.
Namespace
Drupal\ldap_user\ProcessorCode
protected function processAccount(Entry $entry, string $attribute) : void {
if (!$entry
->hasAttribute($attribute, FALSE)) {
// Missing authname attribute.
$this->detailLog
->log('DN @dn missing authentication name.', [
'@dn' => $entry
->getDn(),
], 'ldap_user');
return;
}
$username = $entry
->getAttribute($attribute, FALSE)[0];
// Make sure nothing from the previous request can interact on login.
$this->drupalUserProcessor
->reset();
$uid = $this->externalAuth
->getUid($username, 'ldap_user');
if (!$uid) {
$result = $this->drupalUserProcessor
->createDrupalUserFromLdapEntry([
'name' => $username,
'status' => TRUE,
]);
if ($result) {
$this->detailLog
->log('Periodic update: @name created', [
'@name' => $username,
], 'ldap_user');
$uid = $this->externalAuth
->getUid($username, 'ldap_user');
}
else {
$this->logger
->error('Periodic update: Error creating user @name', [
'@name' => $username,
]);
return;
}
}
// User exists and is mapped in authmap.
/** @var \Drupal\user\Entity\User $drupal_account */
$drupal_account = $this->userStorage
->load($uid);
$this->drupalUserProcessor
->drupalUserLogsIn($drupal_account);
// Reload since data has changed.
/** @var \Drupal\user\UserInterface $user */
$user = $this->userStorage
->load($drupal_account
->id());
$this
->updateAuthorizations($user);
$this->detailLog
->log('Periodic update: @name updated', [
'@name' => $username,
], 'ldap_user');
}