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
- Configure a LDAP server, and set different attributes for authentication name and account name. E.g. we use
userPrincipalNamefor authName attribute andsAMAccountNamefor accountName attribute. - 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
johndoefor accountName andjohndoe@realmfor authName. - Configure the authentication to exclusive mode and user provisioning settings to sync user from LDAP to Drupal.
- Make sure that the user does not exist in Drupal.
- Log in as the user in Drupal. User should be created successfully. Observe the authmap table. You should observe
abcin the authname column. - Log out, and try to log in again. You should encounter the error here.
- Update the authmap table manually, change authname to
abc@realm. - 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
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
Comment #3
lee jun long commentedPlease review submitted patch in MR !38.
Comment #5
lee jun long commentedHi 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).
Comment #6
bluegeek9 commentedHi @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.
Comment #7
bluegeek9 commentedThe tests fail with your changes.