Unable to update LDAP entry on User edit

Created on 4 November 2021, almost 3 years ago
Updated 3 September 2024, 25 days ago

Problem/Motivation

When I create a new Drupal User, his entry is also well created in the LDAP. I'm able to connect with it's credentials to Drupal.
But when I try to edit some of his fields, those values are not updated in LDAP.

When I checked the code, I saw that on edit it checks if my User exists in the authmap table, which he isn't and I don't understand why. I was unable to track down at which point the User id is saved to this table.

The logs is giving me only this error LDAP server if exception: Could not add entry "cn=XXXX,ou=users,dc=XXXX,dc=com": Already exists
Which I assume comes from this code:

public function userUpdated(LdapUserUpdatedEvent $event): void {
    $this->account = $event->account;
    if (
      $this->provisionLdapEntriesFromDrupalUsers() &&
      \in_array(self::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_UPDATE_CREATE, $this->config->get('ldapEntryProvisionTriggers'), TRUE) &&
      $this->account->get('ldap_user_ldap_exclude')->getString() !== '1'
    ) {
      $this->loadServer();
      if ($this->checkExistingLdapEntry()) {
        $this->syncToLdapEntry();
      }
      else {
        // This should only be necessary if the entry was deleted on the
        // directory server.
        $this->provisionLdapEntry();
      }
    }
  }

When no UID found in authmap (in checkExistingLdapEntry()) then create a LDAP entry (in provisionLdapEntry()) which already exists.

So in fact, the problem is that on Drupal User creation there is no entry made to the table authmap, nor the user ldap fields are set (ldap_user_current_dn, ldap_user_puid_sid etc.).
It's not getting inside any of the methods that are saving to that table.

$this->externalAuth->save($this->account, 'ldap_user', $this->account->getAccountName());

// Which is inside:
createDrupalUser();
ldapAssociateDrupalAccount();
updateExistingAccountByPersistentUid()

It seems though that on the version 8.x.3 it works fine.

Steps to reproduce

  1. Create Drupal User
  2. Login
  3. Edit User fields

My LDAP User Settings

The status of my created User is well approved.

πŸ’¬ Support request
Status

Active

Version

4.2

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    Hi @Lus,

    Is there still an issue with creating LDAP entities? Provisioned from Drupal to LDAP?

    If you upgrade to 8.x-4.7, you can post your debug report and the community and better troubleshoot the issue.

    https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... β†’

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
  • πŸ‡«πŸ‡·France oturpin

    Hello
    Using 8.x-4.7 : I cannot update any user on openldap.
    After applying patch from https://www.drupal.org/project/ldap/issues/3210293 πŸ› Can't create LDAP entry -- undefined attribute type Needs review , I was able to create ldap entry.
    But cannot apply any update:
    "LDAP server ketoprofene exception: Could not add entry "uid=popeu,ou=users,dc=equidome,dc=fr": Already exists"
    On my install , debug report crashes everytime:
    [Wed Mar 27 14:03:58.705411 2024] [php:notice] [pid 906] [client 192.168.2.9:37218] Uncaught PHP Exception InvalidArgumentException: "Class "\\Drupal\\ldap_servers\\Form\\DebuggingReviewForm" does not exist." at /home/oturpin/equiresa/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php line 24, referer: http://klipal/admin/reports/dblog

  • Status changed to Active 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
  • Thank you for your investigation and documentation! This issue is still a problem for me using version 8.x-4.11 with openLDAP.

    Only if registration by admin is selected here ldap accounts can be associated with drupal accounts by creating them manually with the checkbox "Create corresponding LDAP entry".
    /admin/config/people/accounts

    I want to enable self registration and use openLDAP. But with this issue it is not possible because user entries in LDAP will not get updated.

    Without an authmap entry / the user profile ldap fields the module always tries to create new ldap entry when an profile update is triggered. The module throws an error and does not associate the existing ldap entry with the drupal user account.

    Error:
    LDAP server ldap_xy exception: Could not add entry "uid=xy,ou=People,dc=xy,dc=xy": Already exists

    It would be awesome if anybody could find a solution for this problem.

  • I tried to find a temporary fix for the specific problem that there is no authmap entry and the ldap entry is not associated with the user profile when self registration via drupal is used.
    I hope OpenLDAP support will be systematically for this module and there will be a solution provided by one of the next minor updates.

    diff --git a/LdapEntryProvisionSubscriber.php b/LdapEntryProvisionSubscriber_patched.php
    index e69e6bf..7cdc2de 100644
    --- a/LdapEntryProvisionSubscriber.php
    +++ b/LdapEntryProvisionSubscriber_patched.php
    @@ -545,6 +545,21 @@ class LdapEntryProvisionSubscriber implements EventSubscriberInterface, LdapUser
           $callback_params = [$entry, $this->ldapServer, $context];
           $this->moduleHandler->invokeAll('ldap_entry_post_provision', $callback_params);
           $this->updateUserProvisioningReferences($entry);
    +
    +      /* tmp fix issue 3247641 begin */
    +       $userProcessor = \Drupal::service('ldap.drupal_user_processor');
    +       $userName = $this->account ? $this->account->getAccountName() : Null;
    +       if(!empty($userName)) {
    +               $association = $userProcessor->ldapAssociateDrupalAccount($userName);
    +
    +               if (!$association) {
    +                       \Drupal::messenger()->addWarning(t('Account created but no LDAP account found to associate with.'));
    +               }
    +       }else {
    +               \Drupal::messenger()->addWarning(t('Account name missing. Association with LDAP account failed.'));
    +       }
    +
    +       /* tmp fix issue 3247641 end */
         }
         else {
           $this->logger->error('LDAP entry for @username cannot be created on @sid. Proposed DN: %dn)',
    
Production build 0.71.5 2024