X509Factory.php 2.3 KB

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