From 6be68fd84539dc5cb99caa2946e101ff02db4c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 28 Sep 2015 09:38:38 +0200 Subject: [PATCH] [TwigBridge] is_granted no longer raise an exception if the token storage is empty --- src/Symfony/Bridge/Twig/Extension/SecurityExtension.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php index b13d7c0f85..fa5fae2e77 100644 --- a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php @@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\Security\Acl\Voter\FieldVote; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; /** * SecurityExtension exposes security context features. @@ -38,7 +39,11 @@ class SecurityExtension extends \Twig_Extension $object = new FieldVote($object, $field); } - return $this->securityChecker->isGranted($role, $object); + try { + return $this->securityChecker->isGranted($role, $object); + } catch (AuthenticationCredentialsNotFoundException $e) { + return false; + } } /**