Skip to content

[Security] Add tip for using new isGrantedForUser() function #18033

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 1 commit into from
Jan 3, 2025
Merged
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
12 changes: 12 additions & 0 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,18 @@ want to include extra details only for users that have a ``ROLE_SALES_ADMIN`` ro
// ...
}

.. tip::

Using ``isGranted()`` checks authorization against the currently logged in user. If you need to check
against a user that is not the one logged in or if checking authorization when the user session is not
available in a CLI context (example: message queue, cronjob) ``isGrantedForUser()`` can be used to set the
target user explicitly.

.. versionadded:: 7.3

The :method:`Symfony\\Bundle\\SecurityBundle\\Security::isGrantedForUser`
method was introduced in Symfony 7.3.

If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
Symfony will automatically pass the ``security.helper`` to your service
thanks to autowiring and the ``Security`` type-hint.
Expand Down
Loading