There are many code snippets how to check if authenticated user is authorized to request a resource. But i cannot find a example to check if the user is authenticated at all.
I've got a kernel request listener, in which i'm trying to check if a user is authenticated, using this code:
if (TRUE === $this->get('security.authorization_checker')->isGranted('ROLE_USER'))
{
//doing stuff
}
I get the following error message:
AuthenticationCredentialsNotFoundException in classes.php line 5307:
The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.
I guess, this is because the user is not logged in at all, and therefore doesn't have any authentication token.
So my question is: how do i, in a symfony controller, check if a user is authenticated before i check if he is authorized?