Skip to content

Commit 2fda262

Browse files
committed
minor #18033 [Security] Add tip for using new isGrantedForUser() function (natewiebe13)
This PR was merged into the 7.3 branch. Discussion ---------- [Security] Add tip for using new isGrantedForUser() function Adds tip for using new `isGrantedForUser()` function from symfony/symfony#48142 Commits ------- c196b44 Add tip for using new isGrantedForUser() function
2 parents 9b65586 + c196b44 commit 2fda262

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

security.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,18 @@ want to include extra details only for users that have a ``ROLE_SALES_ADMIN`` ro
25962596
// ...
25972597
}
25982598
2599+
.. tip::
2600+
2601+
Using ``isGranted()`` checks authorization against the currently logged in user. If you need to check
2602+
against a user that is not the one logged in or if checking authorization when the user session is not
2603+
available in a CLI context (example: message queue, cronjob) ``isGrantedForUser()`` can be used to set the
2604+
target user explicitly.
2605+
2606+
.. versionadded:: 7.3
2607+
2608+
The :method:`Symfony\\Bundle\\SecurityBundle\\Security::isGrantedForUser`
2609+
method was introduced in Symfony 7.3.
2610+
25992611
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
26002612
Symfony will automatically pass the ``security.helper`` to your service
26012613
thanks to autowiring and the ``Security`` type-hint.

0 commit comments

Comments
 (0)