InteractiveLoginEvent example

$this->logger?->debug('Authenticator set no success response: request continues.', ['authenticator' => ($authenticator instanceof TraceableAuthenticator ? $authenticator->getAuthenticator() : $authenticator)::class]);

        return null;
    }

    private function handleAuthenticationSuccess(TokenInterface $authenticatedToken, Passport $passport, Request $request, AuthenticatorInterface $authenticator, ?TokenInterface $previousToken): ?Response
    {
        $this->tokenStorage->setToken($authenticatedToken);

        $response = $authenticator->onAuthenticationSuccess($request$authenticatedToken$this->firewallName);
        if ($authenticator instanceof InteractiveAuthenticatorInterface && $authenticator->isInteractive()) {
            $loginEvent = new InteractiveLoginEvent($request$authenticatedToken);
            $this->eventDispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN);
        }

        $this->eventDispatcher->dispatch($loginSuccessEvent = new LoginSuccessEvent($authenticator$passport$authenticatedToken$request$response$this->firewallName, $previousToken));

        return $loginSuccessEvent->getResponse();
    }

    /** * Handles an authentication failure and returns the Response for the authenticator. */
    
use Symfony\Component\Security\Http\SecurityEvents;

final class EventAliasTest extends AbstractWebTestCase
{
    public function testAliasedEvents()
    {
        $client = $this->createClient(['test_case' => 'AliasedEvents', 'root_config' => 'config.yml']);
        $container = $client->getContainer();
        $dispatcher = $container->get('event_dispatcher');

        $dispatcher->dispatch(new AuthenticationSuccessEvent($this->createMock(TokenInterface::class)), AuthenticationEvents::AUTHENTICATION_SUCCESS);
        $dispatcher->dispatch(new InteractiveLoginEvent($this->createMock(Request::class)$this->createMock(TokenInterface::class)), SecurityEvents::INTERACTIVE_LOGIN);
        $dispatcher->dispatch(new SwitchUserEvent($this->createMock(Request::class)$this->createMock(UserInterface::class)$this->createMock(TokenInterface::class)), SecurityEvents::SWITCH_USER);

        $this->assertEquals(
            [
                'onAuthenticationSuccess' => 1,
                'onInteractiveLogin' => 1,
                'onSwitchUser' => 1,
            ],
            $container->get('test_subscriber')->calledMethods
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.