Skip to content

Commit fa3936b

Browse files
Nebojša Kamberxabbuh
Nebojša Kamber
authored andcommitted
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
1 parent 58ca209 commit fa3936b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cookbook/security/impersonating_user.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ over the user's roles until you find one that a ``SwitchUserRole`` object::
9393
use Symfony\Component\Security\Core\Role\SwitchUserRole;
9494

9595
$authChecker = $this->get('security.authorization_checker');
96+
$tokenStorage = $this->get('security.token_storage');
9697

9798
if ($authChecker->isGranted('ROLE_PREVIOUS_ADMIN')) {
98-
foreach ($authChecker->getToken()->getRoles() as $role) {
99+
foreach ($tokenStorage->getToken()->getRoles() as $role) {
99100
if ($role instanceof SwitchUserRole) {
100101
$impersonatingUser = $role->getSource()->getUser();
101102
break;

0 commit comments

Comments
 (0)