Skip to content
Merged

n/a #16631

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;

/**
* RememberMeListener implements authentication capabilities via a cookie.
Expand All @@ -33,6 +34,7 @@ class RememberMeListener implements ListenerInterface
private $authenticationManager;
private $logger;
private $dispatcher;
private $sessionStrategy;

/**
* Constructor.
Expand All @@ -50,6 +52,7 @@ public function __construct(SecurityContextInterface $securityContext, RememberM
$this->authenticationManager = $authenticationManager;
$this->logger = $logger;
$this->dispatcher = $dispatcher;
$this->sessionStrategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
}

/**
Expand All @@ -70,6 +73,11 @@ public function handle(GetResponseEvent $event)

try {
$token = $this->authenticationManager->authenticate($token);

if ($request->hasSession() && $request->getSession()->isStarted()) {
$this->sessionStrategy->onAuthentication($request, $token);
}

$this->securityContext->setToken($token);

if (null !== $this->dispatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,69 @@ public function testOnCoreSecurity()
$listener->handle($event);
}

public function testSessionStrategy()
{
list($listener, $tokenStorage, $service, $manager) = $this->getListener(false, true, true);

$tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
;

$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$service
->expects($this->once())
->method('autoLogin')
->will($this->returnValue($token))
;

$tokenStorage
->expects($this->once())
->method('setToken')
->with($this->equalTo($token))
;

$manager
->expects($this->once())
->method('authenticate')
->will($this->returnValue($token))
;

$session = $this->getMock('\Symfony\Component\HttpFoundation\Session\SessionInterface');
$session
->expects($this->once())
->method('isStarted')
->will($this->returnValue(true))
;
$session
->expects($this->once())
->method('migrate')
;

$request = $this->getMock('\Symfony\Component\HttpFoundation\Request');
$request
->expects($this->any())
->method('hasSession')
->will($this->returnValue(true))
;

$request
->expects($this->any())
->method('getSession')
->will($this->returnValue($session))
;

$event = $this->getGetResponseEvent();
$event
->expects($this->once())
->method('getRequest')
->will($this->returnValue($request))
;

$listener->handle($event);
}

protected function getGetResponseEvent()
{
return $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
Expand Down