RemoteUserFactory.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * RemoteUserFactory creates services for REMOTE_USER based authentication.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Maxime Douailin <maxime.douailin@gmail.com>
  20. */
  21. class RemoteUserFactory implements SecurityFactoryInterface
  22. {
  23. public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
  24. {
  25. $providerId = 'security.authentication.provider.pre_authenticated.'.$id;
  26. $container
  27. ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.pre_authenticated'))
  28. ->replaceArgument(0, new Reference($userProvider))
  29. ->replaceArgument(1, new Reference('security.user_checker.'.$id))
  30. ->addArgument($id)
  31. ;
  32. $listenerId = 'security.authentication.listener.remote_user.'.$id;
  33. $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.remote_user'));
  34. $listener->replaceArgument(2, $id);
  35. $listener->replaceArgument(3, $config['user']);
  36. $listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));
  37. return array($providerId, $listenerId, $defaultEntryPoint);
  38. }
  39. public function getPosition()
  40. {
  41. return 'pre_auth';
  42. }
  43. public function getKey()
  44. {
  45. return 'remote-user';
  46. }
  47. public function addConfiguration(NodeDefinition $node)
  48. {
  49. $node
  50. ->children()
  51. ->scalarNode('provider')->end()
  52. ->scalarNode('user')->defaultValue('REMOTE_USER')->end()
  53. ->end()
  54. ;
  55. }
  56. }