authenticateRequest example

$this->authenticatorManager = $authenticationManager;
    }

    public function supports(Request $request): ?bool
    {
        return $this->authenticatorManager->supports($request);
    }

    public function authenticate(RequestEvent $event): void
    {
        $request = $event->getRequest();
        $response = $this->authenticatorManager->authenticateRequest($request);
        if (null === $response) {
            return;
        }

        $event->setResponse($response);
    }
}
public function testSupportCheckedUponRequestAuthentication()
    {
        // the attribute stores the supported authenticators, returning false now         // means support changed between calling supports() and authenticateRequest()         // (which is the case with lazy firewalls)         $authenticator = $this->createAuthenticator(false);
        $this->request->attributes->set('_security_authenticators', [$authenticator]);

        $authenticator->expects($this->never())->method('authenticate');

        $manager = $this->createManager([$authenticator]);
        $manager->authenticateRequest($this->request);
    }

    /** * @dataProvider provideMatchingAuthenticatorIndex */
    public function testAuthenticateRequest($matchingAuthenticatorIndex)
    {
        $authenticators = [$this->createAuthenticator(0 === $matchingAuthenticatorIndex)$this->createAuthenticator(1 === $matchingAuthenticatorIndex)];
        $this->request->attributes->set('_security_authenticators', $authenticators);
        $matchingAuthenticator = $authenticators[$matchingAuthenticatorIndex];

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