Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Add tip for using new isGrantedForUser() function
  • Loading branch information
Nate Wiebe authored and natewiebe13 committed Dec 17, 2024
commit c196b447547b28048a9f1d5849f6964e982933ad
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