[SecurityBundle] Deprecate public services to private

This commit is contained in:
Thomas Calvet 2021-04-16 18:30:15 +02:00 committed by Fabien Potencier
parent d7007d7785
commit 56be86aa7d
8 changed files with 36 additions and 5 deletions

View File

@ -214,6 +214,7 @@ SecurityBundle
use `security.password_hasher_factory` and `Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface` instead use `security.password_hasher_factory` and `Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface` instead
* Deprecate the `security.user_password_encoder.generic` service, the `security.password_encoder` and the `Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface` aliases, * Deprecate the `security.user_password_encoder.generic` service, the `security.password_encoder` and the `Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface` aliases,
use `security.user_password_hasher`, `security.password_hasher` and `Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface` instead use `security.user_password_hasher`, `security.password_hasher` and `Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface` instead
* Deprecate the public `security.authorization_checker` and `security.token_storage` services to private
Serializer Serializer
---------- ----------

View File

@ -300,6 +300,7 @@ SecurityBundle
use `security.password_hasher_factory` and `Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface` instead use `security.password_hasher_factory` and `Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface` instead
* Remove the `security.user_password_encoder.generic` service, the `security.password_encoder` and the `Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface` aliases, * Remove the `security.user_password_encoder.generic` service, the `security.password_encoder` and the `Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface` aliases,
use `security.user_password_hasher`, `security.password_hasher` and `Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface` instead use `security.user_password_hasher`, `security.password_hasher` and `Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface` instead
* The `security.authorization_checker` and `security.token_storage` services are now private
Serializer Serializer
---------- ----------

View File

@ -11,16 +11,32 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
class SecurityController implements ContainerAwareInterface class SecurityController implements ServiceSubscriberInterface
{ {
use ContainerAwareTrait; private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function profileAction() public function profileAction()
{ {
return new Response('Welcome '.$this->container->get('security.token_storage')->getToken()->getUserIdentifier().'!'); return new Response('Welcome '.$this->container->get('security.token_storage')->getToken()->getUserIdentifier().'!');
} }
/**
* {@inheritdoc}
*/
public static function getSubscribedServices(): array
{
return [
'security.token_storage' => TokenStorageInterface::class,
];
}
} }

View File

@ -1,6 +1,12 @@
imports: imports:
- { resource: ./../config/default.yml } - { resource: ./../config/default.yml }
services:
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SecurityController:
public: true
tags:
- container.service_subscriber
security: security:
providers: providers:
main: main:

View File

@ -16,6 +16,7 @@ CHANGELOG
use `security.password_hasher_factory` and `Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface` instead use `security.password_hasher_factory` and `Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface` instead
* Deprecate the `security.user_password_encoder.generic` service, the `security.password_encoder` and the `Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface` aliases, * Deprecate the `security.user_password_encoder.generic` service, the `security.password_encoder` and the `Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface` aliases,
use `security.user_password_hasher`, `security.password_hasher` and `Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface` instead use `security.user_password_hasher`, `security.password_hasher` and `Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface` instead
* Deprecate the public `security.authorization_checker` and `security.token_storage` services to private
5.2.0 5.2.0
----- -----

View File

@ -68,6 +68,7 @@ return static function (ContainerConfigurator $container) {
service('security.access.decision_manager'), service('security.access.decision_manager'),
param('security.access.always_authenticate_before_granting'), param('security.access.always_authenticate_before_granting'),
]) ])
->tag('container.private', ['package' => 'symfony/security-bundle', 'version' => '5.3'])
->alias(AuthorizationCheckerInterface::class, 'security.authorization_checker') ->alias(AuthorizationCheckerInterface::class, 'security.authorization_checker')
->set('security.token_storage', UsageTrackingTokenStorage::class) ->set('security.token_storage', UsageTrackingTokenStorage::class)
@ -80,6 +81,7 @@ return static function (ContainerConfigurator $container) {
]) ])
->tag('kernel.reset', ['method' => 'disableUsageTracking']) ->tag('kernel.reset', ['method' => 'disableUsageTracking'])
->tag('kernel.reset', ['method' => 'setToken']) ->tag('kernel.reset', ['method' => 'setToken'])
->tag('container.private', ['package' => 'symfony/security-bundle', 'version' => '5.3'])
->alias(TokenStorageInterface::class, 'security.token_storage') ->alias(TokenStorageInterface::class, 'security.token_storage')
->set('security.untracked_token_storage', TokenStorage::class) ->set('security.untracked_token_storage', TokenStorage::class)

View File

@ -28,7 +28,7 @@ class SecurityTest extends AbstractWebTestCase
// put a token into the storage so the final calls can function // put a token into the storage so the final calls can function
$user = new InMemoryUser('foo', 'pass'); $user = new InMemoryUser('foo', 'pass');
$token = new UsernamePasswordToken($user, '', 'provider', ['ROLE_USER']); $token = new UsernamePasswordToken($user, '', 'provider', ['ROLE_USER']);
$container->get('security.token_storage')->setToken($token); $container->get('security.token_storage.alias')->setToken($token);
$security = $container->get('functional_test.security.helper'); $security = $container->get('functional_test.security.helper');
$this->assertTrue($security->isGranted('ROLE_USER')); $this->assertTrue($security->isGranted('ROLE_USER'));

View File

@ -7,6 +7,10 @@ services:
alias: security.helper alias: security.helper
public: true public: true
functional.test.security.token_storage:
alias: security.token_storage
public: true
security: security:
providers: providers:
in_memory: in_memory: