I have a admin panel and I have defined a role for it ROLE_ADMIN. In my security.yml file I am using a pattern ^/admin/* so every thing under /admin requires ROLE_ADMIN. Now in frontend of my app I need to check user role and if role is ROLE_ADMIN render one file and otherwise render another file. This url does not fall under the pattern defined in security.yml.
So how do I check whether the user is admin or a normal user on the homepage which does not fall under the pattern defined in security.yml ?
Enable the firewall on the whole app using the
^/pattern, permit anonymous access and useaccess_controlto restrict access:As @itsmequinn suggested, use the
isGranted()method of the security context:In Symfony 2.6,
security.contexthas been split into two separate services. Hence you need to use thesecurity.authorization_checkerservice to solve the problem: