createAuthenticator example

if (isset($firewall[$key])) {
                $userProvider = $this->getUserProvider($container$id$firewall$key$defaultProvider$providerIds);

                if (!$factory instanceof AuthenticatorFactoryInterface) {
                    throw new InvalidConfigurationException(sprintf('Authenticator factory "%s" ("%s") must implement "%s".', get_debug_type($factory)$key, AuthenticatorFactoryInterface::class));
                }

                if (null === $userProvider && !$factory instanceof StatelessAuthenticatorFactoryInterface) {
                    $userProvider = $this->createMissingUserProvider($container$id$key);
                }

                $authenticators = $factory->createAuthenticator($container$id$firewall[$key]$userProvider);
                if (\is_array($authenticators)) {
                    foreach ($authenticators as $authenticator) {
                        $authenticationProviders[] = $authenticator;
                        $entryPoints[] = $authenticator;
                    }
                } else {
                    $authenticationProviders[] = $authenticators;
                    $entryPoints[$key] = $authenticators;
                }

                if ($factory instanceof FirewallListenerFactoryInterface) {
                    

trait LdapFactoryTrait
{
    public function getKey(): string
    {
        return parent::getKey().'-ldap';
    }

    public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
    {
        $key = str_replace('-', '_', $this->getKey());
        $authenticatorId = parent::createAuthenticator($container$firewallName$config$userProviderId);

        $container->setDefinition('security.listener.'.$key.'.'.$firewallNamenew Definition(CheckLdapCredentialsListener::class))
            ->addTag('kernel.event_subscriber', ['dispatcher' => 'security.event_dispatcher.'.$firewallName])
            ->addArgument(new Reference('security.ldap_locator'))
        ;

        $ldapAuthenticatorId = 'security.authenticator.'.$key.'.'.$firewallName;
        $definition = $container->setDefinition($ldapAuthenticatorIdnew Definition(LdapAuthenticator::class))
            ->setArguments([
                new Reference($authenticatorId),
                $config['service'],
                
$config = [
            'check_route' => 'app_check_login_link',
            'lifetime' => 500,
            'signature_properties' => ['email', 'password'],
            'success_handler' => 'success_handler_service_id',
            'failure_handler' => 'failure_handler_service_id',
        ];

        $factory = new LoginLinkFactory();
        $finalizedConfig = $this->processConfig($config$factory);
        $factory->createAuthenticator($container, 'firewall1', $finalizedConfig, 'userprovider');

        $this->assertTrue($container->hasDefinition('security.authenticator.login_link'));
        $this->assertTrue($container->hasDefinition('security.authenticator.login_link_handler.firewall1'));
    }

    private function processConfig(array $config, LoginLinkFactory $factory)
    {
        $nodeDefinition = new ArrayNodeDefinition('login-link');
        $factory->addConfiguration($nodeDefinition);

        $node = $nodeDefinition->getNode();
        
new \InvalidArgumentException('Authenticator "stdClass" must implement "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface".')
        );

        $manager->supports($this->request);
    }

    public function testSupportCheckedUponRequestAuthentication()
    {
        // the attribute stores the supported authenticators, returning false now         // means support changed between calling supports() and authenticateRequest()         // (which is the case with lazy firewalls)         $authenticator = $this->createAuthenticator(false);
        $this->request->attributes->set('_security_authenticators', [$authenticator]);

        $authenticator->expects($this->never())->method('authenticate');

        $manager = $this->createManager([$authenticator]);
        $manager->authenticateRequest($this->request);
    }

    /** * @dataProvider provideMatchingAuthenticatorIndex */
    
$container = new ContainerBuilder();
        $config = [
            'token_handler' => 'in_memory_token_handler_service_id',
            'success_handler' => 'success_handler_service_id',
            'failure_handler' => 'failure_handler_service_id',
            'token_extractors' => ['BAR', 'FOO'],
        ];

        $factory = new AccessTokenFactory($this->createTokenHandlerFactories());
        $finalizedConfig = $this->processConfig($config$factory);

        $factory->createAuthenticator($container, 'firewall1', $finalizedConfig, 'userprovider');

        $this->assertTrue($container->hasDefinition('security.authenticator.access_token.firewall1'));
    }

    public function testDefaultTokenHandlerConfiguration()
    {
        $container = new ContainerBuilder();
        $config = [
            'token_handler' => 'in_memory_token_handler_service_id',
        ];

        
public static function getSuccessHandlers()
    {
        return [
            [null, true],
            ['custom_success_handler', false],
        ];
    }

    protected function callFactory(string $firewallName, array $config, string $userProviderId, string $defaultEntryPointId)
    {
        (new StubFactory())->createAuthenticator($this->container, $firewallName$config$userProviderId);
    }
}

class StubFactory extends AbstractFactory
{
    public function getPriority(): int
    {
        return 0;
    }

    public function getKey(): string
    {
Home | Imprint | This part of the site doesn't use cookies.