-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Updated documentation regarding the SecurityContext split #4188
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ Authorization | |
When any of the authentication providers (see :ref:`authentication_providers`) | ||
has verified the still-unauthenticated token, an authenticated token will | ||
be returned. The authentication listener should set this token directly | ||
in the :class:`Symfony\\Component\\Security\\Core\\SecurityContextInterface` | ||
using its :method:`Symfony\\Component\\Security\\Core\\SecurityContextInterface::setToken` | ||
in the :class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added one just below the list |
||
using its :method:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface::setToken` | ||
method. | ||
|
||
From then on, the user is authenticated, i.e. identified. Now, other parts | ||
|
@@ -29,6 +29,11 @@ An authorization decision will always be based on a few things: | |
Any object for which access control needs to be checked, like | ||
an article or a comment object. | ||
|
||
.. versionadded:: 2.6 | ||
The ``TokenStorageInterface`` was introduced in Symfony 2.6. Prior, you | ||
had to use the ``setToken()`` method of the | ||
:class:`Symfony\\Component\\Security\\Core\\SecurityContextInterface`. | ||
|
||
.. _components-security-access-decision-manager: | ||
|
||
Access Decision Manager | ||
|
@@ -227,23 +232,24 @@ are required for the current user to get access to the application:: | |
$authenticationManager | ||
); | ||
|
||
Security Context | ||
~~~~~~~~~~~~~~~~ | ||
Authorization Checker | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The access decision manager is also available to other parts of the application | ||
via the :method:`Symfony\\Component\\Security\\Core\\SecurityContext::isGranted` | ||
method of the :class:`Symfony\\Component\\Security\\Core\\SecurityContext`. | ||
via the :method:`Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker::isGranted` | ||
method of the :class:`Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker`. | ||
A call to this method will directly delegate the question to the access | ||
decision manager:: | ||
|
||
use Symfony\Component\Security\SecurityContext; | ||
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
|
||
$securityContext = new SecurityContext( | ||
$authorizationChecker = new AuthorizationChecker( | ||
$tokenStorage, | ||
$authenticationManager, | ||
$accessDecisionManager | ||
); | ||
|
||
if (!$securityContext->isGranted('ROLE_ADMIN')) { | ||
if (!$authorizationChecker->isGranted('ROLE_ADMIN')) { | ||
throw new AccessDeniedException(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean with
security context
? And I don't get the location of this directiveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It refers to the app.security available as twig global, maybe I should add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I would use "app.security global" (and PHP's alternative) instead of "security context".
Btw, don't forget to update reference/twig_reference.rst in that case.