Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "symfony/acl-bundle",
"name": "skydreams/acl-bundle",
"type": "symfony-bundle",
"description": "Symfony AclBundle",
"description": "Symfony AclBundle fork - symfony 7.0 compatibile",
"keywords": [],
"homepage": "https://symfony.com",
"license": "MIT",
Expand All @@ -18,19 +18,19 @@
"require": {
"php": ">=7.2.9",
"ext-xml": "*",
"symfony/dependency-injection": "^4.4|^5.0|^6.0|^7.0",
"symfony/http-kernel": "^4.4|^5.0|^6.0|^7.0",
"symfony/security-acl": "^3.0",
"symfony/security-bundle": "^4.4|^5.0|^6.0|^7.0"
"symfony/dependency-injection": "^7.0|^8.0",
"symfony/http-kernel": "^7.0|^8.0",
"skydreams/security-acl": "*@dev",
"symfony/security-bundle": "^7.0|^8.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.6.12|^2.0",
"doctrine/dbal": "^2.13.1|^3.1",
"doctrine/orm": "^2.7.3",
"symfony/console": "^4.4|^5.0|^6.0|^7.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0|^7.0",
"symfony/phpunit-bridge": "^5.0|^6.0|^7.0",
"symfony/yaml": "^4.4|^5.0|^6.0|^7.0"
"doctrine/orm": "^2.7.3|^3.6",
"symfony/console": "^7.0|^8.0",
"symfony/framework-bundle": "^7.0|^8.0",
"symfony/phpunit-bridge": "^7.0|^8.0",
"symfony/yaml": "^7.0|^8.0"
},
"suggest": {
"doctrine/doctrine-bundle": "To use the default dbal configuration"
Expand Down
32 changes: 10 additions & 22 deletions src/Command/InitAclCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
Expand All @@ -20,33 +22,21 @@
use Symfony\Component\Security\Acl\Dbal\Schema;

/**
* Creates the tables required by the ACL system.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
#[AsCommand(name: 'acl:init', description: 'Creates ACL tables in the database')]
final class InitAclCommand extends Command
{
protected static $defaultName = 'acl:init';

private $connection;
private $schema;

public function __construct(Connection $connection, Schema $schema)
{
public function __construct(
private readonly Connection $connection,
private readonly Schema $schema,
) {
parent::__construct();

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

/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setDescription('Creates ACL tables in the database')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command creates ACL tables in the database.

Expand All @@ -61,17 +51,15 @@ protected function configure(): void
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$this->schema->addToSchema($this->connection->getSchemaManager()->createSchema());
$schemaManager = $this->connection->createSchemaManager();
$this->schema->addToSchema($schemaManager->introspectSchema());
} catch (SchemaException $e) {
$output->writeln('Aborting: '.$e->getMessage());

return 1;
return Command::FAILURE;
}

foreach ($this->schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
Expand All @@ -80,6 +68,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln('ACL tables have been initialized successfully.');

return 0;
return Command::SUCCESS;
}
}
32 changes: 7 additions & 25 deletions src/Command/SetAclCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
Expand All @@ -25,32 +27,20 @@
use Symfony\Component\Security\Acl\Permission\MaskBuilder;

/**
* Sets ACL for objects.
*
* @author Kévin Dunglas <kevin@les-tilleuls.coop>
*/
#[AsCommand(name: 'acl:set', description: 'Sets ACL for objects')]
final class SetAclCommand extends Command
{
protected static $defaultName = 'acl:set';

private $provider;

public function __construct(MutableAclProviderInterface $provider)
public function __construct(private readonly MutableAclProviderInterface $provider)
{
parent::__construct();

$this->provider = $provider;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Sets ACL for objects')
->setHelp(<<<EOF
->setHelp(<<<'EOF'
The <info>%command.name%</info> command sets ACL.
The ACL system must have been initialized with the <info>acl:init</info> command.

Expand Down Expand Up @@ -79,12 +69,8 @@ protected function configure()
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Parse arguments
$objectIdentities = [];
$maskBuilder = new MaskBuilder();
foreach ($input->getArgument('arguments') as $argument) {
Expand All @@ -97,7 +83,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

// Build permissions mask
$mask = $maskBuilder->get();

$userOption = $input->getOption('user');
Expand All @@ -108,7 +93,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new \InvalidArgumentException('A Role or a User must be specified.');
}

// Create security identities
$securityIdentities = [];

if ($userOption) {
Expand All @@ -129,12 +113,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

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

$acl = $this->provider->findAcl($objectIdentity, $securityIdentities);
Expand All @@ -150,6 +132,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->provider->updateAcl($acl);
}

return 0;
return Command::SUCCESS;
}
}
35 changes: 11 additions & 24 deletions src/DependencyInjection/AclExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
Expand All @@ -14,32 +16,27 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Security\Acl\Domain\PsrAclCache;

/**
* AclExtension.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AclExtension extends Extension
final class AclExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$mainConfig = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($mainConfig, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('acl.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('acl.php');

if (class_exists(Application::class)) {
$loader->load('console.xml');
$loader->load('console.php');
}

if (isset($config['cache']['id'])) {
Expand All @@ -61,18 +58,16 @@ public function load(array $configs, ContainerBuilder $container)

$container->getDefinition('security.acl.voter.basic_permissions')->addArgument($config['voter']['allow_if_object_identity_unavailable']);

// custom ACL provider
if (isset($config['provider'])) {
$container->setAlias('security.acl.provider', $config['provider']);

return;
}

// no provider configured
$loader->load('acl_dbal.xml');
$loader->load('acl_dbal.php');

if (null !== $config['connection']) {
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']));
$container->setAlias('security.acl.dbal.connection', \sprintf('doctrine.dbal.%s_connection', $config['connection']));
}

$container
Expand All @@ -92,12 +87,4 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('security.acl.dbal.oid_ancestors_table_name', $config['tables']['object_identity_ancestors']);
$container->setParameter('security.acl.dbal.sid_table_name', $config['tables']['security_identity']);
}

/**
* {@inheritdoc}
*/
public function getNamespace()
{
return 'http://symfony.com/schema/dic/acl';
}
}
13 changes: 4 additions & 9 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
Expand All @@ -15,17 +17,10 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This class contains the configuration information.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree builder.
*
* @return TreeBuilder The tree builder
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$builder = new TreeBuilder('acl');
Expand All @@ -45,7 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('prefix')->defaultValue('sf_acl_')->end()
->end()
->validate()
->ifTrue(static function (array $config): bool { return isset($config['id'], $config['pool']); })
->ifTrue(static fn (array $config): bool => isset($config['id'], $config['pool']))
->thenInvalid('You cannot set both a cache service id and cache pool')
->end()
->end()
Expand Down
14 changes: 6 additions & 8 deletions src/EventListener/AclSchemaListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
Expand All @@ -19,18 +21,14 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AclSchemaListener
final class AclSchemaListener
{
private $schema;

public function __construct(Schema $schema)
public function __construct(private readonly Schema $schema)
{
$this->schema = $schema;
}

public function postGenerateSchema(GenerateSchemaEventArgs $args)
public function postGenerateSchema(GenerateSchemaEventArgs $args): void
{
$schema = $args->getSchema();
$this->schema->addToSchema($schema);
$this->schema->addToSchema($args->getSchema());
}
}
Loading
Loading