Symfony2 身份验证“login_check"找不到路径
问题说明
我是 Symfony2 的新手,我正在尝试创建一个基本的注册 登录系统.因此,在 Symfony2 文档的帮助下,我创建了这个 security.yml:
I'm new to Symfony2 and I'm trying to create a basic registration login system. So, with the help of the Symfony2 documentation I created this security.yml:
security:
encoders:
TestCompany\InternetBundle\Entity\Member:
algorithm: sha1
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
providers:
administrators:
entity: { class: TestCompanyInternetBundle:Member, property: username }
firewalls:
admin_area:
pattern: ^/admin
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
我使用了这个路由:
login_check:
pattern: /login_check
login:
pattern: /login
defaults: { _controller: TestCompanyInternetBundle:Admin:login }
根据 http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form 我不需要为 login_check 路由实现控制器.然而,Symfony 将这个错误返回给我:
According to http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form I do NOT need to implement a controller for the login_check route. Yet, Symfony returns this error to me:
Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?
你有没有发现我在这里做错了什么?登录页面几乎是文档中使用的页面的精确副本.错误发生在页面上:http://localhost/SymfonyTest/web/app_dev.php/login_check
,这是我在使用登录表单后被发送到的页面.
Do you see anything I could have done wrong here? The login page is almost an exact copy of the one used in the documentation. The error occurs on the page: http://localhost/SymfonyTest/web/app_dev.php/login_check
, which is the page I get sent to after using the login form.
正确答案
http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form
确保 /login_check
位于防火墙后面.
Be sure /login_check
is behind a firewall.
因此,在您的示例中,您为安全区域指定了前缀/admin,因此您的登录检查路由也应具有该前缀,例如/admin/login_check
接下来,确保您的 check_path URL(例如/login_check)位于您用于表单登录的防火墙之后(在本例中,单个防火墙匹配所有 URL,包括/login_check).如果/login_check 与任何防火墙都不匹配,您将收到无法找到路径/login_check"的控制器异常.
Next, make sure that your check_path URL (e.g. /login_check) is behind the firewall you're using for your form login (in this example, the single firewall matches all URLs, including /login_check). If /login_check doesn't match any firewall, you'll receive a Unable to find the controller for path "/login_check" exception.
示例 security.yml
配置:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/
form_login:
login_path: /login
check_path: /login_check
logout:
path: /demo/secured/logout
target: /demo/
anonymous: ~
....
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tangjcfaf
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
使用c++17更新时出现G++编译器警告
it1352 06-18 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
复制文件夹/文件而不修改属性?
it1352 07-15 -
Android微调工具-删除当前选择
it1352 06-20