Skip to content

Commit 9dafd45

Browse files
committed
bug #5450 Fixing "Undefined method" error in code example (nebkam)
This PR was submitted for the 2.7 branch but it was merged into the 2.6 branch instead (closes #5450). Discussion ---------- Fixing "Undefined method" error in code example | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.7 | Fixed tickets | - 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 Commits ------- fa3936b Fixing "Undefined method" error on Symfony 2.7
2 parents 58ca209 + fa3936b commit 9dafd45

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: cookbook/security/impersonating_user.rst

+2-1
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)