<?xml version='1.0' ?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
               "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
<!ENTITY % myvars SYSTEM "../variables.ent">
%myvars;
]>
<sect1 id="permissions-design" xreflabel="OpenACS 4 Permissions Design">
<title>Permissions Design</title>

<authorblurb>
<para>By John Prevost and <ulink url="http://planitia.org">Rafael H. Schloming</ulink> </para>
</authorblurb>

<sect2 id="permissions-design-essentials">
<title>Essentials</title>


<itemizedlist>
<listitem><para>Tcl in <computeroutput>packages/acs-kernel</computeroutput></para></listitem>

<listitem><para><xref linkend="permissions-requirements"/></para></listitem>

<listitem><para><ulink url="/doc/sql/display-sql?url=acs-permissions-create.sql&amp;package_key=acs-kernel">
SQL file</ulink></para></listitem>

<listitem><para><ulink url="images/permissions-er.png">ER diagram</ulink> 

</para></listitem>
</itemizedlist>

</sect2>

<sect2 id="permissions-design-intro">
<title>Introduction</title>


<para>The goal of the Permissions system is to provide generic means to both
programmers and site administrators to designate operations (methods) as
requiring permissions, and then to check, grant, or revoke permissions via a
consistent interface. For example, we might decide that the transaction that
bans a user from a sub-site is an operation a site administrator is able to
assign to a particular user. Or perhaps an application developer might decide
that viewing a certain set of pages within the application is an operation to
be individually granted or revoked from a user. It&#39;s expected that the
Permissions system will be seeing a lot of use - almost every page will make
at least one permissions API call, and some will make several.</para>

<para>For programmers, the Permissions API provides a means to work with access
control in a consistent manner. If a programmer&#39;s OpenACS package defines new
methods for itself, the Permissions API must provide simple calls to
determine whether the current user is authorized to perform the given method.
In addition, using the Permissions API, queries should easily select only
those package objects on which a user has certain permissions.</para>

<para>For site administrators and other authorized users, the Permissions UI
provides a means to aggregate the primitive operations (methods) made
available by the programmer into logical privileges (like read, write, and
admin) that can be granted and revoked.</para>

</sect2>

<sect2 id="permissions-design-history">
<title>Historical Considerations</title>


<para>In earlier versions of the OpenACS, permissions and access control was handled
on a module-by-module basis, often even on a page-by-page basis. For example,
a typical module might allow any registered user to access its pages
read-only, but only allow members of a certain group to make changes. The way
this group was determined also varied greatly between modules. Some modules
used &quot;roles&quot;, while others did not. Other modules did all access
control based simply on coded rules regarding who can act on a given database
row based on the information in that row.</para>

<para>Problems resulting from this piecemeal approach to permissions and access
control were many, the two major ones being inconsistency, and
repeated/redundant code. Thus the drive in OpenACS 4 to provide a unified,
consistent permissions system that both programmers and administrators can
readily use.</para>

</sect2>

<sect2 id="permissions-design-competitors">
<title>Competitive Analysis</title>


<para><emphasis>None available as of 10/2000.</emphasis></para>

</sect2>

<sect2 id="permissions-design-design-tradeoffs">
<title>Design Tradeoffs</title>


<para>The core of the permissions data model is quite simple. Unfortunately, the
hierarchical nature of default permissions entails quite a number of tree
queries which could slow the system down. Since every page will have at least
one permissions check, a number of views and auxiliary tables
(de-normalizations of the data model) have been created to speed up access
queries. As a consequence, speed of updates are decreased and requirements
for additional storage space increase.</para>

</sect2>

<sect2 id="permissions-design-data-model">
<title>Data Model Discussion</title>


<para>As described in section V., the core of the permissions data model is
simple, though a number of views and auxiliary tables exist to ensure
adequate performance. The core model consists of five tables:</para>

<variablelist>
<varlistentry>
<term><computeroutput>acs_methods</computeroutput>

</term>
 
<listitem><para>The set of all defined methods.</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_privileges</computeroutput>

</term>
 
<listitem><para>The set of all defined privileges.</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_privilege_method_rules</computeroutput>

</term>
 
<listitem><para>A relation describing the set of methods <emphasis role="strong">directly</emphasis>
associated with each privilege.</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_privilege_hierarchy</computeroutput>

</term>
 
<listitem><para>A relation describing which privileges <emphasis role="strong">directly</emphasis>
&quot;contain&quot; other privileges.</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_permissions</computeroutput>

</term>
 
<listitem><para>A table with one (<emphasis>party</emphasis>, <emphasis>object</emphasis>, <emphasis>privilege</emphasis>)
row for every privilege <emphasis role="strong">directly</emphasis> granted on any object in
the system - this is a denormalization of
<computeroutput>acs_privilege_method_rules</computeroutput> and
<computeroutput>acs_privilege_hierarchy</computeroutput></para></listitem>
</varlistentry>
</variablelist>

<para>There are also a number of views to make it easier to ask specific
questions about permissions. For example, a number of the above tables
describe &quot;direct&quot; or explicit permissions. Inheritance and default
values can, however, introduce permissions which are not directly specified.
(For example, read access on a forum allows read access on all the messages
in the forum.)</para>

<para>The following views provide flattened versions of inherited
information:</para>

<variablelist>
<varlistentry>
<term><computeroutput>acs_privilege_method_map</computeroutput>

</term>
 
<listitem><para>Map of privileges to the methods they contain either directly or because
of another privilege which is included (at any depth).</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_object_grantee_priv_map</computeroutput>

</term>
 
<listitem><para>Relation on (<emphasis>object</emphasis>, <emphasis>party</emphasis>, <emphasis>privilege</emphasis>) for
privileges from <computeroutput>acs_privileges</computeroutput>) granted directly on the object, or
on the context of the object (at any depth).</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_object_party_privilege_map</computeroutput>

</term>
 
<listitem><para>Relation on (<emphasis>object</emphasis>, <emphasis>party</emphasis>, <emphasis>privilege</emphasis>) for
privileges directly from <computeroutput>acs_object_grantee_priv_map</computeroutput> or also because
a party is a member of a group (at any depth).</para></listitem>
</varlistentry>

<varlistentry>
<term><computeroutput>acs_object_party_method_map</computeroutput>

</term>
 
<listitem><para>Relation with every (<emphasis>object</emphasis>, <emphasis>party</emphasis>, <emphasis>method</emphasis>)
tuple implied by the above trees.</para></listitem>
</varlistentry>
</variablelist>

<para>In general, <emphasis role="strong">only <computeroutput>acs_object_party_method_map</computeroutput></emphasis>
should be used for queries from other modules. The other views are
intermediate steps in building that query.</para>

<para>The data model also includes two simple PL/SQL procedures
(<computeroutput>acs_permission.grant_permission</computeroutput> and
<computeroutput>acs_permission.revoke_permission</computeroutput>) for granting and revoking a
specific privilege for a specific user on a specific object.</para>

<para>To sum up, the PL/SQL procedures are meant to be used to grant or revoke
permissions. The five base tables represent the basic data model of the
system, with a set of views provided to convert them into a format suitable
for joining to answer specific questions. The exact means by which this
transformation takes place should not be depended on, since they may change
for efficiency reasons.</para>

<para>The transformations done create a set of default permissions, in
which:</para>

<itemizedlist>
<listitem><para>parties get the privileges of any groups they are directly or indirectly
a member of</para></listitem>

<listitem><para>privileges get associated with the methods of any other privileges they
have taken methods from (at any level) (see
<computeroutput>acs_privilege_hierarchy</computeroutput>)</para></listitem>

<listitem><para>objects get access control from direct grants, or inherit permissions
from their context (unless the &quot;don&#39;t inherit&quot; flag is
set)</para></listitem>
</itemizedlist>

</sect2>

<sect2 id="permissions-design-transactions">
<title>Legal Transactions</title>


<para>There are three essential areas in which all transactions in the
permissions system fall:</para>

<itemizedlist>
<listitem><para>Modification of methods and privileges</para></listitem>

<listitem><para>Modification of permissions</para></listitem>

<listitem><para>Queries on permissions</para></listitem>
</itemizedlist>

<para><emphasis role="strong">&quot;Modification of methods and privileges.&quot;</emphasis> This
refers to actions that happen mainly at package installation time - a package
will create a number of methods for its own use, then associate them with the
system&#39;s standard privileges, or new privileges which the package has
created. The association step might also happen later, if the site-wide
administrator chooses to change permissions policy.</para>

<para>These steps involve directly manipulating the <computeroutput>acs_methods</computeroutput>,
<computeroutput>acs_privileges</computeroutput>, and <computeroutput>acs_privilege_method_rules</computeroutput> tables. A
web page for manipulating these features should be limited to site-wide
administrators.</para>

<para><emphasis role="strong">&quot;Modification of permissions&quot;</emphasis> - involves fairly
common operations. Users are typically able to administer permissions for
objects they themselves create. The two basic operations here are
&quot;grant&quot; and &quot;revoke&quot;. Granting permissions is done via
<computeroutput>acs_permissions.grant_permission</computeroutput>, and revocation via
<computeroutput>acs_permissions.revoke_permission</computeroutput>. These directly manipulate the
<computeroutput>acs_permissions</computeroutput> table.</para>

<para>Web pages for making these changes are available to all users, so they
should not be in an admin area. In order to grant and revoke permissions on
an object, the user must have the <computeroutput>administer_privileges</computeroutput> method
permission on that object.</para>

<para><emphasis role="strong">&quot;Queries on permissions&quot;</emphasis> - by far the most
common operation is querying the permissions database. Several kinds of
questions are commonly asked: First, and most commonly, &quot;Can this party
perform this method on this object?&quot; Two Tcl functions are provided to
answer this - one which returns a boolean, the other of which results in an
error page. These tcl functions directly access the
<computeroutput>acs_object_party_method_map</computeroutput>.</para>

<para>The second most commonly asked question occurs when a list of objects is
being displayed, often in order to provide appropriate UI functionality:
&quot;For this party, what methods are available on these objects?&quot;
Here, the SQL query needs to filter based on whether the party/user can
perform some operation on the object. This is done via a join or sub-select
against <computeroutput>acs_object_party_method_map</computeroutput>, or by calling the Tcl functions
for appropriate methods.</para>

<para>Finally, when administering the permissions for an object, a web page
needs to know all permissions directly granted on that object. This is done
by querying against <computeroutput>acs_permissions</computeroutput>.</para>

</sect2>

<sect2 id="permissions-design-api">
<title>API</title>


<para>The API to the permissions system consists of a few well-known tables,
plus a pair of PL/SQL procedures and a pair of Tcl functions.</para>

<para><emphasis role="strong">Tables</emphasis></para>

<para><computeroutput>acs_methods</computeroutput>, <computeroutput>acs_privileges</computeroutput>, and
<computeroutput>acs_privilege_method_rules</computeroutput> manage the set of permissions in the
system. At installation time, a package will add to these three tables to
introduce new permissions into the system.</para>

<para>The main table for queries is <computeroutput>acs_object_party_method_map</computeroutput>, which
contains (<emphasis>object</emphasis>, <emphasis>party</emphasis>, <emphasis>method</emphasis>) triples for all
allowed operations in the system.</para>

<para>Also of interest for queries is <computeroutput>acs_permissions</computeroutput>, which lists
directly granted privileges. Neither <computeroutput>acs_object_party_method_map</computeroutput>
(which is a view) nor <computeroutput>acs_permissions</computeroutput> should be updated
directly.</para>

<para><emphasis role="strong">PL/SQL Procedures</emphasis></para>

<para><computeroutput>acs_permissions.grant_permission</computeroutput> introduces new permissions for
an object. It should be given an (<emphasis>object</emphasis>, <emphasis>party</emphasis>,
<emphasis>privilege</emphasis>) triple, and will always succeed. If the permission is
already in the system, no change occurs. The interface for this procedure
is:</para>

<programlisting>
procedure grant_permission (
  object_id    acs_permissions.object_id%TYPE,
  grantee_id   acs_permissions.grantee_id%TYPE,
  privilege    acs_permissions.privilege%TYPE
);
</programlisting>

<para><computeroutput>acs_permissions.revoke_permission</computeroutput> removes a permission entry
given a triple. It always succeeds--if a permission does not exist, nothing
changes. The interface for this procedure is:</para>

<programlisting>
procedure revoke_permission (
  object_id    acs_permissions.object_id%TYPE,
  grantee_id   acs_permissions.grantee_id%TYPE,
  privilege    acs_permissions.privilege%TYPE
);
</programlisting>

<para>These procedures are defined in <ulink url="/doc/sql/display-sql?url=acs-permissions-create.sql&amp;package_key=acs-kernel">
<computeroutput>permissions-create.sql</computeroutput></ulink></para>

<para><emphasis role="strong">Tcl Procedures</emphasis></para>

<para>Two tcl procedures provide a simple call for the query, &quot;Can this
user perform this method on this object?&quot; One returns true or false, the
other presents an error page.</para>

<para>To receive a true or false value, Tcl code should call:</para>

<programlisting>
ad_permission_p $object_id $object_type $method -user_id $user_id
</programlisting>

<para>If the <computeroutput>user_id</computeroutput> argument is left out, then the currently logged in
user is checked. To create an error page, Tcl code should call:</para>

<programlisting>
ad_require_permission $object_id $object_type $method
</programlisting>

<para>These procedures are defined in <computeroutput>acs-permissions-procs.tcl</computeroutput>.</para>

</sect2>

<sect2 id="permissions-design-ui">
<title>User Interface</title>


<para>All users of the permissions system are the same at the user-interface
level. If you have the <computeroutput>administer_privileges</computeroutput> method permission on an
object, then you may edit privileges for that object with the UI.</para>

<para>The UI currently provides a list of all granted permissions on the object.
If the user wishes to revoke privileges, she may select a set of grants,
choose revoke, confirm their deletion, and be returned to the same page after
those privileges have been revoked.</para>

<para>Granting permissions currently (as of 10/2000) works by providing a list
of all possible permissions and a list of all parties in the system. (For
large sites, some future search mechanism will be necessary.) After choosing
privileges to grant, the user is returned to the &quot;edit privileges for
one object&quot; screen.</para>

<para>If it makes sense, the system will also display a checkbox which the user
may select to toggle whether permissions are inherited from the object&#39;s
context.</para>

<para>There are a number of potential future enhancements for the permissions
UI, outlined below.</para>

</sect2>

<sect2 id="permissions-design-configure">
<title>Configuration/Parameters</title>


<para>There are no configuration options for the permissions system.</para>

</sect2>

<sect2 id="permissions-design-future">
<title>Future Improvements/Areas of Likely Change</title>


<para>The most important future changes to the Permissions system are likely to
be in the UI:</para>

<itemizedlist>
<listitem><para>There should be a page displaying a list of all objects for which the
current user is allowed to administer privileges.</para></listitem>

<listitem><para>Users should be able to view the permissions on any object, or perhaps on
objects which they have the &quot;read_permissions&quot; method. This would
allow them to see what grants are affecting their objects through
inheritance.</para></listitem>
</itemizedlist>

</sect2>

<sect2 id="permissions-design-authors">
<title>Authors</title>


<variablelist>
<varlistentry>
<term>System creator

</term>
 
<listitem><para><ulink url="mailto:rhs@mit.edu">Rafael H. Schloming</ulink></para></listitem>
</varlistentry>

<varlistentry>
<term>System owner

</term>
 
<listitem><para><ulink url="mailto:rhs@mit.edu">Rafael H. Schloming</ulink></para></listitem>
</varlistentry>

<varlistentry>
<term>Documentation author

</term>
 
<listitem><para>John Prevost</para></listitem>
</varlistentry>
</variablelist>

</sect2>

<sect2 id="permissions-design-rev-history">
<title>Revision History</title>


 
<informaltable>
<tgroup cols="4">
<tbody>
<row>
<entry><emphasis role="strong">Document Revision #</emphasis></entry>
<entry><emphasis role="strong">Action Taken, Notes</emphasis></entry>
<entry><emphasis role="strong">When?</emphasis></entry>
<entry><emphasis role="strong">By Whom?</emphasis></entry>
</row>

<row>
<entry>0.1</entry>
<entry>Creation</entry>
<entry>9/11/2000</entry>
<entry>John Prevost</entry>
</row>

<row>
<entry>0.2</entry>
<entry>Edited for ACS 4 Beta release</entry>
<entry>10/04/2000</entry>
<entry>Kai Wu</entry>
</row>
</tbody></tgroup></informaltable>


</sect2>

</sect1>
