0

i have two roles in my application : user and Admin i configure my access control that , the user cannot access to my page : hello , only the admin have this access: i used this code in my security.yml

access_control:
   - { path: ^/hello/, role: ROLE_ADMIN }

when a simple user will connect in the root : hello.I have the error : access denied:

how can i configure my app , that will redirect the simple user to the main page (or connection page) when he will want to access to the root hello.

Thank you for your help

Marooweb
  • 476
  • 3
  • 8
  • 21

2 Answers2

1

Maybe you should create kernel.listener.accessDenied? Using Symfony2's AccessDeniedHandlerInterface

Community
  • 1
  • 1
  • to give a better answer (and my +1 on this) you have to report here the code (also because the linked-answers are strongly discouraged) – gp_sflover Nov 14 '14 at 11:55
  • I agree on the linked-answer comment; I have tried to follow this link and its status is 404. Thus no one is able to try and consult the code. – thoroc Jan 07 '16 at 12:58
  • I think stackoverflow links are allowed, here you are: http://stackoverflow.com/questions/9166930/using-symfony2s-accessdeniedhandlerinterface – Karol Wojciechowski Jan 08 '16 at 09:41
  • @KarolWojciechowski edit your answer above, so I can remove the down vote. ;) – thoroc Jan 11 '16 at 09:41
0

Within the controller that handles /hello route, add the logic to redirect the user based on the role. You may implement this by adding the following lines of code within that controller

    if ($this->get('security.context')->isGranted('ROLE_USER')) {
        return $this->redirect($this->generateUrl('Route for Main page'));
    }
Praveesh
  • 1,257
  • 1
  • 10
  • 23
  • thank you for your response , in my case , i'm using fosuserbundle , where should i add this code , in which controller ? SecurityController ??? – Marooweb Nov 14 '14 at 12:32