Skip to content

Commit

Permalink
bug #895 Fix unexpected deprecation about Guard (chalasr)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x branch.

Discussion
----------

Fix unexpected deprecation about Guard

Fixes #891

Commits
-------

cae3b1a Fix unexpected deprecation about Guard
  • Loading branch information
chalasr committed Jul 28, 2021
2 parents b94205c + cae3b1a commit 4ae8ee3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
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

0 comments on commit 4ae8ee3

Please sign in to comment.