vendor/symfony/security-bundle/SecurityBundle.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\SecurityBundle;
  11. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
  12. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
  13. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSessionDomainConstraintPass;
  14. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterCsrfFeaturesPass;
  15. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterGlobalSecurityEventListenersPass;
  16. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterLdapLocatorPass;
  17. use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterTokenUsageTrackingPass;
  18. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AnonymousFactory;
  19. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\CustomAuthenticatorFactory;
  20. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FormLoginFactory;
  21. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FormLoginLdapFactory;
  22. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\GuardAuthenticationFactory;
  23. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\HttpBasicFactory;
  24. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\HttpBasicLdapFactory;
  25. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\JsonLoginFactory;
  26. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\JsonLoginLdapFactory;
  27. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\RememberMeFactory;
  28. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\RemoteUserFactory;
  29. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\X509Factory;
  30. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\InMemoryFactory;
  31. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\LdapFactory;
  32. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  33. use Symfony\Component\DependencyInjection\ContainerBuilder;
  34. use Symfony\Component\EventDispatcher\DependencyInjection\AddEventAliasesPass;
  35. use Symfony\Component\HttpKernel\Bundle\Bundle;
  36. use Symfony\Component\Security\Core\AuthenticationEvents;
  37. use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
  38. use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
  39. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  40. use Symfony\Component\Security\Http\Event\SwitchUserEvent;
  41. use Symfony\Component\Security\Http\SecurityEvents;
  42. /**
  43.  * Bundle.
  44.  *
  45.  * @author Fabien Potencier <fabien@symfony.com>
  46.  */
  47. class SecurityBundle extends Bundle
  48. {
  49.     public function build(ContainerBuilder $container)
  50.     {
  51.         parent::build($container);
  52.         $extension $container->getExtension('security');
  53.         $extension->addSecurityListenerFactory(new FormLoginFactory());
  54.         $extension->addSecurityListenerFactory(new FormLoginLdapFactory());
  55.         $extension->addSecurityListenerFactory(new JsonLoginFactory());
  56.         $extension->addSecurityListenerFactory(new JsonLoginLdapFactory());
  57.         $extension->addSecurityListenerFactory(new HttpBasicFactory());
  58.         $extension->addSecurityListenerFactory(new HttpBasicLdapFactory());
  59.         $extension->addSecurityListenerFactory(new RememberMeFactory());
  60.         $extension->addSecurityListenerFactory(new X509Factory());
  61.         $extension->addSecurityListenerFactory(new RemoteUserFactory());
  62.         $extension->addSecurityListenerFactory(new GuardAuthenticationFactory());
  63.         $extension->addSecurityListenerFactory(new AnonymousFactory());
  64.         $extension->addSecurityListenerFactory(new CustomAuthenticatorFactory());
  65.         $extension->addUserProviderFactory(new InMemoryFactory());
  66.         $extension->addUserProviderFactory(new LdapFactory());
  67.         $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
  68.         $container->addCompilerPass(new AddSecurityVotersPass());
  69.         $container->addCompilerPass(new AddSessionDomainConstraintPass(), PassConfig::TYPE_BEFORE_REMOVING);
  70.         $container->addCompilerPass(new RegisterCsrfFeaturesPass());
  71.         $container->addCompilerPass(new RegisterTokenUsageTrackingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION200);
  72.         $container->addCompilerPass(new RegisterLdapLocatorPass());
  73.         // must be registered after RegisterListenersPass (in the FrameworkBundle)
  74.         $container->addCompilerPass(new RegisterGlobalSecurityEventListenersPass(), PassConfig::TYPE_BEFORE_REMOVING, -200);
  75.         $container->addCompilerPass(new AddEventAliasesPass([
  76.             AuthenticationSuccessEvent::class => AuthenticationEvents::AUTHENTICATION_SUCCESS,
  77.             AuthenticationFailureEvent::class => AuthenticationEvents::AUTHENTICATION_FAILURE,
  78.             InteractiveLoginEvent::class => SecurityEvents::INTERACTIVE_LOGIN,
  79.             SwitchUserEvent::class => SecurityEvents::SWITCH_USER,
  80.         ]));
  81.     }
  82. }