title: Handling login failure in a Symfony application
body: <p>I am currently working on an app that is using the FosUserBundle and maintains a local database of users. The use case is as follows:</p>
  
  <p>User tries to login and upon login the credentials are authenticated</p>
  
  <p>In case of success the user proceeds to navigate the site</p>
  
  <p>In case of failure above:</p>
  
  <p>the credentials are authenticated against a single sign on service and if credentials are correct, the user is created locally, logged in, and proceeds to navigate the site. </p>
  
  <p>In case the single sign on is unsuccessful, user is shown the default incorrect password screen</p>
  
  <p>My question is where in Symfony would I add this logic?  </p>
  
  <p>This is what I have tried so far:</p>
  
  <ol>
  <li><p>I have tried to look at overrriding the loginAction however on
  further research I read that it may not work as it just dislays the
  login form. </p></li>
  <li><p>I looked at the following stackoverflow question:
  <a href="https://stackoverflow.com/questions/17545694/overriding-the-authentication-failure-handler-symfony2">Overriding the authentication failure handler - Symfony2</a></p></li>
  <li><p>Also I read this in Symfony docs:
  <a href="http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html" rel="nofollow noreferrer">http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html</a></p></li>
  </ol>
  
  <p>I am not clear as to whether I should use the approach in 2 or 3 in my use case. Any tips or code samples would be highly appreciated. </p>