我需要手动验证用户身份,它可以工作,但是我有一个问题。我有2个防火墙,当我登录一个防火墙时,symfony认为我也登录了另一个防火墙。

这是我的防火墙:

    firewalls:
    admin:
        pattern: ^/admin
        form_login:
            check_path: /admin/login_check
            login_path: /admin/login
            username_parameter:       username
            password_parameter:       password
            default_target_path: /admin
        logout:
             path: /admin/logout
             target: /admin/login
        security: true
        anonymous: true
    user:
        pattern: ^/
        form_login:
            check_path: /login_check
            login_path: /login
            username_parameter:       username
            password_parameter:       password
            default_target_path: /
        logout:
             path: /logout
             target: /login
        security: true
        anonymous: true

这是在管理防火墙中登录的代码:

public function checkAction(Request $request) {
            $params = $request->request->all();
            $url = 'http://api.remote/login_check';
            $result = HelperController::my_file_read($url,$params,null,false,false);
            if ($result["code"] == 200) {
                $session = new Session();
                $session->set("token_adm",$result["datas"]->token);
                $url = 'http://api.remote/getCurrentUser';
                $resultContent = HelperController::my_file_read($url,$params,null,false,false);
                $session->set($result["datas"]->token,$resultContent["datas"]->datas);
                $token = new UsernamePasswordToken($resultContent["datas"]->datas->username, null, "admin", $resultContent["datas"]->datas->role);
    >username, null, "admin", $roles);
                $this->get("security.context")->setToken($token);
                $this->get('session')->set('_security_admin',serialize($token));
                return $this->redirect($this->generateUrl('eip_admin_homepage', array()));
            }
            $this->get('session')->getFlashBag()->add('notice', "the username and password combination you have entered is invalid");
            return $this->redirect($this->generateUrl('eip_admin_login', array()));
        }

谢谢。

  ask by user3424349 translate from so

本文未有回复,本站智能推荐: