我正在使用 symfony 2.3.4 并尝试设置多个防火墙。但是现在每次我去 /admin/login 都会出现错误 ERR_TOO_MANY_REDIRECTS。这些是我的 routing.yml 和 security.yml 文件:
路由.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/
安全.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".