Ejemplo n.º 1
0
 /**
  * @Given I am authenticated as :username
  * @Given I am authenticated as :username on firewall :firewall
  */
 public function iAmAuthenticatedAs($username, $firewall = 'main')
 {
     /** @var \Behat\Mink\Session $session */
     $minkSession = $this->minkContext->getSession();
     /** @var \Behat\Symfony2Extension\Driver\KernelDriver $driver */
     $driver = $minkSession->getDriver();
     if (!$driver instanceof BrowserKitDriver) {
         throw new UnsupportedDriverActionException('This step is only supported by the BrowserKitDriver', $driver);
     }
     /** @var \Symfony\Component\Security\Core\User\UserProviderInterface $userProvider */
     $userProvider = $this->getContainer()->get('fos_user.user_manager');
     $user = $userProvider->loadUserByUsername($username);
     $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
     $client = $driver->getClient();
     $session = $client->getContainer()->get('session');
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $client->getCookieJar()->set($cookie);
 }
Ejemplo n.º 2
0
 /**
  * @param null $name
  * @return Session
  */
 public function getSession($name = null)
 {
     return parent::getSession($name);
 }