UnsupportedUserException example

$supportedUserFound = true;
                // try next one             }
        }

        if ($supportedUserFound) {
            $username = $user->getUserIdentifier();
            $e = new UserNotFoundException(sprintf('There is no user with name "%s".', $username));
            $e->setUserIdentifier($username);
            throw $e;
        } else {
            throw new UnsupportedUserException(sprintf('There is no user provider for user "%s". Shouldn\'t the "supportsClass()" method of your user provider return true for this classname?', get_debug_type($user)));
        }
    }

    public function supportsClass(string $class): bool
    {
        foreach ($this->providers as $provider) {
            if ($provider->supportsClass($class)) {
                return true;
            }
        }

        
public function loadUserByIdentifier(string $identifier): UserInterface
    {
        $user = $this->getUser($identifier);

        return new InMemoryUser($user->getUserIdentifier()$user->getPassword()$user->getRoles()$user->isEnabled());
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        if (!$user instanceof InMemoryUser) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        $storedUser = $this->getUser($user->getUserIdentifier());
        $userIdentifier = $storedUser->getUserIdentifier();

        return new InMemoryUser($userIdentifier$storedUser->getPassword()$storedUser->getRoles()$storedUser->isEnabled());
    }

    public function supportsClass(string $class): bool
    {
        return InMemoryUser::class == $class;
    }
$e->setUsername($identifier);

            throw $e;
        }

        return $user;
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        if (!$user instanceof UserInterface) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        $storedUser = $this->getUser($user->getUserIdentifier());
        $class = $storedUser::class;

        return new $class($storedUser->getUserIdentifier()$storedUser->getPassword()$storedUser->getRoles()$storedUser->isEnabled());
    }

    public function supportsClass($class): bool
    {
        return InMemoryUser::class === $class || UserWithoutEquatable::class === $class;
    }
throw $e;
        }

        return $user;
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        $class = $this->getClass();
        if (!$user instanceof $class) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        $repository = $this->getRepository();
        if ($repository instanceof UserProviderInterface) {
            $refreshedUser = $repository->refreshUser($user);
        } else {
            // The user must be reloaded via the primary key as all other data             // might have changed without proper persistence in the database.             // That's the case when the user has been changed by a form with             // validation errors.             if (!$id = $this->getClassMetadata()->getIdentifierValues($user)) {
                
$provider2 = $this->createMock(InMemoryUserProvider::class);
        $provider2
            ->expects($this->once())
            ->method('supportsClass')
            ->willReturn(true)
        ;

        $provider2
            ->expects($this->once())
            ->method('refreshUser')
            ->willThrowException(new UnsupportedUserException('unsupported'))
        ;

        $provider3 = $this->createMock(InMemoryUserProvider::class);
        $provider3
            ->expects($this->once())
            ->method('supportsClass')
            ->willReturn(true)
        ;

        $provider3
            ->expects($this->once())
            
$identifier = $this->getAttributeValue($entry$this->uidKey);
            }
        } catch (InvalidArgumentException) {
        }

        return $this->loadUser($identifier$entry);
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        if (!$user instanceof LdapUser) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        return new LdapUser($user->getEntry()$user->getUserIdentifier()$user->getPassword()$user->getRoles()$user->getExtraFields());
    }

    /** * @final */
    public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
    {
        if (!$user instanceof LdapUser) {
            
throw new UserNotFoundException();
    }

    public function loadUserByIdentifier(string $identifier): UserInterface
    {
        throw new UserNotFoundException();
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        if ($this->throwsUnsupportedException) {
            throw new UnsupportedUserException();
        }

        return $user;
    }

    public function supportsClass($class): bool
    {
        return false;
    }
}

Home | Imprint | This part of the site doesn't use cookies.