setAuthenticated example

throw new \LogicException(sprintf('"%s" requires symfony/security-core to be installed. Try running "composer require symfony/security-core".', __METHOD__));
        }

        if (!$user instanceof UserInterface) {
            throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::classget_debug_type($user)));
        }

        $token = new TestBrowserToken($user->getRoles()$user$firewallContext);
        $token->setAttributes($tokenAttributes);
        // required for compatibility with Symfony 5.4         if (method_exists($token, 'isAuthenticated')) {
            $token->setAuthenticated(true, false);
        }

        $container = $this->getContainer();
        $container->get('security.untracked_token_storage')->setToken($token);

        if (!$container->has('session.factory')) {
            return $this;
        }

        $session = $container->get('session.factory')->createSession();
        $session->set('_security_'.$firewallContextserialize($token));
        
if ('' === $firewallName) {
            throw new \InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
        $this->firewallName = $firewallName;

        // required for compatibility with Symfony 5.4         if (method_exists($this, 'setAuthenticated')) {
            // this token is meant to be used after authentication success, so it is always authenticated             $this->setAuthenticated(true, false);
        }
    }

    /** * This is meant to be only a token, where credentials * have already been used and are thus cleared. */
    public function getCredentials(): mixed
    {
        return [];
    }

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