Skip to content

Commit

Permalink
Additional little check to show how we're assumign the User object is…
Browse files Browse the repository at this point in the history
… the User entity
  • Loading branch information
weaverryan authored and wouterj committed Jul 29, 2015
1 parent af85d52 commit 9ad9daf
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cookbook/security/voters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ edit a particular object. Here's an example implementation::
// src/AppBundle/Security/Authorization/Voter/PostVoter.php
namespace AppBundle\Security\Authorization\Voter;

use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -133,6 +134,13 @@ edit a particular object. Here's an example implementation::
return VoterInterface::ACCESS_DENIED;
}

// double-check that the User object is the expected entity.
// It always will be, unless there is some misconfiguration of the
// security system.
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()
Expand Down

0 comments on commit 9ad9daf

Please sign in to comment.