0

i need to manually authenticate a user, it works but i have a problem.I got 2 firewalls, and when i login in one firewall, symfony consider i'm logged in the other firewall too.

Here are my firewalls:

    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

and here is the code to login in the admin firewall:

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()));
        }

thank you.

0 Answers0