Search code examples
phpsymfonysymfony5

Log in database Connection failed


I'm using Symfony 5 on my website. To authenticate users I'm using the LDAP Security bundle dedicated for that. It's works well

What I would like is to log in the database all client connections failed. With a custom LDAP Provider and User Checker, I'm able to catch :

  • LockedException
  • DisabledException
  • AccountExpiredException
  • CredentialsExpiredException
  • UsernameNotFoundException

What I would like is to catch invalid credential but I don't find where this exception is throw...

For you:

  1. Where can I catch invalid password exception please?
  2. Where is the easiest method to overwrite to catch all security exceptions please?

Thank you


Solution

  • You should get all this exceptions via the custom access denied handler. (parent exception)

    namespace App\Security;
    
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Security\Core\Exception\AccessDeniedException;
    use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
    
    class AccessDeniedHandler implements AccessDeniedHandlerInterface
    {
        public function handle(Request $request, AccessDeniedException $accessDeniedException)
        {
            // ...
    
            return new Response($content, 403);
        }
    }
    

    -

    # config/packages/security.yaml
    firewalls:
        # ...
    
        main:
            # ...
            access_denied_handler: App\Security\AccessDeniedHandler
    

    see https://symfony.com/doc/current/security/access_denied_handler.html for more info.