feature #40838 [SecurityBundle] Deprecate public services to private (fancyweb)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[SecurityBundle] Deprecate public services to private

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | -
| License       | MIT
| Doc PR        | -

Follow up of https://github.com/symfony/symfony/pull/36691 on the SecurityBundle

Commits
-------

56be86aa7d [SecurityBundle] Deprecate public services to private
This commit is contained in:
Fabien Potencier 2021-04-18 07:46:24 +02:00
commit 1a87c72c1f
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
* 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
* Deprecate the public `security.authorization_checker` and `security.token_storage` services to private
Serializer
----------

View File

@ -300,6 +300,7 @@ SecurityBundle
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,
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
----------

View File

@ -11,16 +11,32 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Psr\Container\ContainerInterface;
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()
{
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:
- { resource: ./../config/default.yml }
services:
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SecurityController:
public: true
tags:
- container.service_subscriber
security:
providers:
main:

View File

@ -16,6 +16,7 @@ CHANGELOG
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,
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
-----

View File

@ -68,6 +68,7 @@ return static function (ContainerConfigurator $container) {
service('security.access.decision_manager'),
param('security.access.always_authenticate_before_granting'),
])
->tag('container.private', ['package' => 'symfony/security-bundle', 'version' => '5.3'])
->alias(AuthorizationCheckerInterface::class, 'security.authorization_checker')
->set('security.token_storage', UsageTrackingTokenStorage::class)
@ -80,6 +81,7 @@ return static function (ContainerConfigurator $container) {
])
->tag('kernel.reset', ['method' => 'disableUsageTracking'])
->tag('kernel.reset', ['method' => 'setToken'])
->tag('container.private', ['package' => 'symfony/security-bundle', 'version' => '5.3'])
->alias(TokenStorageInterface::class, 'security.token_storage')
->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
$user = new InMemoryUser('foo', 'pass');
$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');
$this->assertTrue($security->isGranted('ROLE_USER'));

View File

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