Problem/Motivation
The Samlauth module allows SAML users to be mapped to local users by one or more of:
- Enable matching on name
- Enable matching on email
When logging in, Drupal\samlauth\SamlService->doLogin is called. This will do the following if no account is passed in:
- Look up the saml user login
- Look up any local users with the same login as the saml login
- If a local user is found, see if linking by name is allowed
- If linking by name is configured, allow login to proceed
- If linking by name is not configured throw an exception with user message "A local user account with your login name already exists, and we are disallowed from linking it"
- If no account was found by login, perform the same checks as above but by email
The problem is that if you are linking by email and not by name, a legitimate saml user who has both a matching name and email to a local user will not be able to log in. They'll be found by the login lookup, and because login linking is off, they'll be denied access. However, they really should be allowed access because their email does match.
Steps to reproduce
Create a local user:
login: test
email: test@example.com
Configure samlauth module with:
Enable matching on name - off
Enable matching on email - on
Attempt to log in as test user via saml - the link exception will be thrown
Proposed resolution
If a user account is found by name, and linking by name is off, do not immediately throw an exception. Rather, check if linking by email is enabled, the saml user has an email and the email matches the local user email. Only if all of those test fail throw the exception.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3368600-7.patch | 2.56 KB | heatherwoz |
| #5 | 3368600-5.patch | 2.52 KB | liberatr |
Issue fork samlauth-3368600
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
ipa 🍺 commentedI had the same problem and the merge request !11 fixed it, thanks!
Comment #4
davej commentedSame issue here with 8.x-3.9 . Merge request 11 fixed it here too, thank you!
Comment #5
liberatrAttempting to reroll against 3.10
Still have yet to test the functionality.
Comment #7
heatherwoz commentedI attempted to rebase the MR and resolve the conflict, but I'm not sure if I did it correctly. Here is a patch with the latest changes. Patch in #5 applied but caused errors for me.
Comment #8
heatherwoz commentedComment #10
roderikYes, patch #5 caused problems: a bracket was removed, so the whole class is invalid / causes errors.
@heatherwoz
In this case, I rebased and force-pushed into the branch (to have cleaner history)... because I was going to merge it and close the issue anyway.
Anyway, that's detail :-)
---
Thank you for the fix. This is a clear bug, but I had ignored the issue for the previous release. Among others, because I felt like this really needs tests, to make sure that it doesn't break anything else unexpectedly. (The code in the fix looks fine, but... the existence of the bug already proves that things are getting too complicated to not have tests. I guess I should have set the issue to Needs Work in the meantime; it took longer than I thought.)
That's done now. Tests for the user creation/linking logic are included, which makes me feel a lot safer for future rewrites/fixes. I also discovered another bug, which I'll fix in #3496176: SAML login must not be linked to an already-linked user, and added some tiny code tweaks and things to the README while thinking about tested behavior.
Comment #12
roderikI still get caught by the fact that the pre-formatted commit message cannot be edited, when merging from the drupal.org issue. Otherwise I'd have changed it slightly.
Anyway, fixed and credited.