title: Implementing Custom Authentication Provider using AbstractAuthenticationListener
body: <p>I'm working on Symfon2 and I've read the documentation, I stumbled with a problem belongs to the "Security" Section.
  I need a custom authentication provider made by me that can persist the token in the session so I can get it in a subsequent requests and if the user didn't provide a correct credential, it will redirect him to a login form and if he provided a correct credentials he would be redirected to another page.</p>
  
  <p>1.
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[access welcome page (protected page)]</p>
  
  <p>user -------------------------------------------------------> [user redirected to a login form page] ----> [user provide wrong credentials]
  -----> [user returned to login form page]</p>
  
  <p>2.
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[access welcome page (protected page)]<br/>
  user --------------------------------------------------------> [user redirected to a login form page] ----> [user provide correct credentials]
  -------> [user accessed to welcom page]</p>
  
  <p>I want the custom authentication provider to make some  stuff (verify user with ldap, db ...etc), then provide a token and save it into the security context, and to put in mind my login forms redirections work correctly (if user credentials are wrong, then the user will be redirected to the login form page, and if they are correct then he will redirected to a welcome page).</p>
  
  <p>In the cookbook there is an article about "<a href="http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html" rel="nofollow">How to create a custom Authentication Provider</a>", it's talking about "how to create a custom authentication provider for WSSE authentication."</p>
  
  <p>Later in the article a note is written:
  A class not used above, the <strong>AbstractAuthenticationListener</strong> class, is a very useful base class which provides commonly needed functionality for security extensions. This includes maintaining the token in the session, providing success / failure handlers, login form urls, and more. As WSSE does not require maintaining authentication sessions or login forms, it won't be used for this example.</p>
  
  <p>In the example mentioned in the cookbook, <strong>ListenerInterface</strong> is used, but it cannot be used with login form pages.</p>
  
  <p>If some one solve this problem, I will be very thankful to get the solution.</p>
  
  <p>Best Regards,<br/>
  Dany</p>