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 (bis) #897

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,32 @@
<?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;

/**
* @internal
*/
class DeprecateLegacyGuardAuthenticatorPass 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;
}

$deprecationArgs = ['The "%service_id%" service is deprecated and will be removed in 3.0, use the new "jwt" authenticator instead.'];
if (method_exists(BaseNode::class, 'getDeprecation')) {
$deprecationArgs = ['lexik/jwt-authentication-bundle', '2.7', 'The "%service_id%" service is deprecated and will be removed in 3.0, use the new "jwt" authenticator instead.'];
}

$container
->getDefinition('lexik_jwt_authentication.security.guard.jwt_token_authenticator')
->setDeprecated(...$deprecationArgs);
}
}

This file was deleted.

1 change: 1 addition & 0 deletions DependencyInjection/LexikJWTAuthenticationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('response_interceptor.xml');
$loader->load('token_authenticator.xml');
$loader->load('token_extractor.xml');
$loader->load('guard_authenticator.xml');

if (isset($config['private_key_path'])) {
$config['secret_key'] = $config['private_key_path'];
Expand Down
10 changes: 3 additions & 7 deletions DependencyInjection/Security/Factory/JWTAuthenticatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
->setDefinition($authenticatorId, new ChildDefinition('lexik_jwt_authentication.security.jwt_authenticator'))
->replaceArgument(3, new Reference($userProviderId));

$this->removeLegacyGuardServices($container);
// 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);

return $authenticatorId;
}

private function removeLegacyGuardServices(ContainerBuilder $container)
{
$container->removeAlias('lexik_jwt_authentication.jwt_token_authenticator');
$container->removeDefinition('lexik_jwt_authentication.security.guard.jwt_token_authenticator');
}
}
4 changes: 0 additions & 4 deletions DependencyInjection/Security/Factory/JWTUserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ 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
3 changes: 2 additions & 1 deletion 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\DeprecateLegacyGuardAuthenticatorPass;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\RegisterLegacyGuardAuthenticatorPass;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\WireGenerateTokenCommandPass;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTAuthenticatorFactory;
Expand All @@ -28,7 +29,7 @@ public function build(ContainerBuilder $container)
parent::build($container);

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

/** @var SecurityExtension $extension */
$extension = $container->getExtension('security');
Expand Down
19 changes: 19 additions & 0 deletions Resources/config/guard_authenticator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
</services>
</container>