title: How to register multiple authentication providers in Symfony2?
body: <p>I created my own authentication based on: <a href="http://symfony.com/doc/2.0/cookbook/security/custom_authentication_provider.html" rel="nofollow noreferrer">http://symfony.com/doc/2.0/cookbook/security/custom_authentication_provider.html</a> and it works well.</p>
  
  <p>But now I need to have two authentication providers. AuthenticationProviderManager supports this but I can't find out how to add second auth provider to my security factory.</p>
  
  <p>My code:</p>
  
  <p>security.yml</p>
  
  <pre><code>  firewalls:
      wsse_secured:
        pattern:   /api/.*
        wsse:      true
  </code></pre>
  
  <p>WsseFactory.php</p>
  
  <pre><code>class WsseFactory implements SecurityFactoryInterface
  {
      public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
      {
          $providerId = 'security.authentication.provider.wsse.'.$id;
          $container
              -&gt;setDefinition(
                  $providerId, 
                  new DefinitionDecorator(
                      'wsse.security.authentication.provider'
                  )
              )
              -&gt;replaceArgument(
                  0, 
                  new Reference($userProvider)
              );
  
          $listenerId = 'security.authentication.listener.wsse.'.$id;
          $container-&gt;setDefinition(
              $listenerId, 
              new DefinitionDecorator(
                  'wsse.security.authentication.listener'
              )
          );
  
          return array($providerId, $listenerId, $defaultEntryPoint);
      }
  
      public function getPosition()
      {
          return 'pre_auth';
      }
  
      public function getKey()
      {
          return 'wsse';
      }
  
      public function addConfiguration(NodeDefinition $node)
      {
      }
  }
  </code></pre>
  
  <p>services.yml:</p>
  
  <pre><code>wsse.security.authentication.provider:
      class: LD\BinaryBackendBundle\Security\Authentication\Provider\WsseProvider
      arguments: ['', %kernel.cache_dir%/security/nonces]
  
  wsse.security.authentication.listener:
      class:  LD\BinaryBackendBundle\Security\Firewall\WsseListener
      arguments: [@security.context, @security.authentication.manager, @logger]
  </code></pre>
  
  <p>So as you can see I have one auth provider registers. How can I add second?</p>