Index: openacs-4/packages/acs-core-docs/www/permissions-tediously-explained.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/permissions-tediously-explained.html,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-core-docs/www/permissions-tediously-explained.html 28 Feb 2003 05:36:05 -0000 1.3 +++ openacs-4/packages/acs-core-docs/www/permissions-tediously-explained.html 24 Jun 2003 03:58:11 -0000 1.4 @@ -1,7 +1,7 @@ -OpenACS 4.x Permissions Tediously Explained

OpenACS 4.x Permissions Tediously Explained

+OpenACS 4.x Permissions Tediously Explained

OpenACS 4.x Permissions Tediously Explained

by Vadim Nasardinov. Modified and converted to Docbook XML by Roberto Mello -

Overview

+

Overview

The general permissions system has a relatively complex data model in OpenACS 4.x. Developers who haven't had the time to learn the internals of the data model may end up writing seemingly correct code that crashes their system in @@ -86,7 +86,7 @@ to store permission information explicitly about every object, i.e. if the system has 100,000 and 1,000 users who have the read privilege on all objects, then we would need to store 100,000,000 entries of the form: -

Table 7.1.

object_idgrantee_idprivilege
object_id_1user_id_1'read'
object_id_1user_id_2'read'
...
object_id_1user_id_n'read'
object_id_2user_id_1'read'
object_id_2user_id_2'read'
...
object_id_2user_id_n'read'
...
...
object_id_muser_id_1'read'
object_id_muser_id_2'read'
...
object_id_muser_id_n'read'

+

Table�10.1.�

object_idgrantee_idprivilege
object_id_1user_id_1'read'
object_id_1user_id_2'read'
...
object_id_1user_id_n'read'
object_id_2user_id_1'read'
object_id_2user_id_2'read'
...
object_id_2user_id_n'read'
...
...
object_id_muser_id_1'read'
object_id_muser_id_2'read'
...
object_id_muser_id_n'read'

Although quite feasible, this approach fails to take advantage of the fact that objects in the system are commonly organized hierarchally, and permissions usually follow the hierarchical structure, so that if user @@ -98,10 +98,10 @@ necessity to explicitly maintain security information for every single object. There are three kinds of hierarchies involved. These are discussed in the following sections. -

Context Hierarchy

+

Context Hierarchy

Suppose objects A, B, ..., and F form the following hierarchy. -

Table 7.2.

A

+

Table�10.2.�

A

object_id=10

B

object_id=20 @@ -117,23 +117,23 @@ This can be represented in the acs_objects table by the following entries: -

Table 7.3.

object_idcontext_id
2010
3010
4020
5020
6030

+

Table�10.3.�

object_idcontext_id
2010
3010
4020
5020
6030

The first entry tells us that object 20 is the descendant of object 10, and the third entry shows that object 40 is the descendant of object 20. By running a CONNECT BY query, we can compute that object 40 is the second-generation descendant of object 10. With this in mind, if we want to record the fact that user Joe has the read privilege on objects A, ..., F, we only need to record one entry in the acs_permissions table. -

Table 7.4.

objectgranteeprivilege
AJoeread

+

Table�10.4.�

objectgranteeprivilege
AJoeread

The fact that Joe can also read B, C, ..., and F can be derived by ascertaining that these objects are children of A by traversing the context hierarchy. As it turns out, hierarchical queries are expensive. As Rafael Schloming put it so aptly, Oracle can't deal with hierarchies for shit.

One way to solve this problem is to cache a flattened view of the context tree like so: -

Table 7.5.

objectancestorn_generations
AA0
BB0
BA1
CC0
CA1
DD0
DB1
DA2
EE0
EB1
EA2
FF0
FC1
FA2

+

Table�10.5.�

objectancestorn_generations
AA0
BB0
BA1
CC0
CA1
DD0
DB1
DA2
EE0
EB1
EA2
FF0
FC1
FA2

Note that the number of entries in the flattened view grows exponentially with respect to the depth of the context tree. For instance, if you have a fully populated binary tree with a depth of n, then the number of entries @@ -163,9 +163,9 @@ an index-organized table, which means it is substantially optimized for access by primary key. Number two, as the above computations suggest, the size of the table - grows polynomially + grows polynomially with respect to the average number of descendants that an object - has, and exponentially + has, and exponentially with respect to the depth of the context tree.

The acs_object_context_index is kept in sync with the @@ -204,7 +204,7 @@ an object's security_inherit_p column to 'f', you can stop permissions from cascading down the context tree. In the following example, Joe does not have the read permissions on C and F. -

Table 7.6.


+

Table�10.6.�


A
object_id=10
readable�by�Joe
@@ -228,11 +228,11 @@ object_id=60
security_inherit_p�=�'f'
not�readable�by�Joe
- ������

Privilege Hierarchy

+ ������

Privilege Hierarchy

Privileges are also organized hierarchically. In addition to the five main system privileges defined in the ACS Kernel data model, application developers may define their own. For instance, the Bboard package defines the following privileges: -

Table 7.7.

privilege
create_category
create_forum
create_message
delete_category
delete_forum
delete_message
moderate_forum
read_category
read_forum
read_message
write_category
write_forum
write_message

+

Table�10.7.�

privilege
create_category
create_forum
create_message
delete_category
delete_forum
delete_message
moderate_forum
read_category
read_forum
read_message
write_category
write_forum
write_message

By defining parent-child relationship between privileges, the OpenACS data model makes it easier for developers to manage permissions. Instead of granting a user explicit read, write, delete, @@ -241,7 +241,7 @@ privilege to which the first four privileges are tied. To give a more detailed example, the Bboard privileges are structured as follows. -

Table 7.8.

admin
createdeletereadwritemoderate forum
create categorycreate forumcreate messagedelete categorydelete forumdelete messageread categoryread forumread messagewrite categorywrite forumwrite message

+

Table�10.8.�

admin
createdeletereadwritemoderate forum
create categorycreate forumcreate messagedelete categorydelete forumdelete messageread categoryread forumread messagewrite categorywrite forumwrite message

The parent-child relationship between privileges is represented in the acs_privilege_hierarchy table:

@@ -284,10 +284,10 @@
       reasonably small, there is no pressing need to cache the flattened ansector-descendant
       view of the privilege hierarchy in a specially maintained table like
       it is done in the case of the context hierarchy.
-    

Party Hierarchy

+

Party Hierarchy

Now for the third hierarchy playing a promiment role in the permission system. The party data model is set up as follows. -

+    

   create table parties (
       party_id
           not null
@@ -371,7 +371,7 @@
     

The acs_rels table entries would look like so: -

Table 7.10.

rel_typeobject_oneobject_two
+

Table�10.10.�

rel_typeobject_oneobject_two
membership_rel Pranksters @@ -393,7 +393,7 @@ Another way of building up groups is by adding subgroups. Suppose we define Merry Pranksters and Sad Pranksters as subgroups of Pranksters. We say that the Pranksters group - is composed of + is composed of groups Merry Pranksters and Sad Pranksters. This information is stored in the acs_rels and composition_rels tables. @@ -406,7 +406,7 @@

The relevant entries in the acs_rels look like so. -

Table 7.11.

rel_typeobject_oneobject_two
+

Table�10.11.�

rel_typeobject_oneobject_two
composition_rel Pranksters @@ -535,7 +535,7 @@ membership relationship resolution can be computed trivially with no hierarchical queries involved. There is no need to keep the view in a denormalized table, unless doing so results in substantial performance gains. -

Putting It All Together

+

Putting It All Together

Security information is queried by calling the acs_permission.permission_p function in OpenACS 4.x.

  
@@ -617,7 +617,7 @@
     

Note that in the above example, acs_permissions had only one entry that needed to be deleted: -

Table 7.12.

object_idgrantee_idprivilege
+

Table�10.12.�

object_idgrantee_idprivilege
default_context registered_users @@ -627,7 +627,7 @@ The above script would never get around to deleting this entry because it had to loop through a gazillion rows in the humongous acs_object_party_privilege_map view. -

Appendix: Various View Definitions

+    

Appendix: Various View Definitions

 create or replace view acs_object_party_privilege_map
 as
 select
@@ -690,4 +690,4 @@
   container_id
 from
   group_member_index;
-    
View comments on this page at openacs.org
+
View comments on this page at openacs.org