I have been following this tutorial from the Symfony Book to manage my users.
Now, I would like to set a flash message after the login has succeeded OR if somebody attempts to access a forbidden area.
What I understand is that authentication and authorization are not managed inside controllers. As a consequence, I do not know where to put my code to display a simple "Sorry, you are not connected" message.
It will take some time and some coding just to display a simple message. If you want to do it by Symfony way you should look at this security configuration first, especially these ones:
entry_point
(under firewall) - which usually redirects users to login page whenever they try to access the secured pages. You can set flash messages here.success_handler
under form_login
(if you're using it) to show your successful login messagesuccess_handler
under logout
to show your logout message Some references: