Duplicate email addresses during LDAP sync cause GroupUserUpdateProcessor to abort

Created on 9 May 2022, about 2 years ago
Updated 9 April 2024, 3 months ago

Problem/Motivation

During cron runs, synchronizing against LDAP, if an account in LDAP has the same email as an account in Drupal but different dn, the process aborts when it gets to that account and no other accounts are processed.

Steps to reproduce

Existing account in Drupal as DOEJ with email john.doe@email.com and account in LDAP as DOEJO with email john.doe@email.com

 [error]  LDAP user DOEJO has email address (john.doe@email.com) conflict with a Drupal user DOEJ
 [warning] array_flip(): Can only flip STRING and INTEGER values! EntityStorageBase.php:261
 [error]  TypeError: Argument 1 passed to Drupal\ldap_user\Processor\DrupalUserProcessor::drupalUserLogsIn() must implement interface Drupal\user\UserInterface, null given, called in /var/www/html/web/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/web/modules/contrib/ldap/ldap_user/src/Processor/DrupalUserProcessor.php) #0 /var/www/html/web/modules/contrib/ldap/ldap_user/src/Processor/GroupUserUpdateProcessor.php(302): Drupal\ldap_user\Processor\DrupalUserProcessor->drupalUserLogsIn()
#1 /var/www/html/web/modules/contrib/ldap/ldap_user/src/Processor/GroupUserUpdateProcessor.php(246): Drupal\ldap_user\Processor\GroupUserUpdateProcessor->processAccount()
#2 /var/www/html/web/modules/contrib/ldap/ldap_user/ldap_user.module(42): Drupal\ldap_user\Processor\GroupUserUpdateProcessor->runQuery()
#3 [internal function]: ldap_user_cron()
...
 [warning] Drush command terminated abnormally.

I have tried to trace the flow through the code, and it looks as though the request goes into GroupUserUpdateProcessor.php processAccount, where there is no match on uid, so $result = $this->drupalUserProcessor->createDrupalUserFromLdapEntry is called.

This function returns a result of true, even though the create process failed due to the email conflict. The failure actually occurs within DrupalUserProcessor.php createDrupalUser function, but is not passed up to createDrupalUserFromLdapEntry or back to processAccount.

Ideally the error would be caught sooner in the process, but as a workaround, I have found that a second check of the uid at line 288 of GroupUserUpdateProcessor.php will catch the failure and the process can be logged for the account in question, allowing the rest of the job to complete.

🐛 Bug report
Status

Active

Version

4.3

Component

Code

Created by

🇨🇦Canada Brandon-

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.

Production build 0.69.0 2024