There is already a separate issue in D7 for this:
https://www.drupal.org/project/masquerade/issues/2124113

In D8, the proposed D7 solution does not get us there.

The issue as I understand it:

  • Masquarade calls $this->moduleHandler->invokeAll('user_logout', [$account])
  • SAML has an aggressive hook_user_logout that destroys the session, logs the user out, tanks everything

The incompatibility may fall under SAML. There may be a way to stash that the current user is attempting to masquarade and check for it in SAML. More to be figured out.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jnicola created an issue. See original summary.

jnicola’s picture

Adding in a patch to comment out $this->moduleHandler->invokeAll('user_logout', [$account]); but still execute drupal_static_reset('template_preprocess, which is called in user_user_logout and should be called.

For the implementation we are using no other contrib modules are using this hook besides the core user module, so this should be all good.

Berdir’s picture

> In D8, the proposed D7 solution does not get us there.

I think it would because this is the same, except there it's configurable and this is hardcoded which obviously doesn't work as a patch that could be committed.

However, the maintainer in the other issue was against this approach. I'm not 100% sure I get that, though. Wondering about what the use cases are for calling the logout hook. There seem to be very few implements of that out there.

Maybe we could alternatively move $_SESSION['masquerading'] = $account->id(); up so that other modules have a way to detect if it's a real logout or just a masquerading. See also #2124117: Unable to masquerade when logging in via SAML which tries to solve this in simplesamlphp_auth but currently requires an ugly hack to check the caller.

The template reset is IMHO not important, that would only matter if we would render anything in this context, but a) nothing has been rendered yet, so it hasn't been filled yet and b) we're not rendering anything after that.

Berdir’s picture

Status: Active » Needs review
FileSize
887 bytes

Discussed with @andypost, he prefers the session-based approach, will also upload a patch to the simplesamlphp_auth issue mentioned above in a minute.

Berdir’s picture

Title: Masquarade Samle compatibility issue » Masquarade Saml compatibility issue
Berdir’s picture

Noticed this doesn't work yet for unmasquerade, might need a similar change for the switch back part.

andypost’s picture

@Berdir is there a steps to test unmasquerade?

Berdir’s picture

Here is a patch that also switches the order for switchBack(), no additional changes are needed for simplesamlphp_auth.

andypost’s picture

Status: Needs review » Needs work

I bet it need hasSession() on request before removal of flag

andypost’s picture

Berdir’s picture

Status: Needs work » Needs review

@andypost: How is that related to that issue? I'm just moving the existing calls around. Even if there s a problem (which I doubt, because you can't get there without having a session/being logged in), it is not caused by this?

andypost’s picture

+++ b/src/Masquerade.php
@@ -147,11 +147,14 @@ class Masquerade {
+    // Save previous account ID to session storage, set this before
+    // switching so that other modules can react to it, e.g. during
+    // hook_user_logout().

I think this flag should be differently named, because this session is not really in action, so $this->session->set('masquerade_logout', TRUE) to allow properly react on login/logout

Berdir’s picture

@andypost: Not sure I follow? I'm only changing when the existing flag is set, we can't change the name of that? I could set a *second* additional flag, but not quite sure what the point of that would be? we could set it somewhere else than the session, but that would likely make the code in the simplesamlphp_auth more complex as it would need a module exists check or so.

joelpittet’s picture

Version: 8.x-2.0-beta2 » 8.x-2.x-dev

@andypost any further thoughts on this patch? I'm going to give it a whirl to see if it helps.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Sorry for taking long to review, goona commit because it only rearranges code

  • andypost committed cc5c635 on 8.x-2.x authored by Berdir
    Issue #2975124 by Berdir, jnicola, andypost: Masquarade Saml...
andypost’s picture

Status: Reviewed & tested by the community » Fixed

Thanks a lot for clean solution!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.