security_authenticator.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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\Component\DependencyInjection\Loader\Configurator;
  11. use Symfony\Bundle\SecurityBundle\Security\UserAuthenticator;
  12. use Symfony\Component\DependencyInjection\ServiceLocator;
  13. use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;
  15. use Symfony\Component\Security\Http\Authentication\NoopAuthenticationManager;
  16. use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
  17. use Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator;
  18. use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator;
  19. use Symfony\Component\Security\Http\Authenticator\JsonLoginAuthenticator;
  20. use Symfony\Component\Security\Http\Authenticator\RememberMeAuthenticator;
  21. use Symfony\Component\Security\Http\Authenticator\RemoteUserAuthenticator;
  22. use Symfony\Component\Security\Http\Authenticator\X509Authenticator;
  23. use Symfony\Component\Security\Http\Event\CheckPassportEvent;
  24. use Symfony\Component\Security\Http\EventListener\CheckCredentialsListener;
  25. use Symfony\Component\Security\Http\EventListener\LoginThrottlingListener;
  26. use Symfony\Component\Security\Http\EventListener\PasswordMigratingListener;
  27. use Symfony\Component\Security\Http\EventListener\RememberMeListener;
  28. use Symfony\Component\Security\Http\EventListener\SessionStrategyListener;
  29. use Symfony\Component\Security\Http\EventListener\UserCheckerListener;
  30. use Symfony\Component\Security\Http\EventListener\UserProviderListener;
  31. use Symfony\Component\Security\Http\Firewall\AuthenticatorManagerListener;
  32. return static function (ContainerConfigurator $container) {
  33. $container->services()
  34. // Manager
  35. ->set('security.authenticator.manager', AuthenticatorManager::class)
  36. ->abstract()
  37. ->args([
  38. abstract_arg('authenticators'),
  39. service('security.token_storage'),
  40. service('event_dispatcher'),
  41. abstract_arg('provider key'),
  42. service('logger')->nullOnInvalid(),
  43. param('security.authentication.manager.erase_credentials'),
  44. ])
  45. ->tag('monolog.logger', ['channel' => 'security'])
  46. ->set('security.authenticator.managers_locator', ServiceLocator::class)
  47. ->args([[]])
  48. ->set('security.user_authenticator', UserAuthenticator::class)
  49. ->args([
  50. service('security.firewall.map'),
  51. service('security.authenticator.managers_locator'),
  52. service('request_stack'),
  53. ])
  54. ->alias(UserAuthenticatorInterface::class, 'security.user_authenticator')
  55. ->set('security.authentication.manager', NoopAuthenticationManager::class)
  56. ->alias(AuthenticationManagerInterface::class, 'security.authentication.manager')
  57. ->set('security.firewall.authenticator', AuthenticatorManagerListener::class)
  58. ->abstract()
  59. ->args([
  60. abstract_arg('authenticator manager'),
  61. ])
  62. // Listeners
  63. ->set('security.listener.check_authenticator_credentials', CheckCredentialsListener::class)
  64. ->args([
  65. service('security.encoder_factory'),
  66. ])
  67. ->tag('kernel.event_subscriber')
  68. ->set('security.listener.user_provider', UserProviderListener::class)
  69. ->args([
  70. service('security.user_providers'),
  71. ])
  72. ->tag('kernel.event_listener', ['event' => CheckPassportEvent::class, 'priority' => 1024, 'method' => 'checkPassport'])
  73. ->set('security.listener.user_provider.abstract', UserProviderListener::class)
  74. ->abstract()
  75. ->args([
  76. abstract_arg('user provider'),
  77. ])
  78. ->set('security.listener.password_migrating', PasswordMigratingListener::class)
  79. ->args([
  80. service('security.encoder_factory'),
  81. ])
  82. ->tag('kernel.event_subscriber')
  83. ->set('security.listener.user_checker', UserCheckerListener::class)
  84. ->abstract()
  85. ->args([
  86. abstract_arg('user checker'),
  87. ])
  88. ->set('security.listener.session', SessionStrategyListener::class)
  89. ->abstract()
  90. ->args([
  91. service('security.authentication.session_strategy'),
  92. ])
  93. ->set('security.listener.remember_me', RememberMeListener::class)
  94. ->abstract()
  95. ->args([
  96. abstract_arg('remember me services'),
  97. service('logger')->nullOnInvalid(),
  98. ])
  99. ->tag('monolog.logger', ['channel' => 'security'])
  100. ->set('security.listener.login_throttling', LoginThrottlingListener::class)
  101. ->abstract()
  102. ->args([
  103. service('request_stack'),
  104. abstract_arg('request rate limiter'),
  105. ])
  106. // Authenticators
  107. ->set('security.authenticator.http_basic', HttpBasicAuthenticator::class)
  108. ->abstract()
  109. ->args([
  110. abstract_arg('realm name'),
  111. abstract_arg('user provider'),
  112. service('logger')->nullOnInvalid(),
  113. ])
  114. ->tag('monolog.logger', ['channel' => 'security'])
  115. ->set('security.authenticator.form_login', FormLoginAuthenticator::class)
  116. ->abstract()
  117. ->args([
  118. service('security.http_utils'),
  119. abstract_arg('user provider'),
  120. abstract_arg('authentication success handler'),
  121. abstract_arg('authentication failure handler'),
  122. abstract_arg('options'),
  123. ])
  124. ->set('security.authenticator.json_login', JsonLoginAuthenticator::class)
  125. ->abstract()
  126. ->args([
  127. service('security.http_utils'),
  128. abstract_arg('user provider'),
  129. abstract_arg('authentication success handler'),
  130. abstract_arg('authentication failure handler'),
  131. abstract_arg('options'),
  132. service('property_accessor')->nullOnInvalid(),
  133. ])
  134. ->call('setTranslator', [service('translator')->ignoreOnInvalid()])
  135. ->set('security.authenticator.remember_me', RememberMeAuthenticator::class)
  136. ->abstract()
  137. ->args([
  138. abstract_arg('remember me services'),
  139. param('kernel.secret'),
  140. service('security.token_storage'),
  141. abstract_arg('options'),
  142. service('security.authentication.session_strategy'),
  143. ])
  144. ->set('security.authenticator.x509', X509Authenticator::class)
  145. ->abstract()
  146. ->args([
  147. abstract_arg('user provider'),
  148. service('security.token_storage'),
  149. abstract_arg('firewall name'),
  150. abstract_arg('user key'),
  151. abstract_arg('credentials key'),
  152. service('logger')->nullOnInvalid(),
  153. ])
  154. ->tag('monolog.logger', ['channel' => 'security'])
  155. ->set('security.authenticator.remote_user', RemoteUserAuthenticator::class)
  156. ->abstract()
  157. ->args([
  158. abstract_arg('user provider'),
  159. service('security.token_storage'),
  160. abstract_arg('firewall name'),
  161. abstract_arg('user key'),
  162. service('logger')->nullOnInvalid(),
  163. ])
  164. ->tag('monolog.logger', ['channel' => 'security'])
  165. ;
  166. };