Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

listen to request before json authentication symfony 4

$
0
0

I have tow way to login the users to my application: from a backoffice or from an api. for some reason i want to process a ldap check before the authentification proccess start.

  • for the BO i found this,and its work fine:

listen to request before authentication or rewrite /login_check in symfony3

  • I want also do that for the api json login,so i want to Extend the UsernamePasswordJsonAuthenticationListener

but i had this error when i try to login to the api:

Argument 3 passed to Symfony\Component\Security\Http\Firewall\UsernamePasswordJsonAuthenticationListener::__construct() must be an instance of Symfony\Component\Security\Http\HttpUtils, instance of Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy given

this is my code

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"]] ]

//UsernamePasswordJsonAuthenticationListener.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;
}

}

?>

thanx before .


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>