You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
2355
2357
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2356
-
use Symfony\Component\Security\Core\Authentication\User\UserInterface;
2357
2358
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
2358
2359
2359
2360
class PostVoter extends Voter
@@ -2364,14 +2365,21 @@ anonymous users access by checking if there is no user set on the token::
2364
2365
{
2365
2366
// ...
2366
2367
2367
-
if (!$token->getUser() instanceof UserInterface) {
2368
+
if ($token instanceof NullToken) {
2368
2369
// the user is not authenticated, e.g. only allow them to
2369
2370
// see public posts
2370
2371
return $subject->isPublic();
2371
2372
}
2372
2373
}
2373
2374
}
2374
2375
2376
+
.. caution::
2377
+
2378
+
:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\NullToken` is only available in voters
2379
+
(because :method:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface::vote` can't receive a null token). Outside of voters (controllers, other services...) there is no token in the
0 commit comments