Skip to content

[Security] Removed deprecated example about SecurityContext #4713

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

Closed
Closed
Show file tree
Hide file tree
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
26 changes: 15 additions & 11 deletions components/security/firewall.rst
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
.. index::
single: Security, Firewall

The Firewall and Security Context
=================================
The Firewall and Authorization
==============================

Central to the Security component is the security context, which is an instance
of :class:`Symfony\\Component\\Security\\Core\\SecurityContextInterface`. When all
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
Central to the Security component is authorization. This is handled by an instance
of :class:`Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface`.
When all steps in the process of authenticating the user have been taken successfully,
you can ask the authorization checker if the authenticated user has access to a
certain action or resource of the application::

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

// instance of Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
$tokenStorage = ...;

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

// instance of Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
$accessDecisionManager = ...;

$securityContext = new SecurityContext(
$authorizationChecker = new AuthorizationChecker(
$tokenStorage,
$authenticationManager,
$accessDecisionManager
);

// ... authenticate the user

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

.. versionadded:: 2.6
As of Symfony 2.6, the :class:`Symfony\\Component\\Security\\Core\\SecurityContext` class was split
in the :class:`Symfony\\Component\\Security\\Core\\Authentication\\Authorization\\AuthorizationChecker` and
As of Symfony 2.6, the :class:`Symfony\\Component\\Security\\Core\\SecurityContext` class was split
in the :class:`Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker` and
:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorage` classes.

.. note::
Expand Down
2 changes: 1 addition & 1 deletion cookbook/profiler/matchers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ something like::
}

.. versionadded:: 2.6
The :class:`Symfony\\Component\\Security\\Core\\Authentication\\Authorization\\AuthorizationCheckerInterface` was
The :class:`Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface` was
introduced in Symfony 2.6. Prior, you had to use the ``isGranted`` method of
:class:`Symfony\\Component\\Security\\Core\\SecurityContextInterface`.

Expand Down