Skip to content

Commit 08f938c

Browse files
pathmissingweaverryan
authored andcommitted
Use preferred way of retrieving authenticated user
Promote the preferred way of retrieving the object of the authenticated user
1 parent 2b6d47f commit 08f938c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

security.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -993,19 +993,20 @@ shown above.
993993
3) Retrieving the User Object
994994
-----------------------------
995995

996-
After authentication, the ``User`` object of the current user can be accessed either
997-
via the ``security.token_storage`` service or via type-hinting the ``UserInterface``
998-
as an argument. From inside a controller, this will look like::
996+
After authentication, the ``User`` object of the current user can be accessed
997+
via the ``security.token_storage`` service. From inside a controller, this will
998+
look like::
999999

10001000
use Symfony\Component\Security\Core\User\UserInterface;
10011001

1002-
public function indexAction(UserInterface $user)
1002+
public function indexAction()
10031003
{
10041004
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
10051005
throw $this->createAccessDeniedException();
10061006
}
10071007

1008-
// type-hinting the UserInterface like above is a shortcut for this
1008+
// This is the recommended way but type-hinting the
1009+
// UserInterface as a method argument also works
10091010
$user = $this->get('security.token_storage')->getToken()->getUser();
10101011
}
10111012

0 commit comments

Comments
 (0)