Symfony: Firewalls, multiple login forms

后端 未结 2 1113
天命终不由人
天命终不由人 2020-12-16 19:43

I am not new to symfony by any means, but I\'ve always used FOSUserBundle which by default prevents one from having 2 different login forms for authenticating t

2条回答
  •  青春惊慌失措
    2020-12-16 20:38

    The problem is that after logging into the "secured_area" firewall you get redirect to "/" which is behind the "members_area" firewall. You can't access "members_area" with your credentials from "secured_area" (at least not by default). Read the details on http://symfony.com/doc/current/reference/configuration/security.html#reference-security-firewall-context .

    If you have a look at the security configuration (http://symfony.com/doc/current/reference/configuration/security.html) you can see that the default_target_path for form_login is "/". Just change this to /admin:

    security:
        ...
    
        firewalls:
        ...
            secured_area:
                pattern:    ^/admin
                ...
                form_login:
                    check_path: /admin/login_check
                    login_path: /admin/login
                    default_target_path: /admin
                logout:
        ...
    

    The alternative is to share the context as described in the first link (http://symfony.com/doc/current/reference/configuration/security.html#reference-security-firewall-context).

提交回复
热议问题