Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e5fc6c

Browse filesBrowse files
committed
Merge branch '2.7'
* 2.7: removing duplicate key Updating one more reference of security.context that I missed in the merge [Security] Removed deprecated example about SecurityContext Use denyAccessUnlessGranted shortcut Use new security.authorization_checker service
2 parents cb6f846 + 2560851 commit 9e5fc6c
Copy full SHA for 9e5fc6c

File tree

Expand file treeCollapse file tree

5 files changed

+30
-24
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+30
-24
lines changed

‎best_practices/security.rst

Copy file name to clipboardExpand all lines: best_practices/security.rst
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ Authorization (i.e. Denying Access)
7575
Symfony gives you several ways to enforce authorization, including the ``access_control``
7676
configuration in :doc:`security.yml </reference/configuration/security>` the
7777
:ref:`@Security annotation <best-practices-security-annotation>` and using
78-
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.context``
78+
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.authorization_checker``
7979
service directly.
8080

8181
.. best-practice::
8282

8383
* For protecting broad URL patterns, use ``access_control``;
8484
* Whenever possible, use the ``@Security`` annotation;
85-
* Check security directly on the ``security.context`` service whenever
85+
* Check security directly on the ``security.authorization_checker`` service whenever
8686
you have a more complex situation.
8787

8888
There are also different ways to centralize your authorization logic, like
@@ -315,7 +315,7 @@ Now, you can use the voter with the ``@Security`` annotation:
315315
// ...
316316
}
317317
318-
You can also use this directly with the ``security.context`` service, or
318+
You can also use this directly with the ``security.authorization_checker`` service, or
319319
via the even easier shortcut in a controller:
320320

321321
.. code-block:: php
@@ -327,9 +327,13 @@ via the even easier shortcut in a controller:
327327
{
328328
$post = // query for the post ...
329329
330-
if (!$this->get('security.context')->isGranted('edit', $post)) {
331-
throw $this->createAccessDeniedException();
332-
}
330+
$this->denyAccessUnlessGranted('edit', $post);
331+
332+
// or without the shortcut:
333+
//
334+
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
335+
// throw $this->createAccessDeniedException();
336+
// }
333337
}
334338
335339
Learn More

‎book/security.rst

Copy file name to clipboardExpand all lines: book/security.rst
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,6 @@ key:
10611061

10621062
.. _book-security-logging-out:
10631063

1064-
.. _book-security-logging-out:
1065-
10661064
Logging Out
10671065
-----------
10681066

‎components/security/firewall.rst

Copy file name to clipboardExpand all lines: components/security/firewall.rst
+15-11Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
.. index::
22
single: Security, Firewall
33

4-
The Firewall and Security Context
5-
=================================
4+
The Firewall and Authorization
5+
==============================
66

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

13-
use Symfony\Component\Security\Core\SecurityContext;
13+
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
1414
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1515

16+
// instance of Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
17+
$tokenStorage = ...;
18+
1619
// instance of Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
1720
$authenticationManager = ...;
1821

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

22-
$securityContext = new SecurityContext(
25+
$authorizationChecker = new AuthorizationChecker(
26+
$tokenStorage,
2327
$authenticationManager,
2428
$accessDecisionManager
2529
);
2630

2731
// ... authenticate the user
2832

29-
if (!$securityContext->isGranted('ROLE_ADMIN')) {
33+
if (!$authorizationChecker->isGranted('ROLE_ADMIN')) {
3034
throw new AccessDeniedException();
3135
}
3236

3337
.. versionadded:: 2.6
34-
As of Symfony 2.6, the :class:`Symfony\\Component\\Security\\Core\\SecurityContext` class was split
35-
in the :class:`Symfony\\Component\\Security\\Core\\Authentication\\Authorization\\AuthorizationChecker` and
38+
As of Symfony 2.6, the :class:`Symfony\\Component\\Security\\Core\\SecurityContext` class was split
39+
in the :class:`Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker` and
3640
:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorage` classes.
3741

3842
.. note::

‎cookbook/expression/expressions.rst

Copy file name to clipboardExpand all lines: cookbook/expression/expressions.rst
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object::
3939

4040
public function indexAction()
4141
{
42-
if (!$this->get('security.context')->isGranted(new Expression(
42+
if (!$this->get('security.authorization_checker')->isGranted(new Expression(
4343
'"ROLE_ADMIN" in roles or (user and user.isSuperAdmin())'
4444
))) {
4545
throw $this->createAccessDeniedException();
@@ -99,10 +99,10 @@ Additionally, you have access to a number of functions inside the expression:
9999
use Symfony\Component\ExpressionLanguage\Expression;
100100
// ...
101101

102-
$sc = $this->get('security.context');
103-
$access1 = $sc->isGranted('IS_AUTHENTICATED_REMEMBERED');
102+
$ac = $this->get('security.authorization_checker');
103+
$access1 = $ac->isGranted('IS_AUTHENTICATED_REMEMBERED');
104104

105-
$access2 = $sc->isGranted(new Expression(
105+
$access2 = $ac->isGranted(new Expression(
106106
'is_remember_me() or is_fully_authenticated()'
107107
));
108108

‎cookbook/profiler/matchers.rst

Copy file name to clipboardExpand all lines: cookbook/profiler/matchers.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ something like::
9090
}
9191

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.