【问题标题】:Listen to the handle method of firewall symfony听听防火墙symfony的处理方法
【发布时间】:2012-06-12 12:02:28
【问题描述】:

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

谢谢!

【问题讨论】:

    标签: php events symfony listener


    【解决方案1】:

    您必须创建一个新的身份验证提供程序。关注this 食谱条目。

    【讨论】:

      猜你喜欢
      • 2018-04-02
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多