SimplePreAuthenticationFactory.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\DependencyInjection\Security\Factory;
  11. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\DefinitionDecorator;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * @author Jordi Boggiano <j.boggiano@seld.be>
  17. */
  18. class SimplePreAuthenticationFactory implements SecurityFactoryInterface
  19. {
  20. public function getPosition()
  21. {
  22. return 'pre_auth';
  23. }
  24. public function getKey()
  25. {
  26. return 'simple-preauth';
  27. }
  28. public function addConfiguration(NodeDefinition $node)
  29. {
  30. $node
  31. ->children()
  32. ->scalarNode('provider')->end()
  33. ->scalarNode('authenticator')->cannotBeEmpty()->end()
  34. ->end()
  35. ;
  36. }
  37. public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
  38. {
  39. $provider = 'security.authentication.provider.simple_preauth.'.$id;
  40. $container
  41. ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.simple'))
  42. ->replaceArgument(0, new Reference($config['authenticator']))
  43. ->replaceArgument(1, new Reference($userProvider))
  44. ->replaceArgument(2, $id)
  45. ->replaceArgument(3, new Reference('security.user_checker.'.$id))
  46. ;
  47. // listener
  48. $listenerId = 'security.authentication.listener.simple_preauth.'.$id;
  49. $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.simple_preauth'));
  50. $listener->replaceArgument(2, $id);
  51. $listener->replaceArgument(3, new Reference($config['authenticator']));
  52. $listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));
  53. return array($provider, $listenerId, null);
  54. }
  55. }