Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected deprecation about Guard #895

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler;

use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;

class RegisterLegacyGuardAuthenticatorPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasParameter('lexik_jwt_authentication.authenticator_manager_enabled') || !$container->getParameter('lexik_jwt_authentication.authenticator_manager_enabled')) {
return;
}

$container->register('.lexik_jwt_authentication.pre_authentication_token_storage', TokenStorage::class);
$container
->register('lexik_jwt_authentication.security.guard.jwt_token_authenticator', JWTTokenAuthenticator::class)
->setArguments([
new Reference('lexik_jwt_authentication.jwt_manager'),
new Reference('event_dispatcher'),
new Reference('lexik_jwt_authentication.extractor.chain_extractor'),
new Reference('.lexik_jwt_authentication.pre_authentication_token_storage'),
])
;
$container->setAlias('lexik_jwt_authentication.jwt_token_authenticator', 'lexik_jwt_authentication.security.guard.jwt_token_authenticator');
$container->getParameterBag()->remove('lexik_jwt_authentication.authenticator_manager_enabled');
}
}

4 changes: 4 additions & 0 deletions DependencyInjection/Security/Factory/JWTUserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public function create(ContainerBuilder $container, $id, $config)
{
$container->setDefinition($id, new ChildDefinition('lexik_jwt_authentication.security.jwt_user_provider'))
->replaceArgument(0, $config['class']);

// Compile-time parameter removed by RemoveLegacyAuthenticatorPass
// Stop setting it when guard support gets removed (aka when removing Symfony<5.3 support)
$container->setParameter('lexik_jwt_authentication.authenticator_manager_enabled', true);
}

public function getKey()
Expand Down
2 changes: 2 additions & 0 deletions LexikJWTAuthenticationBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lexik\Bundle\JWTAuthenticationBundle;

use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\RegisterLegacyGuardAuthenticatorPass;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\WireGenerateTokenCommandPass;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTAuthenticatorFactory;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTFactory;
Expand All @@ -27,6 +28,7 @@ public function build(ContainerBuilder $container)
parent::build($container);

$container->addCompilerPass(new WireGenerateTokenCommandPass());
$container->addCompilerPass(new RegisterLegacyGuardAuthenticatorPass());

/** @var SecurityExtension $extension */
$extension = $container->getExtension('security');
Expand Down
11 changes: 0 additions & 11 deletions Resources/config/token_authenticator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="lexik_jwt_authentication.jwt_token_authenticator" alias="lexik_jwt_authentication.security.guard.jwt_token_authenticator" />

<service id="lexik_jwt_authentication.security.guard.jwt_token_authenticator" class="Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator">
<argument type="service" id="lexik_jwt_authentication.jwt_manager"/>
<argument type="service" id="event_dispatcher"/>
<argument type="service" id="lexik_jwt_authentication.extractor.chain_extractor"/>
<argument type="service">
<service class="Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage" />
</argument>
</service>

<service id="lexik_jwt_authentication.security.jwt_authenticator" class="Lexik\Bundle\JWTAuthenticationBundle\Security\Authenticator\JWTAuthenticator" abstract="true">
<argument type="service" id="lexik_jwt_authentication.jwt_manager"/>
<argument type="service" id="event_dispatcher"/>
Expand Down