vendor/scheb/2fa-bundle/SchebTwoFactorBundle.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Scheb\TwoFactorBundle;
  4. use Scheb\TwoFactorBundle\DependencyInjection\Compiler\AccessListenerCompilerPass;
  5. use Scheb\TwoFactorBundle\DependencyInjection\Compiler\AuthenticationProviderDecoratorCompilerPass;
  6. use Scheb\TwoFactorBundle\DependencyInjection\Compiler\MailerCompilerPass;
  7. use Scheb\TwoFactorBundle\DependencyInjection\Compiler\RememberMeServicesDecoratorCompilerPass;
  8. use Scheb\TwoFactorBundle\DependencyInjection\Compiler\TwoFactorFirewallConfigCompilerPass;
  9. use Scheb\TwoFactorBundle\DependencyInjection\Compiler\TwoFactorProviderCompilerPass;
  10. use Scheb\TwoFactorBundle\DependencyInjection\Factory\Security\AuthenticatorTwoFactorFactory;
  11. use Scheb\TwoFactorBundle\DependencyInjection\Factory\Security\TwoFactorFactory;
  12. use Scheb\TwoFactorBundle\DependencyInjection\Factory\Security\TwoFactorServicesFactory;
  13. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
  14. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FirewallListenerFactoryInterface;
  15. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\HttpKernel\Bundle\Bundle;
  18. /**
  19. * @final
  20. */
  21. class SchebTwoFactorBundle extends Bundle
  22. {
  23. public function build(ContainerBuilder $container): void
  24. {
  25. parent::build($container);
  26. $container->addCompilerPass(new AuthenticationProviderDecoratorCompilerPass());
  27. $container->addCompilerPass(new RememberMeServicesDecoratorCompilerPass());
  28. $container->addCompilerPass(new TwoFactorProviderCompilerPass());
  29. $container->addCompilerPass(new TwoFactorFirewallConfigCompilerPass());
  30. $container->addCompilerPass(new MailerCompilerPass());
  31. // Compatibility for Symfony <= 5.1
  32. // From Symfony 5.2 on the bundle uses FirewallListenerFactoryInterface to inject its TwoFactorAccessListener
  33. if (!interface_exists(FirewallListenerFactoryInterface::class)) {
  34. $container->addCompilerPass(new AccessListenerCompilerPass());
  35. }
  36. /** @var SecurityExtension $extension */
  37. $extension = $container->getExtension('security');
  38. if (interface_exists(AuthenticatorFactoryInterface::class)) {
  39. // Compatibility with authenticators in Symfony >= 5.1
  40. $securityFactory = new AuthenticatorTwoFactorFactory(new TwoFactorServicesFactory());
  41. } else {
  42. $securityFactory = new TwoFactorFactory(new TwoFactorServicesFactory());
  43. }
  44. $extension->addSecurityListenerFactory($securityFactory);
  45. }
  46. }