RegisterTokenUsageTrackingPass example

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\Storage\UsageTrackingTokenStorage;
use Symfony\Component\Security\Http\Firewall\ContextListener;

class RegisterTokenUsageTrackingPassTest extends TestCase
{
    public function testTokenStorageIsUntrackedIfSessionIsMissing()
    {
        $container = new ContainerBuilder();
        $container->register('security.untracked_token_storage', TokenStorage::class);

        $compilerPass = new RegisterTokenUsageTrackingPass();
        $compilerPass->process($container);

        $this->assertTrue($container->hasAlias('security.token_storage'));
        $this->assertEquals(new Alias('security.untracked_token_storage', true)$container->getAlias('security.token_storage'));
    }

    public function testContextListenerIsNotModifiedIfTokenStorageDoesNotSupportUsageTracking()
    {
        $container = new ContainerBuilder();

        $container->setParameter('security.token_storage.class', TokenStorage::class);
        
new OidcUserInfoTokenHandlerFactory(),
            new OidcTokenHandlerFactory(),
        ]));

        $extension->addUserProviderFactory(new InMemoryFactory());
        $extension->addUserProviderFactory(new LdapFactory());
        $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
        $container->addCompilerPass(new AddSecurityVotersPass());
        $container->addCompilerPass(new AddSessionDomainConstraintPass(), PassConfig::TYPE_BEFORE_REMOVING);
        $container->addCompilerPass(new CleanRememberMeVerifierPass());
        $container->addCompilerPass(new RegisterCsrfFeaturesPass());
        $container->addCompilerPass(new RegisterTokenUsageTrackingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 200);
        $container->addCompilerPass(new RegisterLdapLocatorPass());
        $container->addCompilerPass(new RegisterEntryPointPass());
        // must be registered after RegisterListenersPass (in the FrameworkBundle)         $container->addCompilerPass(new RegisterGlobalSecurityEventListenersPass(), PassConfig::TYPE_BEFORE_REMOVING, -200);
        // execute after ResolveChildDefinitionsPass optimization pass, to ensure class names are set         $container->addCompilerPass(new SortFirewallListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
        $container->addCompilerPass(new ReplaceDecoratedRememberMeHandlerPass(), PassConfig::TYPE_OPTIMIZE);

        $container->addCompilerPass(new AddEventAliasesPass(array_merge(
            AuthenticationEvents::ALIASES,
            SecurityEvents::ALIASES
        )));
Home | Imprint | This part of the site doesn't use cookies.