本文介绍了在 Symfony 2 中使用多个防火墙会导致 ERR_TOO_MANY_REDIRECTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 symfony 2.3.4 并且我尝试设置多个防火墙.但是现在每次我去/admin/login 时都会出现错误 ERR_TOO_MANY_REDIRECTS.这些是我的 routing.yml 和 security.yml 文件:

路由.yml

login_admin:模式:/管理员/登录/默认值:{ _controller: HerbanistAdminBundle:Security:login }login_check_admin:模式:/admin/login_check/登出_管理员:路径:/管理员/注销/登录_客户:模式:/客户/登录/默认值:{ _controller: HerbanistStoreBundle:Security:login }login_check_customer:模式:/客户/登录_检查/登出_客户:路径:/客户/注销/

security.yml

安全性:编码器:Symfony\Component\Security\Core\User\User: 明文role_hierarchy:ROLE_ADMIN:ROLE_USERROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]供应商:在记忆中:记忆:用户:用户:{ 密码:userpass,角色:['ROLE_USER']}管理员:{ 密码:管理员,角色:['ROLE_ADMIN']}防火墙:admin_secured_area:模式:^/管理员表单登录:检查路径:/admin/login_check登录路径:/管理员/登录always_use_default_target_path: 真default_target_path:/admin登出:路径:/管理员/注销目标:/管理员customer_secured_area:模式:^/客户表单登录:check_path:/customere/login_check登录路径:/客户/登录always_use_default_target_path: 真default_target_path:/customer登出:路径:/客户/注销目标:/客户访问控制:- { 路径:^/admin/login,角色:IS_AUTHENTICATED_ANONYMOUSLY }- { 路径:^/admin,角色:ROLE_ADMIN }- { 路径:^/客户,角色:ROLE_USER }

编辑

Profiler 中的调试消息:

DEBUG - 将事件kernel.request"通知给侦听器Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".调试 - 将事件kernel.request"通知给侦听器Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".调试 - 将事件kernel.request"通知给侦听器Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".调试 - 将事件kernel.request"通知给侦听器Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".信息 - 匹配路由login_admin"(参数:_controller":Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction",path":/admin/login/",permanent":true","scheme": "null", "httpPort": "80", "httpsPort": "443", "_route": "login_admin")调试 - 将事件kernel.request"通知给侦听器Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".调试 - 将事件kernel.request"通知给侦听器Symfony\Component\Security\Http\Firewall::onKernelRequest".调试 - 将事件kernel.exception"通知给侦听器Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException".INFO - 发生身份验证异常;重定向到身份验证入口点(在 SecurityContext 中找不到令牌.)DEBUG - 调用身份验证入口点调试 - 侦听器Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException"停止传播事件kernel.exception".调试 - 事件kernel.exception"未调用侦听器Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".调试 - 事件kernel.exception"未调用侦听器Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException".调试 - 将事件kernel.response"通知给侦听器Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse".DEBUG - 在会话中写入 SecurityContext调试 - 将事件kernel.response"通知给侦听器Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse".调试 - 将事件kernel.response"通知给侦听器Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse".调试 - 将事件kernel.response"通知给侦听器Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse".调试 - 将事件kernel.response"通知给侦听器Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse".调试 - 将事件kernel.response"通知给侦听器Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse".调试 - 将事件kernel.response"通知给侦听器Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse".
解决方案

anonymous: ~ 添加到您的两个防火墙,并在 access_control 部分强制要求角色.阅读安全章节了解更多信息.>

I'm using symfony 2.3.4 and I tried to set up multiple firewalls. But now everytime I go to /admin/login there's error ERR_TOO_MANY_REDIRECTS.These are my routing.yml and security.yml files:

routing.yml

login_admin:
    pattern:   /admin/login/
    defaults:  { _controller: HerbanistAdminBundle:Security:login }

login_check_admin:
    pattern:   /admin/login_check/

logout_admin:
    path:   /admin/logout/

login_customer:
    pattern:   /customer/login/
    defaults:  { _controller: HerbanistStoreBundle:Security:login }

login_check_customer:
    pattern:   /customer/login_check/

logout_customer:
    path:   /customer/logout/

security.yml

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        in_memory:
            memory:
                users:
                    user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                    admin: { password: admin, roles: [ 'ROLE_ADMIN' ] }

    firewalls:
        admin_secured_area:
            pattern: ^/admin
            form_login:
                check_path: /admin/login_check
                login_path: /admin/login
                always_use_default_target_path: true
                default_target_path: /admin
            logout:
                path:   /admin/logout
                target: /admin
        customer_secured_area:
            pattern:    ^/customer
            form_login:
                check_path: /customere/login_check
                login_path: /customer/login
                always_use_default_target_path: true
                default_target_path: /customer
            logout:
                path:   /customer/logout
                target: /customer

    access_control:
        - { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, roles: ROLE_ADMIN }
        - { path: ^/customer, roles: ROLE_USER }


Edit

Debug messages in Profiler:

DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
INFO - Matched route "login_admin" (parameters: "_controller": "Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction", "path": "/admin/login/", "permanent": "true", "scheme": "null", "httpPort": "80", "httpsPort": "443", "_route": "login_admin")
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException".
INFO - Authentication exception occurred; redirecting to authentication entry point (A Token was not found in the SecurityContext.)
DEBUG - Calling Authentication entry point
DEBUG - Listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException" stopped propagation of the event "kernel.exception".
DEBUG - Listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException" was not called for event "kernel.exception".
DEBUG - Listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException" was not called for event "kernel.exception".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse".
DEBUG - Write SecurityContext in the session
DEBUG - Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse".
解决方案

Add anonymous: ~ to both of your firewalls and force the required roles in the access_control section. Read the Security chapter for more information.

这篇关于在 Symfony 2 中使用多个防火墙会导致 ERR_TOO_MANY_REDIRECTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:23