【发布时间】:2019-12-03 11:41:29
【问题描述】:
我有两种方法可以让用户登录我的应用程序:从后台或从 api。 出于某种原因,我想在身份验证过程开始之前处理 ldap 检查。
- 对于 BO,我发现了这个,并且它的工作正常:
listen to request before authentication or rewrite /login_check in symfony3
- 我也想为 api json 登录做这个,所以我想扩展 UsernamePasswordJsonAuthenticationListener
但当我尝试登录 api 时出现此错误:
传递给 Symfony\Component\Security\Http\Firewall\UsernamePasswordJsonAuthenticationListener::__construct() 的参数 3 必须是 Symfony\Component\Security\Http\HttpUtils 的实例,Symfony\Component\ 的实例Security\Http\Session\SessionAuthenticationStrategy 给定
这是我的代码
services.yaml
security.authentication.listener.json:
class: App\EventListener\UsernamePasswordJsonAuthenticationListener
parent: security.authentication.listener.abstract
abstract: true
autowire: true
autoconfigure: false
calls: [ [initialize, ["@doctrine.orm.entity_manager"]] ]
//用户名密码JsonAuthenticationListener.php
<?php
namespace App\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use App\Service\LdapTools;
use Symfony\Component\Security\Http\Firewall\UsernamePasswordJsonAuthenticationListener as baseJsonAuthenticationListener;
class UsernamePasswordJsonAuthenticationListener extends baseJsonAuthenticationListener
{
/** @var EntityManagerInterface */
protected $entityManager;
/** @var LdapTools */
protected $ldapTools;
/** @var UserManagerInterface */
protected $userManager;
/**
* setter is called through DI container
*
* @param EntityManagerInterface $entityManager
*/
public function initialize(EntityManagerInterface $entityManager,LdapTools $ldapTools,UserManagerInterface $userManager)
{
$this->entityManager = $entityManager;
$this->ldapTools = $ldapTools;
$this->userManager = $userManager;
}
}
?>
感谢之前。
【问题讨论】:
标签: symfony4