2

I am trying to configure separate login for admin user in Symfony application. These are my settings:

config.yml

 fos_user:
     db_driver: orm
     firewall_name: main
     user_class: CoreBundle\Entity\User
     service:
             user_manager: pugx_user_manager
     resetting:
             form:
                  type: APIBundle\Form\ResettingFormType

routing.yml

 admin_login:
     path:  /admin/login
     defaults: { _controller: FOSUserBundle:Security:login }

 admin_check:
     path:  /admin/login_check
     defaults: { _controller: FOSUserBundle:Security:check }

 admin_logout:
     path:  /admin/logout
     defaults: { _controller: FOSUserBundle:Security:logout }

security.yml

firewalls:
   admin:
        pattern:            ^/admin
        form_login:
            provider:       fos_userbundle
            login_path:     admin_login
            check_path:     admin_check
            csrf_token_generator: security.csrf.token_manager
            default_target_path: /admin/
        logout:
            path:           /admin/logout
            target:         /admin/login
        anonymous:    true

   main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
        logout:
            target:   /login
        anonymous:    true

access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }

        - { path: ^/admin/, role: ROLE_ADMIN }

When I try to login to admin panel on http://localhost/admin/login I am redirected to http://localhost/login_check and get following error

You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.

blahblah
  • 1,010
  • 15
  • 40
  • can you post the configuration of the main firewall? In the `security.yml`, Under `firewalls` the key `main` (like `admin`) – Matteo Oct 12 '16 at 13:21
  • @Matteo I updated my code – blahblah Oct 12 '16 at 13:22
  • try changing the pattern of the admin firewall as `pattern: ^/admin` – Matteo Oct 12 '16 at 13:26
  • check_path wants the path, not the route name (the word "path" is meant to mean something) So put in `/admin/login_check` (and fix the login path as well) and it should work. – Koalabaerchen Oct 12 '16 at 15:59
  • @Koalabaerchen i did what you said. Something really weird happened. I was redirected to blank 'Welcome' page on `http://localhost/admin/login` – blahblah Oct 12 '16 at 16:25
  • @blahblah Thaaaaaat doesn't sound right. What happens if you just go to /admin/login? Same welcome page? Are you sure you don't overwrite the "admin_login" route somewhere in your routings? Check router:debug console command. (or whas it debug:router?) Those route names need to be unique. – Koalabaerchen Oct 12 '16 at 16:59
  • @Koalabaerchen yes, same blank page. I overwrite admin_login only in routing.yml. – blahblah Oct 13 '16 at 09:15
  • @blahblah check with the symfony toolbar which controller/view is being called. I think you broke something inside fosuserbundle – Koalabaerchen Oct 13 '16 at 09:46
  • @Koalabaerchen toolbar says admin_login route is called with 200 status. Controller: FOS\UserBundle\Controller\SecurityController::loginAction – blahblah Oct 13 '16 at 09:47
  • @blahblah did you overwrite the templates? – Koalabaerchen Oct 13 '16 at 10:24
  • @Koalabaerchen no, did I suppose to do that? – blahblah Oct 13 '16 at 13:31
  • @blahblah no. You should open a new question with your routing and settings to figure that out – Koalabaerchen Oct 14 '16 at 07:50

0 Answers0