Replace undefined method setAccount

Created on 10 January 2022, over 3 years ago
Updated 27 June 2023, almost 2 years 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.

Production build 0.71.5 2024