symfony - How to restrict acces to login form if user is authenticated? -


i used basic login form in symfony2 , works ( without fosuserbundle ). how restrict acces if user authenticated ?

if ($this->get('security.context')->isgranted('role_admin')) { } 

the code above not work because login route not under firewall... , throw :

the security context contains no authentication token. 1 possible reason may there no firewall configured url.

how solve ?

as said, login url must under firewall if want have access token/authenticated user. possible allowing anonymous access , proper access control rules.

firewalls:     main:         pattern: ^/         # firewall settings         anonymous:    true  access_control:     - { path: ^/$, role: is_authenticated_anonymously }     - { path: ^/login$, role: is_authenticated_anonymously }     - { path: ^/register, role: is_authenticated_anonymously }     - { path: ^/, role: role_user } 

Comments