You are here

private function LdapEntryProvisionSubscriber::syncToLdapEntry in Lightweight Directory Access Protocol (LDAP) 8.4

Given a Drupal account, sync to related LDAP entry.

3 calls to LdapEntryProvisionSubscriber::syncToLdapEntry()
LdapEntryProvisionSubscriber::login in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Handle account login with LDAP entry provisioning.
LdapEntryProvisionSubscriber::userCreated in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Create or update LDAP entries on user creation.
LdapEntryProvisionSubscriber::userUpdated in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Create or update LDAP entries on user update.

File

ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php, line 588

Class

LdapEntryProvisionSubscriber
Event subscribers for creating and updating LDAP entries.

Namespace

Drupal\ldap_user\EventSubscriber

Code

private function syncToLdapEntry() : void {
  if (!$this->config
    ->get('ldapEntryProvisionServer')) {
    $this->logger
      ->error('Provisioning server not available');
    return;
  }
  try {
    $entry = $this
      ->buildLdapEntry(self::EVENT_SYNC_TO_LDAP_ENTRY);
  } catch (\Exception $e) {
    $this->logger
      ->error('Unable to prepare LDAP entry: %message', [
      '%message',
      $e
        ->getMessage(),
    ]);
    return;
  }
  if (!empty($entry
    ->getDn())) {

    // Stick $proposedLdapEntry in $ldap_entries array for drupal_alter.
    $context = [
      'action' => 'update',
      'corresponding_drupal_data_type' => 'user',
      'account' => $this->account,
    ];
    $this->moduleHandler
      ->alter('ldap_entry_pre_provision', $entry, $this->ldapServer, $context);
    $this->ldapUserManager
      ->modifyLdapEntry($entry);
    $params = [
      $entry,
      $this->ldapServer,
      $context,
    ];
    $this->moduleHandler
      ->invokeAll('ldap_entry_post_provision', $params);
    $tokens = [
      '%dn' => $entry
        ->getDn(),
      '%sid' => $this->ldapServer
        ->id(),
      '%username' => $this->account
        ->getAccountName(),
      '%uid' => !method_exists($this->account, 'id') || empty($this->account
        ->id()) ? '' : $this->account
        ->id(),
    ];
    $this->logger
      ->info('LDAP entry on server %sid synced dn=%dn for username=%username, uid=%uid', $tokens);
  }
}