Skip to content

Commit a4ec9e9

Browse files
committed
minor #5580 Additional User check in voter class (weaverryan)
This PR was merged into the 2.3 branch. Discussion ---------- Additional User check in voter class Finishes #5317 | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3+ | Fixed tickets | #5279 Commits ------- 9ad9daf Additional little check to show how we're assumign the User object is the User entity
2 parents af85d52 + 9ad9daf commit a4ec9e9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cookbook/security/voters.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ edit a particular object. Here's an example implementation::
7777
// src/AppBundle/Security/Authorization/Voter/PostVoter.php
7878
namespace AppBundle\Security\Authorization\Voter;
7979

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

137+
// double-check that the User object is the expected entity.
138+
// It always will be, unless there is some misconfiguration of the
139+
// security system.
140+
if (!$user instanceof User) {
141+
throw new \LogicException('The user is somehow not our User class!');
142+
}
143+
136144
switch($attribute) {
137145
case self::VIEW:
138146
// the data object could have for example a method isPrivate()

0 commit comments

Comments
 (0)