Total Knowledge Projects Jobs Clientele Contact

UU Database

Personal tools
From Total Knowledge
(Difference between revisions)
Jump to: navigation, search
(User Managed Objects (UMOs))
Current revision (13:10, 3 April 2011) (view source)
(HowTo: Find out if person is currently a student of a class)
 
 +
<keywords content="database,design,structure,schema,table,field,university,school,course,study,online,on-line,postgre,postgreSQL,SQL"/>
 +
== '''Database structure requirements''' ==
== '''Database structure requirements''' ==
</OL>
</OL>
-
 
+
===Implementation===
-
== ACL implementation ==
+
* All access to database tables and views is revoked from DB role under which application connects
-
ACL is implemented on per-table basis. For every table covered by ACL, there is a table with the same name appended with "_acl". The ACL tables have similar structure. They contain references to the user (person id) and to the object (object id), accompanied with the access field. An access field is an integer that contains a bit combination of the available access values:
+
* All DML access is granted to role under which stored procedures are created
-
<table border=1 bgcolor="#A0FFA0">
+
* Application user is granted EXECUTE access on all public stored procedures
-
<th>access name</th><th>access value</th><th>Description</th><th> Comments </th>
+
* All public stored procedures are marked as ''SECURITY DEFINER''
-
<tr><td> No access </td><td> 0 or NULL </td><td> User may not have any access to the object </td></tr>
+
* All internal stored procedures are '''not''' marked as ''SECURITY DEFINER''
-
<tr><td> View </td><td> 1 </td><td>User may browse and view the content of the object</td></tr>
+
* Public stored procedures call is_authorized function with relevant access parameters in order to verify user's access to requested object
-
<tr><td> Modify </td><td> 2 </td> <td> User may modify the object but not the object access </td> </tr>
+
* Application will perform ''login'' procedure before any transaction and ''logout'' procedure after. These procedures take care of setting up environment for is_authorized call.
-
<tr><td> Delete </td><td> 4 </td> <td> User may delete the object </td> </tr>
+
-
<tr><td> Grant Access </td><td> 8 </td> <td> User may grant or change access to the object to other user(s) </td> </tr>
+
-
<tr><td> Study </td><td> 16 </td> <td> User (student) may submit his answer or solution of the problem </td> <td> Always set for Open Server </td>  </tr>
+
-
<tr><td> Add Version </td><td> 32 </td> <td> User may create his own version of the object </td> <td> Always set for Open Server </td>  </tr>
+
-
<tr><td> Add Translation </td><td> 64 </td> <td> User may create his own translated version of the object </td> <td> Always set for Open Server </td> </tr>
+
-
<tr><td> Reference </td> <td> 128 </td> <td> User may refer to this object in his objects </td> <td> Always set for Open Server </td>  </tr>
+
-
</table>
+
-
 
+
-
Here is the example of the topic_list_acl table:
+
-
<pre>
+
-
create table topic_list_acl (
+
-
  tla_id serial int primary key,
+
-
  tla_person int references person_list(pl_id),
+
-
  tla_topic int references topic_list(tl_id),
+
-
  tla_access int default 0
+
-
)
+
-
</pre>
+
-
 
+
-
ACL entries are maintained with the single stored procedure acl_set( table_name varchar(40), person int, access int ). Upon execution, stored procedure checks if the user has "Grant Access" right on the object, and if modifies the access for the person. If the required ACL entry doesn't exist it is created.
+
-
 
+
-
ACL entries are performed slightly differently for the open server and proprietary server configurations. For the open server, the special right bits (Study..Reference) are always set, allowing unlimited Study..Reference use.
+
== Database objects ==
== Database objects ==
All UMOs are equal, but some UMOs are more equal than others :) Even though all the UMOs are stored in the database the same way, some of them may have extra actions not typical for others. These actions are implemented as stored UMO-type specific procedures.
All UMOs are equal, but some UMOs are more equal than others :) Even though all the UMOs are stored in the database the same way, some of them may have extra actions not typical for others. These actions are implemented as stored UMO-type specific procedures.
 +
 +
== Security implementation ==
 +
Most modern databases allow to define primitive access permissions (SELECT,UPDATE,DELETE) on the table level, or even on the level of table column. The general limitation of this approach is that it doesn't offer any access restrictions on the row level. One of the ways to implement different restrictions for the same user to different records within the same table is to implement all the access to the database tables throw stored procedures while revoking all the access rights from the users on the restricted tables. Stored procedures, in that case, must be created with SECURITY DEFINER attribute. Such stored procedures can be called by regular users but use their creator's permissions when access the tables.
 +
 +
For the regular users (not database administrators), the user information is stored in the person_list table, including known user information along with login name and encrypted password. A user id (a primary key from person_list table, or pl_id) is used as primary user identification. However, any permissions to any object are granted to groups of users and not to particular user. The permissions to an object fro a user can be determined by combining group permissions (from the groups user belongs to) for the object.
 +
 +
Every stored procedure that supports access restrictions must check if the current user has enough permissions to perform an operation. The user credentials are obtained during logon (session start). Logon to the system creates temporary table that stores current user information. Without that table, most of the stored procedures would generate exception requiring to login first.
 +
 +
== ACL implementation ==
 +
ACL is implemented on object type and object id basis. The ACL table contains references to the group id, the object type id, and the object (object id), accompanied with the access field. An access field is an integer that contains a bit combination of the available access values:
 +
 +
<table border=1 bgcolor="#A0FFA0">
 +
<th>access name</th><th>access value</th><th>Description</th><th> Comments </th>
 +
<tr><td> No access </td><td> 0 or NULL </td><td> User may not have any access to the object </td></tr>
 +
<tr><td> View </td><td> 1 </td><td>User may browse and view the content of the object</td></tr>
 +
<tr><td> Study </td><td> 2 </td> <td> User (student) may submit his answer or solution of the problem </td> <td> Always set for Open Server </td>  </tr>
 +
<tr><td> Modify </td><td> 4 </td> <td> User may modify the object but not the object access </td> </tr>
 +
<tr><td> Delete </td><td> 8 </td> <td> User may delete the object </td> </tr>
 +
<tr><td> Add Version </td><td> 16 </td> <td> User may create his own version of the object </td> <td> Always set for Open Server </td>  </tr>
 +
<tr><td> Link </td> <td> 32 </td> <td> User may link to this object in his objects </td> <td> Always set for Open Server </td>  </tr>
 +
<tr><td> Translate </td><td> 64 </td> <td> User may create his own translated version of the object </td> <td> Always set for Open Server </td> </tr>
 +
<tr><td> Teach </td><td> 128 </td> <td> User may teach this version of the object </td> <td> </td> </tr>
 +
<tr><td> Group administration </td><td> 256 </td> <td> User may include or exclude other users in the object groups </td> <tr><td> Catalog administration </td><td> 512 </td> <td> User may edit catalogs </td> <td> </td> </tr>
 +
</table>
 +
 +
A particular person has a permission to object that combine permissions of all groups of th object, the person is a member of.
 +
 +
ACL entries are maintained with the stored procedures acl_grant and acl_revoke. Upon execution, stored procedures check if the user has "Modify" right on the object, and then modifies the access for the group. If the required ACL entry doesn't exist it is created.
 +
 +
ACL entries perform slightly differently for the open server and proprietary server configurations. For the open server, the special right bits (Study..Link) are always set, allowing unlimited Study..Link use.
 +
 +
== HowTo ==
 +
This section lists correct functions to use in order to manipulate specific aspects of the database. Please check here before adding any new functions. Make sure to add info here as you add new procedures.
 +
(This section is still incomplete, so make sure to search sources as well).
 +
 +
* How to find list of classes given person is student of
 +
  <code>list_person_classes(person_id, 'STUDY');</code>
 +
* How to find list of classes given person is teaching
 +
  <code>list_person_classes(person_id, 'TEACH');</code>
 +
* How to find list of courses given person is studying
 +
  <code>list_person_umos(person_id, 'COURSE', 'STUDY', 0);</code>
 +
  (last parameter is limit of courses to return)
 +
* How to find out if person is CURRENTLY a student of given class.
 +
  <code>is_student_of(person_id, class_id)

Current revision