protected function setUp()
 {
     $this->client = static::createClient();
     $this->container = $this->client->getContainer();
     $this->token = $this->createToken();
     $this->container->get('security.context')->setToken($this->token);
     $this->connection = $this->container->get('database_connection');
     if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
         $this->markTestSkipped('This test requires SQLite support in your environment.');
     }
     $options = array('oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'class_table_name' => 'acl_classes', 'sid_table_name' => 'acl_security_identities', 'entry_table_name' => 'acl_entries');
     $schema = new Schema($options);
     foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
         $this->connection->exec($sql);
     }
     $this->manager = $this->container->get('oneup_acl.manager');
     $this->object1 = new SomeObject(1);
     $this->object2 = new SomeObject(2);
     $builder1 = new MaskBuilder();
     $builder1->add('view')->add('create')->add('edit');
     $this->mask1 = $builder1->get();
     $builder2 = new MaskBuilder();
     $builder2->add('delete')->add('undelete');
     $this->mask2 = $builder2->get();
 }
示例#2
0
    /**
     * @see Command
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $connection = $this->container->get('security.acl.dbal.connection');
        $sm = $connection->getSchemaManager();
        $tableNames = $sm->listTableNames();
        $tables = array(
            'class_table_name' => $this->container->getParameter('security.acl.dbal.class_table_name'),
            'sid_table_name'   => $this->container->getParameter('security.acl.dbal.sid_table_name'),
            'oid_table_name'   => $this->container->getParameter('security.acl.dbal.oid_table_name'),
            'oid_ancestors_table_name' => $this->container->getParameter('security.acl.dbal.oid_ancestors_table_name'),
            'entry_table_name' => $this->container->getParameter('security.acl.dbal.entry_table_name'),
        );

        foreach ($tables as $table) {
            if (in_array($table, $tableNames, true)) {
                $output->writeln(sprintf('The table "%s" already exists. Aborting.', $table));

                return;
            }
        }

        $schema = new Schema($tables);
        foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
            $connection->exec($sql);
        }

        $output->writeln('ACL tables have been initialized successfully.');
    }
 protected function setUp()
 {
     if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
         self::markTestSkipped('This test requires SQLite support in your environment');
     }
     $this->con = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
     // import the schema
     $schema = new Schema($this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
     $this->sid = UserSecurityIdentity::fromAccount(new User('jimmy', 'jimmypass'));
     $this->aclProvider = $this->getProvider();
 }
 protected function createDB()
 {
     $schema = new Schema($this->tableNames);
     foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
         $this->connection->exec($sql);
     }
 }
 /**
  * This generates a huge amount of test data to be used mainly for benchmarking
  * purposes, not so much for testing. That's why it's not called by default.
  */
 protected function generateTestData()
 {
     $sm = $this->con->getSchemaManager();
     $sm->dropAndCreateDatabase('testdb');
     $this->con->exec("USE testdb");
     // import the schema
     $schema = new Schema($options = $this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
     // setup prepared statements
     $this->insertClassStmt = $this->con->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
     $this->insertSidStmt = $this->con->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
     $this->insertOidStmt = $this->con->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
     $this->insertEntryStmt = $this->con->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
     $this->insertOidAncestorStmt = $this->con->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
     for ($i = 0; $i < 40000; $i++) {
         $this->generateAclHierarchy();
     }
 }
示例#6
0
/*
 * This file is part of the Symfony framework.
 *
 * (c) Fabien Potencier <*****@*****.**>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */
require_once __DIR__ . '/../../../../ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Security\Acl\Dbal\Schema;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => __DIR__ . '/../../../../../..', 'Doctrine\\Common' => __DIR__ . '/../../../../../../../vendor/doctrine-common/lib', 'Doctrine\\DBAL\\Migrations' => __DIR__ . '/../../../../../../../vendor/doctrine-migrations/lib', 'Doctrine\\DBAL' => __DIR__ . '/../../../../../../../vendor/doctrine-dbal/lib', 'Doctrine' => __DIR__ . '/../../../../../../../vendor/doctrine/lib'));
$loader->register();
$schema = new Schema(array('class_table_name' => 'acl_classes', 'entry_table_name' => 'acl_entries', 'oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'sid_table_name' => 'acl_security_identities'));
$reflection = new ReflectionClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
$finder = new Finder();
$finder->name('*Platform.php')->in(dirname($reflection->getFileName()));
foreach ($finder as $file) {
    require_once $file->getPathName();
    $className = 'Doctrine\\DBAL\\Platforms\\' . $file->getBasename('.php');
    $reflection = new ReflectionClass($className);
    if ($reflection->isAbstract()) {
        continue;
    }
    $platform = $reflection->newInstance();
    $targetFile = sprintf(__DIR__ . '/../schema/%s.sql', $platform->name);
    file_put_contents($targetFile, implode("\n\n", $schema->toSql($platform)));
}
示例#7
0
 protected function setUp()
 {
     $this->con = DriverManager::getConnection(array('driver' => 'pdo_sqlite', 'memory' => true));
     // import the schema
     $schema = new Schema($options = $this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
     // populate the schema with some test data
     $this->insertClassStmt = $this->con->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
     foreach ($this->getClassData() as $data) {
         $this->insertClassStmt->execute($data);
     }
     $this->insertSidStmt = $this->con->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
     foreach ($this->getSidData() as $data) {
         $this->insertSidStmt->execute($data);
     }
     $this->insertOidStmt = $this->con->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
     foreach ($this->getOidData() as $data) {
         $this->insertOidStmt->execute($data);
     }
     $this->insertEntryStmt = $this->con->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
     foreach ($this->getEntryData() as $data) {
         $this->insertEntryStmt->execute($data);
     }
     $this->insertOidAncestorStmt = $this->con->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
     foreach ($this->getOidAncestorData() as $data) {
         $this->insertOidAncestorStmt->execute($data);
     }
 }
 protected function setUp()
 {
     $this->con = DriverManager::getConnection(array('driver' => 'pdo_sqlite', 'memory' => true));
     // import the schema
     $schema = new Schema($this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
 }
 protected function setUp()
 {
     if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
         self::markTestSkipped('This test requires SQLite support in your environment');
     }
     $this->con = DriverManager::getConnection(array('driver' => 'pdo_sqlite', 'memory' => true));
     // import the schema
     $schema = new Schema($this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
 }
示例#10
0
文件: setUp.php 项目: r4cker/lowbi
 private function creataDatabaseTables()
 {
     //init the database
     $em = $this->em;
     $schemaTool = new Tools\SchemaTool($em);
     $classes = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool->updateSchema($classes, true);
     //install Acl Tables
     $connection = $this->container->get('security.acl.dbal.connection');
     $sm = $connection->getSchemaManager();
     $tableNames = $sm->listTableNames();
     $continue = true;
     $tables = array('class_table_name' => $this->container->getParameter('security.acl.dbal.class_table_name'), 'sid_table_name' => $this->container->getParameter('security.acl.dbal.sid_table_name'), 'oid_table_name' => $this->container->getParameter('security.acl.dbal.oid_table_name'), 'oid_ancestors_table_name' => $this->container->getParameter('security.acl.dbal.oid_ancestors_table_name'), 'entry_table_name' => $this->container->getParameter('security.acl.dbal.entry_table_name'));
     foreach ($tables as $table) {
         if (in_array($table, $tableNames, true)) {
             echo 'The table ' . $table . ' already exists.';
             $continue = false;
             break;
         }
     }
     if ($continue) {
         $schema = new Schema($tables);
         foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
             $connection->exec($sql);
         }
     }
 }
示例#11
0
 protected function setUp()
 {
     if (!class_exists('Doctrine\\DBAL\\DriverManager')) {
         $this->markTestSkipped('The Doctrine2 DBAL is required for this test');
     }
     if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
         self::markTestSkipped('This test requires SQLite support in your environment');
     }
     $this->con = DriverManager::getConnection(array('driver' => 'pdo_sqlite', 'memory' => true));
     // import the schema
     $schema = new Schema($options = $this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
     // populate the schema with some test data
     $this->insertClassStmt = $this->con->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
     foreach ($this->getClassData() as $data) {
         $this->insertClassStmt->execute($data);
     }
     $this->insertSidStmt = $this->con->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
     foreach ($this->getSidData() as $data) {
         $this->insertSidStmt->execute($data);
     }
     $this->insertOidStmt = $this->con->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
     foreach ($this->getOidData() as $data) {
         $this->insertOidStmt->execute($data);
     }
     $this->insertEntryStmt = $this->con->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
     foreach ($this->getEntryData() as $data) {
         $this->insertEntryStmt->execute($data);
     }
     $this->insertOidAncestorStmt = $this->con->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
     foreach ($this->getOidAncestorData() as $data) {
         $this->insertOidAncestorStmt->execute($data);
     }
 }
 protected function setUp()
 {
     if (!class_exists('Doctrine\\DBAL\\DriverManager')) {
         $this->markTestSkipped('The Doctrine2 DBAL is required for this test');
     }
     $this->con = DriverManager::getConnection(array('driver' => 'pdo_sqlite', 'memory' => true));
     // import the schema
     $schema = new Schema($this->getOptions());
     foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
         $this->con->exec($sql);
     }
 }
示例#13
0
 public function resetAclSchema()
 {
     $conn = $this->getEntityManager()->getConnection();
     $tablesMapping = ['class_table_name' => 'acl_classes', 'entry_table_name' => 'acl_entries', 'oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'sid_table_name' => 'acl_security_identities'];
     foreach ($tablesMapping as $tableName) {
         $conn->executeQuery(sprintf('DROP TABLE IF EXISTS %s', $tableName));
     }
     $schema = new Schema($tablesMapping);
     $platform = $conn->getDatabasePlatform();
     foreach ($schema->toSql($platform) as $query) {
         $conn->executeQuery($query);
     }
     return $this;
 }