Skip to content

fix security context example code #2838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2013
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
15 changes: 13 additions & 2 deletions components/security/firewall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ steps in the process of authenticating the user have been taken successfully,
you can ask the security context if the authenticated user has access to a
certain action or resource of the application::

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

// instance of Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
$authenticationManager = ...;

$securityContext = new SecurityContext();
// instance of Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
$accessDecisionManager = ...;

$securityContext = new SecurityContext($authenticationManager, $accessDecisionManager);

// ... authenticate the user

if (!$securityContext->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}

.. note::

Read the dedicated sections to learn more about :doc:`/components/security/authentication`
and :doc:`/components/security/authorization`.

.. _firewall:

A Firewall for HTTP Requests
Expand Down