Replace undefined method setAccount

Created on 10 January 2022, almost 3 years ago
Updated 27 June 2023, over 1 year ago

Problem/Motivation

When logging out of a SAML-based session, we receive the following error:
Error: Call to undefined method Drupal\user\Entity\User::setAccount() in /mnt/www/html/hcaintranetstg/docroot/modules/contrib/simplesamlphp_auth/simplesamlphp_auth.module on line 68 #0 [internal function]: simplesamlphp_auth_user_logout(Object(Drupal\user\Entity\User))
#1 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('simplesamlphp_a...', Array)
#2 /mnt/www/html/hcaintranetstg/docroot/modules/contrib/masquerade/src/Masquerade.php(114): Drupal\Core\Extension\ModuleHandler->invokeAll('user_logout', Array)
#3 /mnt/www/html/hcaintranetstg/docroot/modules/contrib/masquerade/src/Masquerade.php(156): Drupal\masquerade\Masquerade->switchUser(Object(Drupal\user\Entity\User))
#4 /mnt/www/html/hcaintranetstg/docroot/modules/contrib/masquerade/src/Controller/SwitchController.php(82): Drupal\masquerade\Masquerade->switchTo(Object(Drupal\user\Entity\User))
#5 [internal function]: Drupal\masquerade\Controller\SwitchController->switchTo(Object(Drupal\user\Entity\User), Object(Symfony\Component\HttpFoundation\Request))
#6 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#7 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#9 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#10 /mnt/www/html/hcaintranetstg/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /mnt/www/html/hcaintranetstg/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#12 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /mnt/www/html/hcaintranetstg/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /mnt/www/html/hcaintranetstg/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /mnt/www/html/hcaintranetstg/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /mnt/www/html/hcaintranetstg/docroot/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /mnt/www/html/hcaintranetstg/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#21 {main} request_id="v-16054034-7224-11ec-a1c9-5720c7fc7bfb"

Steps to reproduce

In the toolbar, click Logout. Or, go to /user/logout.

Proposed resolution

The attached patch replaces the code in the simplesamlphp_auth_user_logout function, which originally copied its code from the user_logout function in /core/modules/user/user.module, with updated code from the same function.

It also includes a merge request submitted by Kobe Wright in https://www.drupal.org/project/simplesamlphp_auth/issues/2124117 β†’ (#18/#19) to fix users being unable to masquerade, which is what I was originally trying to fix when I found this issue.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jsutta United States

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡¬Bulgaria pfrenssen Sofia

    Yeah we cannot call $account->setAccount() because this method doesn't exist on AccountInterface. This is a method that only exists on AccountProxyInterface.

    Here is a more straightforward fix that copies the actual approach from user_logout() without a risk of invoking an endless loop.

    I did not test this patch, but I am guessing it will solve the problem.

  • First commit to issue fork.
  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Not currently mergeable.
  • @elber opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    21 pass
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    21 pass
  • πŸ‡§πŸ‡·Brazil elber Brazil

    HI I Just added the previously patch in the MR please revise.

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    I just tried patch #8 and it completely broke Masquerade! Before this patch I was able to masquerade as a non-admin and only got the error when trying to do as admin (user 1).

    I'm currently on Drupal core 9.5.11, simpleSAMLphp Authentication 8.x-3.3, and Masquerade 8.x-2.0-rc4.

  • Patch #2 fixes the error for me.

    • Drupal Core 10.2.5
    • Masquerade 2.0@beta
    • simplesamlphp_auth 4.0
Production build 0.71.5 2024