Problem/Motivation

Drupal\ldap_user\Processor\DrupalUserProcessor::createDrupalUser() function stores Drupal account name as authName in authmap table. When new users are created in Drupal, the Drupal account name is derived from the value of the accountName attribute. This is fine when the authName and accountName share the same attribute, e.g. for AD usually it's sAMAccountName. However, when the accountName attribute is different than the authName attribute, the login function breaks.

Steps to reproduce

  1. Configure a LDAP server, and set different attributes for authentication name and account name. E.g. we use userPrincipalName for authName attribute and sAMAccountName for accountName attribute.
  2. Create / use existing user object in the LDAP server. Make sure that the values for authName and accountName are different in the LDAP server. E.g. we use johndoe for accountName and johndoe@realm for authName.
  3. Configure the authentication to exclusive mode and user provisioning settings to sync user from LDAP to Drupal.
  4. Make sure that the user does not exist in Drupal.
  5. Log in as the user in Drupal. User should be created successfully. Observe the authmap table. You should observe abc in the authname column.
  6. Log out, and try to log in again. You should encounter the error here.
  7. Update the authmap table manually, change authname to abc@realm.
  8. Try logging in as the same user again. This should be successful.

Proposed resolution

Store the authName value obtained from LDAP server (instead of Drupal account name) in the authmap table when creating a new Drupal user.

Remaining tasks

Review the submitted patch and merge to main.

User interface changes

None.

API changes

None.

Data model changes

The authname column in authmap table is changed from Drupal account name to LDAP authname.

  • This should be fine for sites which use the same accountName attribute as the authName attribute.
  • For sites which use different attributes, the only way those sites managed to get it to work in the first place is that the value of the authName attribute is the same as the value of the accountName attribute, and therefore there is no issue updating the code without updating the database value.

Conclusion: no hook_update_N is necessary.

Release notes snippet

Fix Drupal\ldap_user\Processor\DrupalUserProcessor::createDrupalUser() to store authName in the authmap table.

Issue fork ldap-3373783

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Lee Jun Long created an issue. See original summary.

lee jun long’s picture

Status: Active » Needs review

Please review submitted patch in MR !38.

bluegeek9 made their first commit to this issue’s fork.

lee jun long’s picture

Hi bluegeek9,

Just curious, why was branch '8.x-4.x' merged into my MR? I had thought it would be the other way round (or maybe I am not looking at the right place).

bluegeek9’s picture

Priority: Major » Minor

Hi @Lee Jun Long,

Your branch was stale. It was 17 commits behind 8.x-4.x. Your pull request is still open. I am merging 8.x-4.x again to pull in the changes to Gitlab CI. Drupal 9 is no longer supported in the CI pipeline. The tests should run and pass now.

I don't know if this is needed since the username is mapped to the domain username.

bluegeek9’s picture

Status: Needs review » Needs work

The tests fail with your changes.