我需要手动验证用户,它有效但我有问题。我有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()));
}
谢谢。