I am using Symfony2 and FOSUserBundle . I want to get a user with Doctrine ORM then logging in as it.
$user = $em->getRepository("InoUserBundle:User")->find(10);
// I want the security context as $user
like so:
$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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.