Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3b7dc5

Browse files
author
Robin Chalas
committed
[SecurityBundle] Deprecate ACL related code
1 parent 477a24d commit e3b7dc5

14 files changed

+315
-46
lines changed

UPGRADE-3.4.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,11 @@ SecurityBundle
264264
`Doctrine\DBAL\Connection` as first argument. Not passing it is
265265
deprecated and will throw a `TypeError` in 4.0.
266266

267-
* `SetAclCommand::__construct()` now takes an instance of
268-
`Symfony\Component\Security\Acl\Model\MutableAclProviderInterfaceConnection`
269-
as first argument. Not passing it is deprecated and will throw a `TypeError`
270-
in 4.0.
267+
* The `acl:set` command has been deprecated along with the `SetAclCommand` class,
268+
both will be removed in 4.0. Install symfony/acl-bundle instead
269+
270+
* The `init:acl` command has been deprecated along with the `InitAclCommand` class,
271+
both will be removed in 4.0. Install symfony/acl-bundle and use `acl:init` instead
271272

272273
* Added `logout_on_user_change` to the firewall options. This config item will
273274
trigger a logout when the user has changed. Should be set to true to avoid

UPGRADE-4.0.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,9 @@ SecurityBundle
656656

657657
* `UserPasswordEncoderCommand` does not extend `ContainerAwareCommand` nor implement `ContainerAwareInterface` anymore.
658658

659-
* `InitAclCommand::__construct()` now requires an instance of
660-
`Doctrine\DBAL\Connection` as first argument.
659+
* `InitAclCommand` has been removed. Use `Symfony\Bundle\AclBundle\Command\InitAclCommand` instead
661660

662-
* `SetAclCommand::__construct()` now requires an instance of
663-
`Symfony\Component\Security\Acl\Model\MutableAclProviderInterfaceConnection`
664-
as first argument.
661+
* `SetAclCommand` has been removed. Use `Symfony\Bundle\AclBundle\Command\SetAclCommand` instead
665662

666663
* The firewall option `logout_on_user_change` is now always true, which will
667664
trigger a logout if the user changes between requests.

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ CHANGELOG
88
`VoterInterface` on the class is now deprecated and will be removed in 4.0.
99
* [BC BREAK] `FirewallContext::getListeners()` now returns `\Traversable|array`
1010
* added info about called security listeners in profiler
11-
* `InitAclCommand::__construct()` now takes an instance of
12-
`Doctrine\DBAL\Connection` as first argument
13-
* `SetAclCommand::__construct()` now takes an instance of
14-
`Symfony\Component\Security\Acl\Model\MutableAclProviderInterfaceConnection`
15-
as first argument
1611
* Added `logout_on_user_change` to the firewall options. This config item will
1712
trigger a logout when the user has changed. Should be set to true to avoid
1813
deprecations in the configuration.
14+
* deprecated command `acl:set` along with `SetAclCommand` class
15+
* deprecated command `init:acl` along with `InitAclCommand` class
1916

2017
3.3.0
2118
-----

src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Command;
1313

14+
@trigger_error(sprintf('Class "%s" is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Bundle\AclBundle\Command\SetAclCommand instead.', SetAclCommand::class), E_USER_DEPRECATED);
15+
1416
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1517
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1619
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Style\SymfonyStyle;
1721
use Symfony\Component\Security\Acl\Dbal\Schema;
1822
use Doctrine\DBAL\Connection;
1923
use Doctrine\DBAL\Schema\SchemaException;
@@ -23,7 +27,7 @@
2327
*
2428
* @author Johannes M. Schmitt <[email protected]>
2529
*
26-
* @final since version 3.4
30+
* @deprecated since version 3.4, to be removed in 4.0. See Symfony\Bundle\AclBundle\Command\SetAclCommand instead.
2731
*/
2832
class InitAclCommand extends ContainerAwareCommand
2933
{
@@ -32,15 +36,9 @@ class InitAclCommand extends ContainerAwareCommand
3236
private $connection;
3337
private $schema;
3438

35-
/**
36-
* @param Connection $connection
37-
* @param Schema $schema
38-
*/
3939
public function __construct($connection = null, Schema $schema = null)
4040
{
4141
if (!$connection instanceof Connection) {
42-
@trigger_error(sprintf('%s() expects an instance of "%s" as first argument since version 3.4. Not passing it is deprecated and will throw a TypeError in 4.0.', __METHOD__, Connection::class), E_USER_DEPRECATED);
43-
4442
parent::__construct($connection);
4543

4644
return;
@@ -54,8 +52,6 @@ public function __construct($connection = null, Schema $schema = null)
5452

5553
/**
5654
* {@inheritdoc}
57-
*
58-
* BC to be removed in 4.0
5955
*/
6056
public function isEnabled()
6157
{
@@ -93,7 +89,8 @@ protected function configure()
9389
*/
9490
protected function execute(InputInterface $input, OutputInterface $output)
9591
{
96-
// BC to be removed in 4.0
92+
(new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output))->warning('Command "init:acl" is deprecated since version 3.4 and will be removed from SecurityBundle in 4.0. Install symfony/acl-bundle and use "acl:init" instead.');
93+
9794
if (null === $this->connection) {
9895
$this->connection = $this->getContainer()->get('security.acl.dbal.connection');
9996
$this->schema = $this->getContainer()->get('security.acl.dbal.schema');

src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Command;
1313

14+
@trigger_error(sprintf('Class "%s" is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Bundle\AclBundle\Command\SetAclCommand instead.', SetAclCommand::class), E_USER_DEPRECATED);
15+
1416
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1517
use Symfony\Component\Console\Input\InputArgument;
1618
use Symfony\Component\Console\Input\InputInterface;
1719
use Symfony\Component\Console\Input\InputOption;
20+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1821
use Symfony\Component\Console\Output\OutputInterface;
22+
use Symfony\Component\Console\Style\SymfonyStyle;
1923
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
2024
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
2125
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
@@ -28,7 +32,7 @@
2832
*
2933
* @author Kévin Dunglas <[email protected]>
3034
*
31-
* @final since version 3.4
35+
* @deprecated since version 3.4, to be removed in 4.0. See Symfony\Bundle\AclBundle\Command\SetAclCommand instead.
3236
*/
3337
class SetAclCommand extends ContainerAwareCommand
3438
{
@@ -42,8 +46,6 @@ class SetAclCommand extends ContainerAwareCommand
4246
public function __construct($provider = null)
4347
{
4448
if (!$provider instanceof MutableAclProviderInterface) {
45-
@trigger_error(sprintf('%s() expects an instance of "%s" as first argument since version 3.4. Not passing it is deprecated and will throw a TypeError in 4.0.', __METHOD__, MutableAclProviderInterface::class), E_USER_DEPRECATED);
46-
4749
parent::__construct($provider);
4850

4951
return;
@@ -56,8 +58,6 @@ public function __construct($provider = null)
5658

5759
/**
5860
* {@inheritdoc}
59-
*
60-
* BC to be removed in 4.0
6161
*/
6262
public function isEnabled()
6363
{
@@ -117,7 +117,8 @@ protected function configure()
117117
*/
118118
protected function execute(InputInterface $input, OutputInterface $output)
119119
{
120-
// BC to be removed in 4.0
120+
(new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output))->warning('Command "acl:set" is deprecated since version 3.4 and will be removed from SecurityBundle in 4.0. Install symfony/acl-bundle to use this command.');
121+
121122
if (null === $this->provider) {
122123
$this->provider = $this->getContainer()->get('security.acl.provider');
123124
}
@@ -192,8 +193,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
192193
/**
193194
* Gets the mask builder.
194195
*
195-
* BC to be removed in 4.0
196-
*
197196
* @return MaskBuilder
198197
*/
199198
protected function getMaskBuilder()

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ private function addAclSection(ArrayNodeDefinition $rootNode)
121121
$rootNode
122122
->children()
123123
->arrayNode('acl')
124+
->setDeprecated('The "security.acl" configuration key is deprecated since version 3.4 and will be removed in 4.0. Install symfony/acl-bundle and use the "acl" key instead.')
124125
->children()
125126
->scalarNode('connection')
126127
->defaultNull()

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
abstract class CompleteConfigurationTest extends TestCase
2424
{
25-
private static $containerCache = array();
26-
2725
abstract protected function getLoader(ContainerBuilder $container);
2826

2927
abstract protected function getFileExtension();
@@ -38,6 +36,20 @@ public function testRolesHierarchy()
3836
), $container->getParameter('security.role_hierarchy.roles'));
3937
}
4038

39+
/**
40+
* @group legacy
41+
* @expectedDeprecation The "security.acl" configuration key is deprecated since version 3.4 and will be removed in 4.0. Install symfony/acl-bundle and use the "acl" key instead.
42+
*/
43+
public function testRolesHierarchyWithAcl()
44+
{
45+
$container = $this->getContainer('container1_with_acl');
46+
$this->assertEquals(array(
47+
'ROLE_ADMIN' => array('ROLE_USER'),
48+
'ROLE_SUPER_ADMIN' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'),
49+
'ROLE_REMOTE' => array('ROLE_USER', 'ROLE_ADMIN'),
50+
), $container->getParameter('security.role_hierarchy.roles'));
51+
}
52+
4153
public function testUserProviders()
4254
{
4355
$container = $this->getContainer('container1');
@@ -314,14 +326,22 @@ public function testEncoders()
314326
)), $container->getDefinition('security.encoder_factory.generic')->getArguments());
315327
}
316328

329+
/**
330+
* @group legacy
331+
* @expectedDeprecation The "security.acl" configuration key is deprecated since version 3.4 and will be removed in 4.0. Install symfony/acl-bundle and use the "acl" key instead.
332+
*/
317333
public function testAcl()
318334
{
319-
$container = $this->getContainer('container1');
335+
$container = $this->getContainer('container1_with_acl');
320336

321337
$this->assertTrue($container->hasDefinition('security.acl.dbal.provider'));
322338
$this->assertEquals('security.acl.dbal.provider', (string) $container->getAlias('security.acl.provider'));
323339
}
324340

341+
/**
342+
* @group legacy
343+
* @expectedDeprecation The "security.acl" configuration key is deprecated since version 3.4 and will be removed in 4.0. Install symfony/acl-bundle and use the "acl" key instead.
344+
*/
325345
public function testCustomAclProvider()
326346
{
327347
$container = $this->getContainer('custom_acl_provider');
@@ -421,9 +441,6 @@ protected function getContainer($file)
421441
{
422442
$file = $file.'.'.$this->getFileExtension();
423443

424-
if (isset(self::$containerCache[$file])) {
425-
return self::$containerCache[$file];
426-
}
427444
$container = new ContainerBuilder();
428445
$security = new SecurityExtension();
429446
$container->registerExtension($security);
@@ -436,6 +453,6 @@ protected function getContainer($file)
436453
$container->getCompilerPassConfig()->setRemovingPasses(array());
437454
$container->compile();
438455

439-
return self::$containerCache[$file] = $container;
456+
return $container;
440457
}
441458
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
$container->loadFromExtension('security', array(
4-
'acl' => array(),
54
'encoders' => array(
65
'JMS\FooBundle\Entity\User1' => 'plaintext',
76
'JMS\FooBundle\Entity\User2' => array(
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', array(
4+
'acl' => array(),
5+
'encoders' => array(
6+
'JMS\FooBundle\Entity\User1' => 'plaintext',
7+
'JMS\FooBundle\Entity\User2' => array(
8+
'algorithm' => 'sha1',
9+
'encode_as_base64' => false,
10+
'iterations' => 5,
11+
),
12+
'JMS\FooBundle\Entity\User3' => array(
13+
'algorithm' => 'md5',
14+
),
15+
'JMS\FooBundle\Entity\User4' => array(
16+
'id' => 'security.encoder.foo',
17+
),
18+
'JMS\FooBundle\Entity\User5' => array(
19+
'algorithm' => 'pbkdf2',
20+
'hash_algorithm' => 'sha1',
21+
'encode_as_base64' => false,
22+
'iterations' => 5,
23+
'key_length' => 30,
24+
),
25+
'JMS\FooBundle\Entity\User6' => array(
26+
'algorithm' => 'bcrypt',
27+
'cost' => 15,
28+
),
29+
),
30+
'providers' => array(
31+
'default' => array(
32+
'memory' => array(
33+
'users' => array(
34+
'foo' => array('password' => 'foo', 'roles' => 'ROLE_USER'),
35+
),
36+
),
37+
),
38+
'digest' => array(
39+
'memory' => array(
40+
'users' => array(
41+
'foo' => array('password' => 'foo', 'roles' => 'ROLE_USER, ROLE_ADMIN'),
42+
),
43+
),
44+
),
45+
'basic' => array(
46+
'memory' => array(
47+
'users' => array(
48+
'foo' => array('password' => '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', 'roles' => 'ROLE_SUPER_ADMIN'),
49+
'bar' => array('password' => '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', 'roles' => array('ROLE_USER', 'ROLE_ADMIN')),
50+
),
51+
),
52+
),
53+
'service' => array(
54+
'id' => 'user.manager',
55+
),
56+
'chain' => array(
57+
'chain' => array(
58+
'providers' => array('service', 'basic'),
59+
),
60+
),
61+
),
62+
63+
'firewalls' => array(
64+
'simple' => array('pattern' => '/login', 'security' => false),
65+
'secure' => array('stateless' => true,
66+
'http_basic' => true,
67+
'http_digest' => array('secret' => 'TheSecret'),
68+
'form_login' => true,
69+
'anonymous' => true,
70+
'switch_user' => true,
71+
'x509' => true,
72+
'remote_user' => true,
73+
'logout' => true,
74+
'remember_me' => array('secret' => 'TheSecret'),
75+
'user_checker' => null,
76+
),
77+
'host' => array(
78+
'pattern' => '/test',
79+
'host' => 'foo\\.example\\.org',
80+
'methods' => array('GET', 'POST'),
81+
'anonymous' => true,
82+
'http_basic' => true,
83+
),
84+
'with_user_checker' => array(
85+
'user_checker' => 'app.user_checker',
86+
'anonymous' => true,
87+
'http_basic' => true,
88+
),
89+
),
90+
91+
'access_control' => array(
92+
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https', 'methods' => array('get', 'POST')),
93+
array('path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'),
94+
array('path' => '/blog/524', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY', 'allow_if' => "token.getUsername() matches '/^admin/'"),
95+
),
96+
97+
'role_hierarchy' => array(
98+
'ROLE_ADMIN' => 'ROLE_USER',
99+
'ROLE_SUPER_ADMIN' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'),
100+
'ROLE_REMOTE' => 'ROLE_USER,ROLE_ADMIN',
101+
),
102+
));

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
77

88
<config>
9-
<acl />
10-
119
<encoder class="JMS\FooBundle\Entity\User1" algorithm="plaintext" />
1210

1311
<encoder class="JMS\FooBundle\Entity\User2" algorithm="sha1" encode-as-base64="false" iterations="5" />

0 commit comments

Comments
 (0)