10000 Continuation of #23624 by ro0NL · Pull Request #23801 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Continuation of #23624 #23801

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
finalized securitybundle
  • Loading branch information
ro0NL committed Aug 6, 2017
commit 0f302777c4ff290520cc331b095514e87dbbbb95
45 changes: 38 additions & 7 deletions src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\SchemaException;

/**
Expand All @@ -25,11 +27,39 @@
*/
class InitAclCommand extends ContainerAwareCommand
{
private $connection;
private $schema;

/**
* @param Connection $connection
* @param Schema $schema
*/
public function __construct($connection = null, Schema $schema = null)
{
if (!$connection instanceof Connection) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);

parent::__construct($connection);

return;
}

parent::__construct();

$this->connection = $connection;
$this->schema = $schema;
}

/**
* {@inheritdoc}
*
* BC to be removed in 4.0
*/
public function isEnabled()
{
if (null !== $this->connection) {
return parent::isEnabled();
}
if (!$this->getContainer()->has('security.acl.dbal.connection')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!$this->connection && ..) instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ro0NL ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return false;
}
Expand Down Expand Up @@ -65,21 +95,22 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();

$connection = $container->get('security.acl.dbal.connection');
$schema = $container->get('security.acl.dbal.schema');
// BC to be removed in 4.0
if (null === $this->connection) {
$this->connection = $this->getContainer()->get('security.acl.dbal.connection');
$this->schema = $this->getContainer()->get('security.acl.dbal.schema');
}

try {
$schema->addToSchema($connection->getSchemaManager()->createSchema());
$this->schema->addToSchema($this->connection->getSchemaManager()->createSchema());
} catch (SchemaException $e) {
$output->writeln('Aborting: '.$e->getMessage());

return 1;
}

foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
$connection->exec($sql);
foreach ($this->schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->exec($sql);
}

$output->writeln('ACL tables have been initialized successfully.');
Expand Down
43 changes: 35 additions & 8 deletions src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,36 @@
*/
class SetAclCommand extends ContainerAwareCommand
{
private $provider;

/**
* @param MutableAclProviderInterface $provider
*/
public function __construct($provider = null)
{
if (!$provider instanceof MutableAclProviderInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);

parent::__construct($provider);

return;
}

parent::__construct();

$this->provider = $provider;
}

/**
* {@inheritdoc}
*
* BC to be removed in 4.0
*/
public function isEnabled()
{
if (null !== $this->provider) {
return parent::isEnabled();
}
if (!$this->getContainer()->has('security.acl.provider')) {
return false;
}
Expand Down Expand Up @@ -91,6 +116,11 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// BC to be removed in 4.0
if (null === $this->provider) {
$this->provider = $this->getContainer()->get('security.acl.provider');
}

// Parse arguments
$objectIdentities = array();
$maskBuilder = $this->getMaskBuilder();
Expand Down Expand Up @@ -136,20 +166,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

/** @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
$container = $this->getContainer();
/** @var $aclProvider MutableAclProviderInterface */
$aclProvider = $container->get('security.acl.provider');

// Sets ACL
foreach ($objectIdentities as $objectIdentity) {
// Creates a new ACL if it does not already exist
try {
$aclProvider->createAcl($objectIdentity);
$this->provider->createAcl($objectIdentity);
} catch (AclAlreadyExistsException $e) {
}

$acl = $aclProvider->findAcl($objectIdentity, $securityIdentities);
$acl = $this->provider->findAcl($objectIdentity, $securityIdentities);

foreach ($securityIdentities as $securityIdentity) {
if ($classScopeOption) {
Expand All @@ -159,13 +184,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$aclProvider->updateAcl($acl);
$this->provider->updateAcl($acl);
}
}

/**
* Gets the mask builder.
*
* BC to be removed in 4.0
*
* @return MaskBuilder
*/
protected function getMaskBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Bundle\SecurityBundle\DependencyInjection;

use Symfony\Bundle\SecurityBundle\Command\InitAclCommand;
use Symfony\Bundle\SecurityBundle\Command\SetAclCommand;
use Symfony\Bundle\SecurityBundle\Command\UserPasswordEncoderCommand;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
Expand Down Expand Up @@ -114,6 +116,9 @@ public function load(array $configs, ContainerBuilder $container)
// load ACL
if (isset($config['acl'])) {
$this->aclLoad($config['acl'], $container);
} else {
$container->removeDefinition(InitAclCommand::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken if console not available, should go in the previous if (console.xml loading) and acl loading be moved just before console loading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure.. removeDefinition is non-fatal. Did this for translations, routing, etc. as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair

$container->removeDefinition(SetAclCommand::class);
}

$container->registerForAutoconfiguration(VoterInterface::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
<defaults public="false" />

<service id="Symfony\Bundle\SecurityBundle\Command\InitAclCommand">
<argument type="service" id="security.acl.dbal.connection" />
<argument type="service" id="security.acl.dbal.schema" />
<tag name="console.command" command="init:acl" />
</service>

<service id="Symfony\Bundle\SecurityBundle\Command\SetAclCommand">
<argument type="service" id="security.acl.provider" />
<tag name="console.command" command="acl:set" />
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testSetAclRole()
$role = 'ROLE_ADMIN';

$application = $this->getApplication();
$application->add(new SetAclCommand());
$application->add(new SetAclCommand($application->getKernel()->getContainer()->get('security.acl.provider')));

$setAclCommand = $application->find('acl:set');
$setAclCommandTester = new CommandTester($setAclCommand);
Expand Down Expand Up @@ -138,7 +138,7 @@ public function testSetAclClassScope()
$role = 'ROLE_USER';

$application = $this->getApplication();
$application->add(new SetAclCommand());
$application->add(new SetAclCommand($application->getKernel()->getContainer()->get('security.acl.provider')));

$setAclCommand = $application->find('acl:set');
$setAclCommandTester = new CommandTester($setAclCommand);
Expand Down Expand Up @@ -170,7 +170,7 @@ private function getApplication()
$kernel->boot();

4DBF $application = new Application($kernel);
$application->add(new InitAclCommand());
$application->add(new InitAclCommand($kernel->getContainer()->get('security.acl.dbal.connection'), $kernel->getContainer()->get('security.acl.dbal.schema')));

$initAclCommand = $application->find('init:acl');
$initAclCommandTester = new CommandTester($initAclCommand);
Expand Down
0