Reviewed & tested by the community
Project:
simpleSAMLphp Authentication
Version:
8.x-3.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
30 Oct 2013 at 16:28 UTC
Updated:
18 Mar 2025 at 13:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
nitebreedHaving the same issue. Noticed it has to do with the user I was masquerading to didn't have a role that was enabled for local login
Comment #2
odegard commentedCan cofirm. Users you want to masquerade to must be specified in "Which users should be allowed to login with local accounts?", or leave blank for all.
Comment #3
zekvyrin commentedThis is closely related to #2478499: User 1: Automatic Logout after saving configuration
It's exactly the same code which logs out users not authenticated from simplesaml.
Comment #4
odegard commentedI've taken a closer look at this and found a solution, see patch.
It is as Zekvyrin points out a problem with simplesamlphp_auth_user_logout - it logges out "too much".
I've not been able to solve the "problem", I've found a way around it. Caveat emptor.
I considered two options:
1) Patch masquerade to set a session variable before invoking user_logout which runs simplesamlphp_auth_user_logout AND patch simplesamlphp_auth to check for this variable.
2) Find another way that only affects simplesamlphp_auth.
This patch incorporates option 2 by checking the backtrace for the two masquerade-functions involved when invoking user_logout.
Comment #5
odegard commentedUpdated patch. Switched out ddebug_backtrace with debug_backtrace since the first one requires that the user has access to devel and normal users should not.
Comment #6
berdirHere is an 8.x patch that relies on #2975124: Masquarade Saml compatibility issue and then checks for the session key, much less hackery required but it does need a masquerade patch too per the previous issue.
Comment #7
berdirAlso, you will likely also need the patch from #2975184: Masquerading as user not authenticated causes logout to remain logged in.
Comment #8
andypostComment #9
andypostMasquerade issue commited
Comment #10
jplana commentedI can confirm the patch #6 works for me, with the latest dev branch of the masquerade module.
Thanks @Berdir for the patch and @andypost for the tip!
Comment #11
joelpittetThis is helpful thanks @andypost and @Berdir!
Comment #12
andypostNew beta released https://www.drupal.org/project/masquerade/releases/8.x-2.0-beta3
Comment #13
berdirThere's also a related issue here: #2975184: Masquerading as user not authenticated causes logout, you might need that if you disallow local logins for example. Testing of that would be appreciated so I can commit both. FWIW, this patch should also switch to doing a hasService() && isMasquerading approach to use the API like the new patch over there.
Comment #14
joelpittetRerolled
Comment #15
fengtanWe faced the same issue in Drupal 7 and were able to fix it by applying this patch from the masquerade module (it has been committed to 7.x-1.x-dev but has not been included in a stable release yet): https://www.drupal.org/project/masquerade/issues/2124113#comment-11760980
Comment #16
devkinetic commented#11 working great!
Comment #18
kobe wright commentedEncountered a fatal after a D9 upgrade when trying to masquerade while being logged in using simplesaml because the $account parameter is a User object (not AccountProxy) which doesn't have the setAccount() function.
Created an issue fork with a solution based on the patch in #14, opted to check if the masquerade module is enabled and leaving it up to that module to indicate if the user is masquerading.
Comment #20
kobe wright commentedComment #21
elmis hernandezHello,
I also found this problem and although they say that #14 works, for me it worked only after applying it also in the Subscriber.
Here I leave my change and the difference between #14 and my change.
Comment #22
hfernandes commented#21 worked here.
Comment #23
devkinetic commentedThis looks good to me as well.
Comment #24
kecsotWould be nice to implement another solution except hardcoding 'masquerading' session check to simplesamlphp_auth.
Also good idea to Close with won't do.
What do you think?
Comment #25
pfrenssenSetting back to needs work since the patch from #21 is conflicting with #2975184: Masquerading as user not authenticated causes logout. I think the right way forward for this issue is probably to follow the approach proposed by @berdir (co-maintainer of this module) in comment #13, and making sure we address the fatal mentioned in #18.
Comment #27
pfrenssenAdded a new MR with the suggestions from #2124117-13: Unable to masquerade when logging in via SAML and #2124117-18: Unable to masquerade when logging in via SAML. This is meant to be used together with #2975184: Masquerading as user not authenticated causes logout.
Comment #28
hazn commentedLooks good to me :) Thanks Pieter!
Comment #29
himanshu5050 commentedI think its better to use Drupal::service('masquerade')->isMasquerading() to check masquerading.
Added patch.