/**
  * {@inheritdoc}
  */
 protected function retrieveUser($username, UsernamePasswordToken $token)
 {
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         return $user;
     }
     try {
         $user = $this->userProvider->loadUserByUsername($username);
         if (!$user instanceof UserInterface) {
             throw new AuthenticationServiceException('The user provider must return a UserInterface object.');
         }
         return $user;
     } catch (UsernameNotFoundException $e) {
         $e->setUsername($username);
         throw $e;
     } catch (\Exception $e) {
         $e = new AuthenticationServiceException($e->getMessage(), 0, $e);
         $e->setToken($token);
         throw $e;
     }
 }