symfony - Symfony2 security different firewalls don't redirect properly to login -


i configured 3 secured areas based on user type: admin, teacher , student. when i'm accessing /admin, i'm redirected /admin/login. when i'm accessing /teacher or /student redirection fails, although i'm being redirected /teacher/login or /student/login i'm getting error:

the page isn't redirecting properly firefox has detected server redirecting request address in way never complete.

this security.yml:

      firewalls:     # disables authentication assets , profiler, adapt according needs     dev:         pattern:  ^/(_(profiler|wdt)|css|images|js)/         security: false     admin:          pattern: ^/admin          form_login:              check_path: login_check              login_path: /admin/login              provider: chain_provider              csrf_provider: form.csrf_provider              default_target_path: /admin          logout:       true     teacher:          pattern: ^/teacher          form_login:              check_path: login_check              login_path: /teacher/login              provider: chain_provider              csrf_provider: form.csrf_provider              default_target_path: /teacher          logout:       true     student:          pattern: ^/student          form_login:              check_path: login_check              login_path: /student/login              provider: chain_provider              csrf_provider: form.csrf_provider              default_target_path: /student          logout:       true  access_control:     - { path: ^/admin/login, role: is_authenticated_anonymously }     - { path: ^/teacher/login, role: is_authenticated_anonymously }     - { path: ^/teacher/register, role: is_authenticated_anonymously }     - { path: ^/student/login, role: is_authenticated_anonymously }     - { path: ^/student/register, role: is_authenticated_anonymously }     - { path: ^/resetting, role: is_authenticated_anonymously }     - { path: ^/admin, role: role_admin }     - { path: ^/teacher, role: role_teacher }     - { path: ^/student, role: role_user } 

i need help. missing? thanks

you've secured login forms ... when symfony tries redirect login form, tries redirect login form, tries redirect login form, tries redirect ...

try this:

admin_login:     pattern:                 ^/admin/login     anonymous:               ~  admin:     pattern:                 ^/admin     form_login:         login_path:          /admin/login         check_path:          /login_check         provider:            chain_provider         csrf_provider:       form.csrf_provider         default_target_path: /admin     logout:         path:                /logout         target:              /admin/login  teacher_login:     pattern:                 ^/teacher/login     anonymous:               ~  teacher:     pattern:                 ^/teacher     form_login:        ... etc ...  student_login:     pattern:                 ^/student/login     anonymous:               ~  student:     pattern:                 ^/student     form_login:         .... etc ...  access_control:     - { path: ^/admin/login$,   roles: is_authenticated_anonymously }     - { path: ^/teacher/login$, roles: is_authenticated_anonymously }     - { path: ^/student/login$, roles: is_authenticated_anonymously }     ...     - { path: ^/admin,          roles: role_admin }     - { path: ^/teacher,        roles: role_teacher }     - { path: ^/student,        roles: role_user } 

this covered under heading avoid common pitfalls in symfony cookbook.

the order of firewalls important

note 'login firewalls' defined ahead of partner firewalls.

note added '/' front of check_path remind you need define route it. if use annotations define routes, you'll need create empty action method in controller somewhere router has chew on.

your 'logout' definitions suspect me well. not saying they're incorrect - i've never seen them defined way before , not how definitions work given know of symfony.

in case of '/logout' paths i've defined in example above, - again - need create valid route these ... though symfony won't execute 'logout' method define in controllers.

the logout stuff covered here


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -