Exemple #1
0
 /**
  * @param BaseUser $user
  * @param SessionInterface $session
  * @param $firewall
  * @throws UnsupportedDriverActionException
  */
 public function login(BaseUser $user, SessionInterface $session, $firewall)
 {
     $driver = $this->getDriver();
     if (!$driver instanceof BrowserKitDriver) {
         //Fall back to manual login if BrowserKitDriver is not used
         throw new UnsupportedDriverActionException("Not supported by the current driver", $driver);
     }
     $client = $driver->getClient();
     $client->getCookieJar()->set(new Cookie(session_name(), true));
     $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $client->getCookieJar()->set($cookie);
 }