#[CurrentUser]: Cannot autowire argument $user of "App\Controller\FooController::method()": it references class "App\Entity\User" but no such service exists
if user isn't logged in
#45257
Labels
Symfony version(s) affected
5.4, 6.0
Description
If I try to autowire \App\Entity\User to a non-nullable variable using
#[CurrentUser]
attribute in a controller method and I'm not logged in, Symfony crashes with a RuntimeException$user references class "App\Entity\User" but no such service exists
.It works like a charm if I logged in or the variable is nullable.
I'd expect it throws \Symfony\Component\Security\Core\Exception\AccessDeniedException instead, because if a programmer requests a non-null $user for a method then I think there's is an implication this method is accessible only if a user is logged in (as if there's a
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
line in the beginning).How to reproduce
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: