0

我正在 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");
    }  
}
?>

谢谢!

4

1 回答 1

3

您必须创建一个新的身份验证提供程序。按照这个食谱条目。

于 2012-06-12T18:45:41.143 回答