protected function retrieveAuthenticatedUser($username)
    {
        // Find the user in LDAP.
        if ($user = $this->resolveUserByUsername($username)) {
            $provider = $this->auth->getProvider();

            if ($provider instanceof NoDatabaseUserProvider) {
                $this->fireAuthenticatedEvent($user);

                return $user;
            } elseif ($provider instanceof DatabaseUserProvider) {
                // Here we'll import the LDAP user. If the user already exists in
                // our local database, it will be returned from the importer.
                $model = Bus::dispatch(
                    new Import($user, $this->model())
                );

                // We'll sync / set the users password after
                // our model has been synchronized.
                Bus::dispatch(new SyncPassword($model));

                // We also want to save the returned model in case it doesn't
                // exist yet, or there are changes to be synced.
                $model->save();

                $this->fireAuthenticatedEvent($user, $model);

                return $model;
            }
        }
    }