我正在使用 Symfony2 和 FOSUserBundle 。我想让一个用户使用Doctrine ORM然后以其身份登录。
$user = $em->getRepository("InoUserBundle:User")->find(10);
// I want the security context as $user
答案 0 :(得分:1)
$token = new UsernamePasswordToken($user, '12345', "admin", $user->getRolesAsArray());
$this->get('security.context')->setToken($token);
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);