在 symfony 2 中添加多个防火墙
Add multiples firewalls in symfony 2
我有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
当我尝试在 ShopAdminBundle
上进行身份验证时,ShopDesktopBundle
的身份验证工作正常,但出现错误:Unable to find the controller for path "/admin/login_check". The route is wrongly configured.
我认为问题出在我的文件 security.yml
中。你能帮我吗?提前致谢
首先改变防火墙的位置。 user_secured_area
适合所有路线,它永远不会命中 admin_secured_area
。我相信它会解决你的问题。
firewalls:
admin_secured_area:
pattern: ^/admin
...
user_secured_area:
pattern: ^/
...
我有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
当我尝试在 ShopAdminBundle
上进行身份验证时,ShopDesktopBundle
的身份验证工作正常,但出现错误:Unable to find the controller for path "/admin/login_check". The route is wrongly configured.
我认为问题出在我的文件 security.yml
中。你能帮我吗?提前致谢
首先改变防火墙的位置。 user_secured_area
适合所有路线,它永远不会命中 admin_secured_area
。我相信它会解决你的问题。
firewalls:
admin_secured_area:
pattern: ^/admin
...
user_secured_area:
pattern: ^/
...