I’m developing a project in Symfony2(.0.x) and I’m building a simple auto login system.
Now to do that I want to listen to the event that triggers the handle() method in the Firewall. Only problem is that I can’t find out how to do it. (I’m also using the FOSUserBundle combined with the FOSFacebookbundle)
Someone who could help me. (Or tell me if i’m doing it all wrong)
This is my service:
project.user.auto_login_listener:
class: Project\UserBundle\Listener\AutoLoginListener
public: false
abstract: true
arguments: [@security.context, @security.authentication.manager, '' , '' , @logger, @event.dispatcher]
I have removed my event listener in this example because it doesn’t work
<?php
namespace Project\UserBundle\Listener;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
class AutoLoginListener implements ListenerInterface {
private $authenticationManager;
private $dispatcher;
private $logger;
private $providerKey;
private $securityContext;
private $tokenParam;
public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $tokenParam, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
{
$this->securityContext = $securityContext;
$this->authenticationManager = $authenticationManager;
$this->providerKey = $providerKey;
$this->tokenParam = $tokenParam;
$this->logger = $logger;
$this->dispatcher = $dispatcher;
}
public function handle(GetResponseEvent $event)
{
die("test");
}
}
?>
Thanks!
You have to create a new authentication provider. Follow this cookbook entry.