|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Security\Acl\Dbal; |
|
|
13 |
|
|
|
14 |
use Doctrine\DBAL\Schema\Schema as BaseSchema; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* The schema used for the ACL system. |
|
|
18 |
* |
|
|
19 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
20 |
*/ |
|
|
21 |
final class Schema extends BaseSchema |
|
|
22 |
{ |
|
|
23 |
protected $options; |
|
|
24 |
|
|
|
25 |
/** |
|
|
26 |
* Constructor |
|
|
27 |
* |
|
|
28 |
* @param array $options the names for tables |
|
|
29 |
* @return void |
|
|
30 |
*/ |
|
|
31 |
public function __construct(array $options) |
|
|
32 |
{ |
|
|
33 |
parent::__construct(); |
|
|
34 |
|
|
|
35 |
$this->options = $options; |
|
|
36 |
|
|
|
37 |
$this->addClassTable(); |
|
|
38 |
$this->addSecurityIdentitiesTable(); |
|
|
39 |
$this->addObjectIdentitiesTable(); |
|
|
40 |
$this->addObjectIdentityAncestorsTable(); |
|
|
41 |
$this->addEntryTable(); |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
/** |
|
|
45 |
* Adds the class table to the schema |
|
|
46 |
* |
|
|
47 |
* @return void |
|
|
48 |
*/ |
|
|
49 |
protected function addClassTable() |
|
|
50 |
{ |
|
|
51 |
$table = $this->createTable($this->options['class_table_name']); |
|
|
52 |
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => 'auto')); |
|
|
53 |
$table->addColumn('class_type', 'string', array('length' => 200)); |
|
|
54 |
$table->setPrimaryKey(array('id')); |
|
|
55 |
$table->addUniqueIndex(array('class_type')); |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
/** |
|
|
59 |
* Adds the entry table to the schema |
|
|
60 |
* |
|
|
61 |
* @return void |
|
|
62 |
*/ |
|
|
63 |
protected function addEntryTable() |
|
|
64 |
{ |
|
|
65 |
$table = $this->createTable($this->options['entry_table_name']); |
|
|
66 |
|
|
|
67 |
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => 'auto')); |
|
|
68 |
$table->addColumn('class_id', 'integer', array('unsigned' => true)); |
|
|
69 |
$table->addColumn('object_identity_id', 'integer', array('unsigned' => true, 'notnull' => false)); |
|
|
70 |
$table->addColumn('field_name', 'string', array('length' => 50, 'notnull' => false)); |
|
|
71 |
$table->addColumn('ace_order', 'smallint', array('unsigned' => true)); |
|
|
72 |
$table->addColumn('security_identity_id', 'integer', array('unsigned' => true)); |
|
|
73 |
$table->addColumn('mask', 'integer'); |
|
|
74 |
$table->addColumn('granting', 'boolean'); |
|
|
75 |
$table->addColumn('granting_strategy', 'string', array('length' => 30)); |
|
|
76 |
$table->addColumn('audit_success', 'boolean'); |
|
|
77 |
$table->addColumn('audit_failure', 'boolean'); |
|
|
78 |
|
|
|
79 |
$table->setPrimaryKey(array('id')); |
|
|
80 |
$table->addUniqueIndex(array('class_id', 'object_identity_id', 'field_name', 'ace_order')); |
|
|
81 |
$table->addIndex(array('class_id', 'object_identity_id', 'security_identity_id')); |
|
|
82 |
|
|
|
83 |
$table->addForeignKeyConstraint($this->getTable($this->options['class_table_name']), array('class_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); |
|
|
84 |
$table->addForeignKeyConstraint($this->getTable($this->options['oid_table_name']), array('object_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); |
|
|
85 |
$table->addForeignKeyConstraint($this->getTable($this->options['sid_table_name']), array('security_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
/** |
|
|
89 |
* Adds the object identity table to the schema |
|
|
90 |
* |
|
|
91 |
* @return void |
|
|
92 |
*/ |
|
|
93 |
protected function addObjectIdentitiesTable() |
|
|
94 |
{ |
|
|
95 |
$table = $this->createTable($this->options['oid_table_name']); |
|
|
96 |
|
|
|
97 |
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => 'auto')); |
|
|
98 |
$table->addColumn('class_id', 'integer', array('unsigned' => true)); |
|
|
99 |
$table->addColumn('object_identifier', 'string', array('length' => 100)); |
|
|
100 |
$table->addColumn('parent_object_identity_id', 'integer', array('unsigned' => true, 'notnull' => false)); |
|
|
101 |
$table->addColumn('entries_inheriting', 'boolean'); |
|
|
102 |
|
|
|
103 |
$table->setPrimaryKey(array('id')); |
|
|
104 |
$table->addUniqueIndex(array('object_identifier', 'class_id')); |
|
|
105 |
$table->addIndex(array('parent_object_identity_id')); |
|
|
106 |
|
|
|
107 |
$table->addForeignKeyConstraint($table, array('parent_object_identity_id'), array('id'), array('onDelete' => 'RESTRICT', 'onUpdate' => 'RESTRICT')); |
|
|
108 |
} |
|
|
109 |
|
|
|
110 |
/** |
|
|
111 |
* Adds the object identity relation table to the schema |
|
|
112 |
* |
|
|
113 |
* @return void |
|
|
114 |
*/ |
|
|
115 |
protected function addObjectIdentityAncestorsTable() |
|
|
116 |
{ |
|
|
117 |
$table = $this->createTable($this->options['oid_ancestors_table_name']); |
|
|
118 |
|
|
|
119 |
$table->addColumn('object_identity_id', 'integer', array('unsigned' => true)); |
|
|
120 |
$table->addColumn('ancestor_id', 'integer', array('unsigned' => true)); |
|
|
121 |
|
|
|
122 |
$table->setPrimaryKey(array('object_identity_id', 'ancestor_id')); |
|
|
123 |
|
|
|
124 |
$oidTable = $this->getTable($this->options['oid_table_name']); |
|
|
125 |
$table->addForeignKeyConstraint($oidTable, array('object_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); |
|
|
126 |
$table->addForeignKeyConstraint($oidTable, array('ancestor_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); |
|
|
127 |
} |
|
|
128 |
|
|
|
129 |
/** |
|
|
130 |
* Adds the security identity table to the schema |
|
|
131 |
* |
|
|
132 |
* @return void |
|
|
133 |
*/ |
|
|
134 |
protected function addSecurityIdentitiesTable() |
|
|
135 |
{ |
|
|
136 |
$table = $this->createTable($this->options['sid_table_name']); |
|
|
137 |
|
|
|
138 |
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => 'auto')); |
|
|
139 |
$table->addColumn('identifier', 'string', array('length' => 200)); |
|
|
140 |
$table->addColumn('username', 'boolean'); |
|
|
141 |
|
|
|
142 |
$table->setPrimaryKey(array('id')); |
|
|
143 |
$table->addUniqueIndex(array('identifier', 'username')); |
|
|
144 |
} |
|
|
145 |
} |