Skip to content

Commit 6501e95

Browse files
committed
fix security context example code
1 parent 4eeec12 commit 6501e95

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

components/security/firewall.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,28 @@ steps in the process of authenticating the user have been taken successfully,
1010
you can ask the security context if the authenticated user has access to a
1111
certain action or resource of the application::
1212

13-
use Symfony\Component\Security\SecurityContext;
13+
use Symfony\Component\Security\Core\SecurityContext;
1414
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
15+
16+
// instance of Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
17+
$authenticationManager = ...;
1518

16-
$securityContext = new SecurityContext();
19+
// instance of Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
20+
$accessDecisionManager = ...;
21+
22+
$securityContext = new SecurityContext($authenticationManager, $accessDecisionManager);
1723

1824
// ... authenticate the user
1925

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

30+
.. note::
31+
32+
Read the dedicated sections to learn more about :doc:`/components/security/authentication`
33+
and :doc:`/components/security/authorization`.
34+
2435
.. _firewall:
2536

2637
A Firewall for HTTP Requests

0 commit comments

Comments
 (0)