Al Bennett
Al Bennett

Reputation: 428

Showing required roles in a Symfony 2.1 403 forbidden page

I have a Symfony 2.1 application that has various access controlled areas. My set up includes an administrative area for users to manage their accounts, another area for company admin users to manage their company accounts and backends for us and the office staff.

All these different users have defined roles, ROLE_ADMIN, ROLE_COMPANY_ADMIN etc. The firewalls set up in my security.yml work fine for handling these different cases, however when a user accesses a page without the required role then get a generic 403 forbidden page.

I would like to have a custom page that has different content depending on the required role that the user is missing. I.e., you can't access this page because you're not an admin|company admin.

I need to retrieve the required roles of the route that has lead to the exception, I can then compare that against the user. Is there a good way to do this?

Many thanks in advance, Al

Upvotes: 2

Views: 685

Answers (1)

stedekay
stedekay

Reputation: 497

You can add a custom access denied url and implement your own controller.

A good example is posted here: http://michelsalib.com/2011/03/31/advance-customization-of-the-403-error-page-in-symfony2/

Upvotes: 1

Related Questions