Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions best_practices/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ more advanced use-case, you can always do the same security check in PHP:

.. code-block:: php

use Symfony\Component\Security\Core\Exception\AccessDeniedException;

// ...

/**
* @Route("/{id}/edit", name="admin_post_edit")
*/
Expand All @@ -238,7 +234,16 @@ more advanced use-case, you can always do the same security check in PHP:
}

if (!$post->isAuthor($this->getUser())) {
throw new AccessDeniedException();
$this->denyAccessUnlessGranted('edit', $post);

// or without the shortcut:
//
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// ...
//
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
// throw $this->createAccessDeniedException();
// }
}

// ...
Expand Down Expand Up @@ -327,10 +332,6 @@ via the even easier shortcut in a controller:

.. code-block:: php

use Symfony\Component\Security\Core\Exception\AccessDeniedException;

// ...

/**
* @Route("/{id}/edit", name="admin_post_edit")
*/
Expand All @@ -342,6 +343,9 @@ via the even easier shortcut in a controller:

// or without the shortcut:
//
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// ...
//
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
// throw $this->createAccessDeniedException();
// }
Expand Down