Skip to content

Commit 0aa6719

Browse files
committed
[SecurityBundle] Deprecate XML-configured custom authenticators and providers under security namespace
1 parent c3bb47a commit 0aa6719

File tree

6 files changed

+55
-18
lines changed

6 files changed

+55
-18
lines changed

UPGRADE-7.2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Security
4242
* Deprecate passing an empty string as `$userIdentifier` argument to `UserBadge` constructor
4343
* Deprecate returning an empty string in `UserInterface::getUserIdentifier()`
4444

45+
SecurityBundle
46+
--------------
47+
48+
* Deprecate XML-configured custom authenticators and providers under security namespace
49+
4550
Serializer
4651
----------
4752

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Allow configuring the secret used to sign login links
8+
* Deprecate XML-configured custom authenticators and providers under security namespace
89

910
7.1
1011
---

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCustomAuthenticatorTest.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
1617
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\Authenticator\CustomAuthenticator;
17-
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\CustomProvider;
1818
use Symfony\Component\Config\FileLocator;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2121

2222
class XmlCustomAuthenticatorTest extends TestCase
2323
{
24+
use ExpectDeprecationTrait;
25+
2426
/**
25-
* @dataProvider provideXmlConfigurationFile
27+
* @group legacy
2628
*/
27-
public function testCustomProviderElement(string $configurationFile)
29+
public function testCustomAuthenticatorElementUnderSecurityNamespace()
2830
{
2931
$container = new ContainerBuilder();
3032
$container->setParameter('kernel.debug', false);
@@ -34,18 +36,30 @@ public function testCustomProviderElement(string $configurationFile)
3436
$security->addAuthenticatorFactory(new CustomAuthenticator());
3537
$container->registerExtension($security);
3638

37-
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load($configurationFile);
39+
$this->expectDeprecation('Since symfony/security-bundle 7.2: Custom authenticators must now be namespaced; please update your security configuration "custom" tag.');
40+
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load('custom_authenticator_under_security_namespace.xml');
3841

3942
$container->getCompilerPassConfig()->setRemovingPasses([]);
4043
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
4144
$container->compile();
42-
43-
$this->addToAssertionCount(1);
4445
}
4546

46-
public static function provideXmlConfigurationFile(): iterable
47+
public function testCustomAuthenticatorElementUnderOwnNamespace()
4748
{
48-
yield 'Custom authenticator element under SecurityBundle’s namespace' => ['custom_authenticator_under_security_namespace.xml'];
49-
yield 'Custom authenticator element under its own namespace' => ['custom_authenticator_under_own_namespace.xml'];
49+
$container = new ContainerBuilder();
50+
$container->setParameter('kernel.debug', false);
51+
$container->register('cache.system', \stdClass::class);
52+
53+
$security = new SecurityExtension();
54+
$security->addAuthenticatorFactory(new CustomAuthenticator());
55+
$container->registerExtension($security);
56+
57+
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load('custom_authenticator_under_own_namespace.xml');
58+
59+
$container->getCompilerPassConfig()->setRemovingPasses([]);
60+
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
61+
$container->compile();
62+
63+
$this->addToAssertionCount(1);
5064
}
5165
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCustomProviderTest.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
1617
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\CustomProvider;
1718
use Symfony\Component\Config\FileLocator;
@@ -20,10 +21,12 @@
2021

2122
class XmlCustomProviderTest extends TestCase
2223
{
24+
use ExpectDeprecationTrait;
25+
2326
/**
24-
* @dataProvider provideXmlConfigurationFile
27+
* @group legacy
2528
*/
26-
public function testCustomProviderElement(string $configurationFile)
29+
public function testCustomProviderElementUnderSecurityNamespace()
2730
{
2831
$container = new ContainerBuilder();
2932
$container->setParameter('kernel.debug', false);
@@ -33,18 +36,30 @@ public function testCustomProviderElement(string $configurationFile)
3336
$security->addUserProviderFactory(new CustomProvider());
3437
$container->registerExtension($security);
3538

36-
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load($configurationFile);
39+
$this->expectDeprecation('Since symfony/security-bundle 7.2: Custom providers must now be namespaced; please update your security configuration "custom" tag.');
40+
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load('custom_provider_under_security_namespace.xml');
3741

3842
$container->getCompilerPassConfig()->setRemovingPasses([]);
3943
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
4044
$container->compile();
41-
42-
$this->addToAssertionCount(1);
4345
}
4446

45-
public static function provideXmlConfigurationFile(): iterable
47+
public function testCustomProviderElementUnderOwnNamespace()
4648
{
47-
yield 'Custom provider element under SecurityBundle’s namespace' => ['custom_provider_under_security_namespace.xml'];
48-
yield 'Custom provider element under its own namespace' => ['custom_provider_under_own_namespace.xml'];
49+
$container = new ContainerBuilder();
50+
$container->setParameter('kernel.debug', false);
51+
$container->register('cache.system', \stdClass::class);
52+
53+
$security = new SecurityExtension();
54+
$security->addUserProviderFactory(new CustomProvider());
55+
$container->registerExtension($security);
56+
57+
(new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml')))->load('custom_provider_under_own_namespace.xml');
58+
59+
$container->getCompilerPassConfig()->setRemovingPasses([]);
60+
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
61+
$container->compile();
62+
63+
$this->addToAssertionCount(1);
4964
}
5065
}

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ext-xml": "*",
2222
"symfony/clock": "^6.4|^7.0",
2323
"symfony/config": "^6.4|^7.0",
24-
"symfony/dependency-injection": "^6.4.11|^7.1.4",
24+
"symfony/dependency-injection": "^7.2",
2525
"symfony/event-dispatcher": "^6.4|^7.0",
2626
"symfony/http-kernel": "^6.4|^7.0",
2727
"symfony/http-foundation": "^6.4|^7.0",

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ private function parseFileToDOM(string $file): \DOMDocument
477477
continue;
478478
}
479479
if ('provider' === $parent->localName || 'firewall' === $parent->localName) {
480+
trigger_deprecation('symfony/security-bundle', '7.2', 'Custom %s must now be namespaced; please update your security configuration "%s" tag.', 'provider' === $parent->localName ? 'providers' : 'authenticators', $tagName);
481+
480482
unset($errors[$errorIndex]);
481483
}
482484
}

0 commit comments

Comments
 (0)