Skip to content

Instantly share code, notes, and snippets.

@cakper
Last active December 17, 2015 17:09
Show Gist options
  • Save cakper/5644139 to your computer and use it in GitHub Desktop.
Save cakper/5644139 to your computer and use it in GitHub Desktop.
Security Token Injection
<?php
/**
* @Given /^I am logged in as a "([^"]*)"$/
*/
public function iAmLoggedInAsA($role)
{
$firewall = 'secured_area';
$session = $this->getContainer()->get('session');
$user = $this->getUser();
$user->setRole($this->getRole($role));
$token = new PreAuthenticatedToken($user, null, $firewall, array($user->getRoleName()));
$session->start();
$this->mink->getSession()->setCookie($session->getName(), $session->getId());
$session->set('_security_' . $firewall, serialize($token));
$session->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment