/**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     $domain = $this->ldap->getDomainContext();
     $this->switchDomainIfNeeded($token);
     try {
         $user = $this->userProvider->loadUserByUsername($token->getUsername());
         $this->userChecker->checkPreAuth($user);
         $token = $this->doAuthentication($user, $token);
         $this->userChecker->checkPostAuth($user);
     } catch (UsernameNotFoundException $e) {
         $this->hideOrThrow($e);
     } catch (BadCredentialsException $e) {
         $this->hideOrThrow($e);
     } catch (LdapConnectionException $e) {
         $this->hideOrThrow($e);
     } finally {
         $this->switchDomainBackIfNeeded($domain);
     }
     return $token;
 }
 /**
  * {@inheritdoc}
  */
 public function getUser($credentials, UserProviderInterface $userProvider)
 {
     $domain = $this->ldap->getDomainContext();
     try {
         $this->switchDomainIfNeeded($credentials);
         $user = $userProvider->loadUserByUsername($credentials['username']);
         $this->userChecker->checkPreAuth($user);
         return $user;
     } catch (UsernameNotFoundException $e) {
         $this->hideOrThrow($e);
     } catch (BadCredentialsException $e) {
         $this->hideOrThrow($e);
     } catch (LdapConnectionException $e) {
         $this->hideOrThrow($e);
     } catch (\Exception $e) {
         $this->hideOrThrow($e);
     } finally {
         $this->switchDomainBackIfNeeded($domain);
     }
 }