我正在Symfony2(.0.x)中开发一个项目,我正在构建一个简单的自动登录系统。现在要做到这一点,我想侦听在防火墙中触发 handle() 方法的事件。唯一的问题是我找不到该怎么做。(我也在使用FOSUserBundle和FOSFacebookbundle的组合)
有人可以帮助我。(或者告诉我我是否做错了)
这是我的服务:
project.user.auto_login_listener:
class: Project'UserBundle'Listener'AutoLoginListener
public: false
abstract: true
arguments: [@security.context, @security.authentication.manager, '' , '' , @logger, @event.dispatcher]
在此示例中,我删除了事件侦听器,因为它不起作用
<?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");
}
}
?>
谢谢!
您必须创建新的身份验证提供程序。遵循此食谱条目。