Problem/Motivation

LDAP Query does not continue all users if the user already exists in the system with the same email address

Steps to reproduce

- Create a user with an email and user name that exists in LDAP System.
- Install and config LDAP module and config
Existing Drupal User Account Conflict to be "Associate Drupal account with the LDAP entry. This option is useful for creating accounts and assigning roles before an LDAP user authenticates."
- Config LDAP Query
- Run the Cron
- Query stopped because "Another user already exists in the system with the same email address."

Proposed resolution

Update the user if has same email and user name to sync with LDAP.

Comments

Qusai Taha created an issue. See original summary.

qusai taha’s picture

Assigned: qusai taha » Unassigned
Status: Active » Needs review
StatusFileSize
new1.92 KB
qusai taha’s picture

StatusFileSize
new1.88 KB
lars.stiebenz’s picture

StatusFileSize
new3.37 KB

The Patch in #3304327-3: Fix LDAP Query does not continue all users if the user already exists in the system with the same email address works for the case that a Drupal user without LDAP mapping exists and gets related to an LDAP account with the same mail and name through the cron update.

My problem goes a bit further. I get LDAP accounts with different names but the same mail from the source. Reporting this in the log with the "Another user already exists[...]" message is fine and a reminder for the LDAP manager. But the cron job currently gets interrupted with a PHP error and warning:

TypeError: Drupal\ldap_user\Processor\DrupalUserProcessor::drupalUserLogsIn(): Argument #1 ($account) must be of type Drupal\user\UserInterface, null given, called in /var/www/html/docroot/modules/contrib/ldap/ldap_user/src/Processor/GroupUserUpdateProcessor.php on line 302 in Drupal\ldap_user\Processor\DrupalUserProcessor->drupalUserLogsIn() (line 431 of /var/www/html/docroot/modules/contrib/ldap/ldap_user/src/Processor/DrupalUserProcessor.php)

Warning: array_flip(): Can only flip string and integer values, entry skipped in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 312 of /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)

I added a check to the GroupUserUpdateProcessor to only proceed with the update for a single account if there is a valid UID.

osamahdev1’s picture

Component: Code » Tests
Assigned: Unassigned » osamahdev1
Status: Needs review » Reviewed & tested by the community
Issue tags: +PHP 7.4 & MySQL 8, +D9.4 Skipped, +branch did not pass for 4 weeks

It worked perfectly

bluegeek9’s picture

Assigned: osamahdev1 » Unassigned
Issue tags: -PHP 7.4 & MySQL 8, -D9.4 Skipped, -branch did not pass for 4 weeks
bluegeek9’s picture

Status: Reviewed & tested by the community » Active
Parent issue: » #2883852: Handle duplicate emails
hamzadwaya’s picture

Version: 8.x-4.3 » 8.x-4.x-dev
Component: Tests » Code
StatusFileSize
new3.29 KB

In my situation, the patch wasn't working effectively when a user logged in and another user had the same email but a different username. I discovered that the patch was checking if the logged-in user had the same username, which always triggered the error message: 'Another user already exists in the system with the same email address. You should contact the system administrator to resolve this conflict.'

To resolve this, I modified the code to remove the username check, tested it, and found that it works fine