在symfony 2中添加多个防火墙

时间:2015-07-16 11:26:25

标签: php symfony symfony-forms symfony-2.1 symfony-2.3

我有2个捆绑包,路由文件app/config/routing是:

shop_admin:
    resource: "@ShopAdminBundle/Resources/config/routing.yml"
    prefix:   /admin

shop_desktop:
    resource: "@ShopDesktopBundle/Resources/config/routing.yml"
    prefix:   /

ShopDesktopBundle的路由文件是:

login:
   pattern:   /login
   defaults:  { _controller: ShopDesktopBundle:User:login }

login_check:
   pattern:   /login_check

ShopAdminBundle的路由文件是:

admin_login:
   path:   /login
   defaults:  { _controller: ShopAdminBundle:Login:login }

admin_login_check:
   path:   /login_check

security.yml

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    user_secured_area:
        pattern:    ^/
        form_login:
            login_path:  login
            check_path:  login_check
            username_parameter: _username
            password_parameter: _password
        logout:
            invalidate_session: true
            path:   shop_logout_user
            target: /
        anonymous: true
    admin_secured_area:
        pattern: ^/admin
        form_login:
            login_path: /admin/login
            check_path: /admin/login_check
            username_parameter: _username
            password_parameter: _password
        anonymous: true

当{I}尝试在ShopDesktopBundle上进行身份验证时,ShopAdminBundle的身份验证工作正常。我收到错误:Unable to find the controller for path "/admin/login_check". The route is wrongly configured. 我认为问题出在我的文件security.yml中。你能帮我吗? Thx提前

1 个答案:

答案 0 :(得分:2)

首先改变防火墙的位置。 user_secured_area适合所有路线,而且永远不会发送admin_secured_area。我相信它会解决你的问题。

firewalls:
    admin_secured_area:
       pattern: ^/admin
       ...
    user_secured_area:
        pattern: ^/
        ...