Skip to content

Commit 9230ea7

Browse files
committed
use access decision manager to control which token to vote on
1 parent 1b363c4 commit 9230ea7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

security/voters.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,33 +222,33 @@ Checking for Roles inside a Voter
222222
---------------------------------
223223

224224
What if you want to call ``isGranted()`` from *inside* your voter - e.g. you want
225-
to see if the current user has ``ROLE_SUPER_ADMIN``. That's possible by injecting
226-
the :class:`Symfony\\Component\\Security\\Core\\Security`
227-
into your voter. You can use this to, for example, *always* allow access to a user
225+
to see if the current user has ``ROLE_SUPER_ADMIN``. That's possible by using an
226+
:class:`access decision manager <Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface>`
227+
inside your voter. You can use this to, for example, *always* allow access to a user
228228
with ``ROLE_SUPER_ADMIN``::
229229

230230
// src/Security/PostVoter.php
231231

232232
// ...
233-
use Symfony\Component\Security\Core\Security;
233+
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
234234

235235
class PostVoter extends Voter
236236
{
237237
// ...
238238

239-
private $security;
239+
private $accessDecisionManager;
240240

241-
public function __construct(Security $security)
241+
public function __construct(AccessDecisionManagerInterface $accessDecisionManager)
242242
{
243-
$this->security = $security;
243+
$this->accessDecisionManager = $accessDecisionManager;
244244
}
245245

246246
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
247247
{
248248
// ...
249249

250250
// ROLE_SUPER_ADMIN can do anything! The power!
251-
if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
251+
if ($this->accessDecisionManager->isGranted($token, ['ROLE_SUPER_ADMIN'])) {
252252
return true;
253253
}
254254

0 commit comments

Comments
 (0)