From 92039507d4e405010e34a476de73aa7aef238786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Neboj=C5=A1a=20Kamber?= Date: Sat, 27 Jun 2015 13:21:43 +0200 Subject: [PATCH] Fixing "Undefined method" error on Symfony 2.7 The code example tries to call `getToken` on `Symfony\Component\Security\Core\Authorization\AuthorizationChecker`, which fails on Symfony 2.7 because the method is undefined. This change utilizes the TokenStorage class, introduced in Symfony 2.6 --- cookbook/security/impersonating_user.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/security/impersonating_user.rst b/cookbook/security/impersonating_user.rst index f9003fd9b93..2e6775b6c22 100644 --- a/cookbook/security/impersonating_user.rst +++ b/cookbook/security/impersonating_user.rst @@ -93,9 +93,10 @@ over the user's roles until you find one that a ``SwitchUserRole`` object:: use Symfony\Component\Security\Core\Role\SwitchUserRole; $authChecker = $this->get('security.authorization_checker'); + $tokenStorage = $this->get('security.token_storage'); if ($authChecker->isGranted('ROLE_PREVIOUS_ADMIN')) { - foreach ($authChecker->getToken()->getRoles() as $role) { + foreach ($tokenStorage->getToken()->getRoles() as $role) { if ($role instanceof SwitchUserRole) { $impersonatingUser = $role->getSource()->getUser(); break;