Skip to content

Commit

Permalink
Documenting createAccessDeniedException() method
Browse files Browse the repository at this point in the history
Updating documentation to reflect the changes added in symfony/symfony#9405.
  • Loading branch information
klaussilveira committed Jan 17, 2014
1 parent 6db5f23 commit 6fd3f93
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions book/security.rst
Expand Up @@ -1072,19 +1072,21 @@ fine-grained enough in certain cases. When necessary, you can easily force
authorization from inside a controller::

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

public function helloAction($name)
{
if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
throw $this->createAccessDeniedException('Unable to access this page!');
}

// ...
}

.. _book-security-securing-controller-annotations:

The ``createAccessDeniedException()`` method creates a special ``AccessDeniedException``
object, which ultimately triggers a 403 HTTP response inside Symfony.

Thanks to the SensioFrameworkExtraBundle, you can also secure your controller using annotations::

// ...
Expand Down

0 comments on commit 6fd3f93

Please sign in to comment.