Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener::__construct PHP Method

__construct() public method

Constructor.
public __construct ( Symfony\Component\Security\Core\SecurityContextInterface $securityContext, Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface $authenticationManager, Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, string $providerKey, array $options = [], Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface $successHandler = null, Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface $failureHandler = null, Symfony\Component\HttpKernel\Log\LoggerInterface $logger = null, Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher = null )
$securityContext Symfony\Component\Security\Core\SecurityContextInterface A SecurityContext instance
$authenticationManager Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface An AuthenticationManagerInterface instance
$sessionStrategy Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface
$httpUtils Symfony\Component\Security\Http\HttpUtils An HttpUtilsInterface instance
$providerKey string
$options array An array of options for the processing of a successful, or failed authentication attempt
$successHandler Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface
$failureHandler Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface
$logger Symfony\Component\HttpKernel\Log\LoggerInterface A LoggerInterface instance
$dispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface An EventDispatcherInterface instance
    public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
    {
        if (empty($providerKey)) {
            throw new \InvalidArgumentException('$providerKey must not be empty.');
        }

        $this->securityContext = $securityContext;
        $this->authenticationManager = $authenticationManager;
        $this->sessionStrategy = $sessionStrategy;
        $this->providerKey = $providerKey;
        $this->successHandler = $successHandler;
        $this->failureHandler = $failureHandler;
        $this->options = array_merge(array(
            'check_path'                     => '/login_check',
            'login_path'                     => '/login',
            'always_use_default_target_path' => false,
            'default_target_path'            => '/',
            'target_path_parameter'          => '_target_path',
            'use_referer'                    => false,
            'failure_path'                   => null,
            'failure_forward'                => false,
        ), $options);
        $this->logger = $logger;
        $this->dispatcher = $dispatcher;
        $this->httpUtils = $httpUtils;
    }

Usage Example

    /**
     * Constructor.
     *
     * @param TokenStorageInterface                  $tokenStorage          A TokenStorageInterface instance
     * @param AuthenticationManagerInterface         $authenticationManager An AuthenticationManagerInterface instance
     * @param SessionAuthenticationStrategyInterface $sessionStrategy
     * @param HttpUtils                              $httpUtils             An HttpUtilsInterface instance
     * @param string                                 $providerKey
     * @param AuthenticationSuccessHandlerInterface  $successHandler
     * @param AuthenticationFailureHandlerInterface  $failureHandler
     * @param array                                  $options               An array of options for the processing of a
     *                                                                      successful, or failed authentication attempt
     * @param LoggerInterface                        $logger                A LoggerInterface instance
     * @param EventDispatcherInterface               $dispatcher            An EventDispatcherInterface instance
     * @param CsrfTokenManagerInterface              $csrfTokenManager      A CsrfTokenManagerInterface instance
     * @param SimpleFormAuthenticatorInterface       $simpleAuthenticator   A SimpleFormAuthenticatorInterface instance
     *
     * @throws \InvalidArgumentException In case no simple authenticator is provided
     * @throws InvalidArgumentException  In case an invalid CSRF token manager is passed
     */
    public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
    {
        if (!$simpleAuthenticator) {
            throw new \InvalidArgumentException('Missing simple authenticator');
        }

        if ($csrfTokenManager instanceof CsrfProviderInterface) {
            $csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
        } elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
            throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
        }

        $this->simpleAuthenticator = $simpleAuthenticator;
        $this->csrfTokenManager = $csrfTokenManager;

        $options = array_merge(array(
            'username_parameter' => '_username',
            'password_parameter' => '_password',
            'csrf_parameter' => '_csrf_token',
            'intention' => 'authenticate',
            'post_only' => true,
        ), $options);

        parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, $options, $logger, $dispatcher);
    }
All Usage Examples Of Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener::__construct