Skip to content

Commit 2874a67

Browse files
committed
minor #5476 [Cookbook][Security] some additional tweaks for the voter cookbook (xabbuh)
This PR was merged into the 2.6 branch. Discussion ---------- [Cookbook][Security] some additional tweaks for the voter cookbook | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.6+ | Fixed tickets | This applies the comments left by @wouterj in e46f02e. Commits ------- 10e022d some additional tweaks for the voter cookbook
2 parents e93c251 + 10e022d commit 2874a67

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

cookbook/security/voters.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ edit a particular object. Here's an example implementation:
105105
106106
break;
107107
case self::EDIT:
108-
// we assume that our data object has a method getOwner() to
109-
// get the current owner user entity for this data object
108+
// this assumes that the data object has a getOwner() method
109+
// to get the entity of the user who owns this data object
110110
if ($user->getId() === $post->getOwner()->getId()) {
111111
return true;
112112
}
@@ -218,9 +218,7 @@ from the authorization checker is called.
218218
219219
$authChecker = $this->get('security.authorization_checker');
220220
221-
if (false === $authChecker->isGranted('view', $post)) {
222-
throw $this->createAccessDeniedException('Unauthorized access!');
223-
}
221+
$this->denyAccessUnlessGranted('view', $post, 'Unauthorized access!');
224222
225223
return new Response('<h1>'.$post->getName().'</h1>');
226224
}

0 commit comments

Comments
 (0)