From f8dd30f1f1537ddff71e7f08db1ac3fd31b13311 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 25 May 2015 19:11:29 -0400 Subject: [PATCH] Additional little check to show how we're assumign the User object is the User entity --- cookbook/security/voters_data_permission.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cookbook/security/voters_data_permission.rst b/cookbook/security/voters_data_permission.rst index 2376d393b53..c57ac88c2f0 100644 --- a/cookbook/security/voters_data_permission.rst +++ b/cookbook/security/voters_data_permission.rst @@ -62,6 +62,7 @@ edit a particular object. Here's an example implementation:: use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\User\UserInterface; + use AppBundle\Entity\User; class PostVoter implements VoterInterface { @@ -118,6 +119,13 @@ edit a particular object. Here's an example implementation:: return VoterInterface::ACCESS_DENIED; } + // double-check that our User object is the entity we expect. + // It always will be, unless we've configured our security system + // in some other way. + if (!$user instanceof User) { + throw new \LogicException('The user is somehow not our User class!'); + } + switch($attribute) { case self::VIEW: // the data object could have for example a method isPrivate()