Skip to content

Added documentation for the priority access decision strategy #12956

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
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
10 changes: 8 additions & 2 deletions components/security/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ recognizes several strategies:
``unanimous``
only grant access if none of the voters has denied access;

``priority``
grants or denies access by the first voter that does not abstain;

.. versionadded:: 5.1

The priority version strategy was introduced in Symfony 5.1.

Usage of the available options in detail::

use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;

// instances of Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
$voters = [...];

// one of "affirmative", "consensus", "unanimous"
// one of "affirmative", "consensus", "unanimous", "priority"
$strategy = ...;

// whether or not to grant access when all voters abstain
Expand Down Expand Up @@ -258,4 +265,3 @@ decision manager::
if (!$authorizationChecker->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}

15 changes: 12 additions & 3 deletions security/voters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uses the authorization checker), or by

Ultimately, Symfony takes the responses from all voters and makes the final
decision (to allow or deny access to the resource) according to the strategy defined
in the application, which can be: affirmative, consensus or unanimous.
in the application, which can be: affirmative, consensus, unanimous or priority.

For more information take a look at
:ref:`the section about access decision managers <components-security-access-decision-manager>`.
Expand Down Expand Up @@ -262,7 +262,7 @@ checks if the user is a member of the site and a second one that checks if the u
is older than 18.

To handle these cases, the access decision manager uses an access decision
strategy. You can configure this to suit your needs. There are three
strategy. You can configure this to suit your needs. There are four
strategies available:

``affirmative`` (default)
Expand All @@ -274,7 +274,16 @@ strategies available:
``unanimous``
This only grants access if there is no voter denying access. If all voters
abstained from voting, the decision is based on the ``allow_if_all_abstain``
config option (which defaults to ``false``).
config option (which defaults to ``false``);

``priority``
This grants or denies access by the first voter that does not abstain,
based on their service priority;

.. versionadded:: 5.1

The priority version strategy was introduced in Symfony 5.1.


In the above scenario, both voters should grant access in order to grant access
to the user to read the post. In this case, the default strategy is no longer
Expand Down