我正在使用symfony 2.3.4,我尝试设置多个防火墙。但现在每次我去/ admin / login都有错误ERR_TOO_MANY_REDIRECTS。这些是我的routing.yml和security.yml文件:
的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 }
修改
在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".
答案 0 :(得分:4)
将anonymous: ~
添加到两个防火墙,并在access_control
部分强制执行所需的角色。有关详细信息,请阅读Security chapter。
答案 1 :(得分:0)
冲突是routing.yml和security.yml中的路径不是完全相同的URL格式。在routing.yml中,它们以'/'结尾,但在security.yml中却没有。所以解决方案是用'/'结束每个路径。并且还要向两个防火墙添加anonymous: ~
。