我有一个symfony网站,它是为2.0.9版本开发的。我试图升级到最新版本(2.4.2),但现在每次我尝试甚至访问登录页面,我得到一个重定向循环。日志显示如下:
[2014-03-16 12:39:10] security.INFO: Authentication exception occurred; redirecting to authentication entry point (A Token was not found in the SecurityContext.) [] []
这是我的安全。yml
security:
encoders:
Starski'FrontBundle'Entity'User:
algorithm: sha1
iterations: 1
encode-as-base64: false
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
main:
entity: { class: Starski'FrontBundle'Entity'User, property: mail }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
index:
pattern: ^/
form_login:
login_path: /login
check_path: /auth
default_target_path: /index
failure_handler: starski.security.handler
success_handler: starski.security.handler
access_control:
- { path: ^/demo/secured/hello/admin/, roles: ROLE_ADMIN }
有人知道为什么会这样吗?
您可以检查以下内容:
-
您的login_path在防火墙后面。这将永远不会像这样进行身份验证。
将此添加到访问控制:- { path: ^(.*)/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
-
login_path
、check_path
和default_target_path
应正确定义路由名,而不是绝对url。 -
您定义了一个从未使用过的提供商('main')。
尝试添加provider: main
到您的表单登录认证方法
阅读要点:
http://symfony.com/doc/current/book/security.html#book-security-common-pitfallshttp://symfony.com/doc/current/reference/configuration/security.html the-login-form-and-process