-
Notifications
You must be signed in to change notification settings - Fork 11
AWA_Permissions
The AWA.Permissions framework defines and controls the permissions used by an application
to verify and grant access to the data and application service. The framework provides a
set of services and API that helps an application in enforcing its specific permissions.
Permissions are verified by a permission controller which uses the service context to
have information about the user and other context. The framework allows to use different
kinds of permission controllers. The Entity_Controller
is the default permission
controller which uses the database and an XML configuration to verify a permission.
To be used in the application, the first step is to declare the permission. This is a static definition of the permission that will be used to ask to verify the permission. The permission is given a unique name that will be used in configuration files:
with Security.Permissions;
...
package ACL_Create_Post is new Security.Permissions.Definition ("blog-create-post");
A permission can be checked in Ada as well as in the presentation pages.
This is done by using the Check
procedure and the permission definition. This operation
acts as a barrier: it does not return anything but returns normally if the permission is
granted. If the permission is denied, it raises the NO_PERMISSION
exception.
Several Check
operation exists. Some require no argument and some others need a context
such as some entity identifier to perform the check.
with AWA.Permissions;
...
AWA.Permissions.Check (Permission => ACL_Create_Post.Permission,
Entity => Blog_Id);
The AWA.Permissions framework supports a simple permission model
The application configuration file must provide some information to help in checking the
permission. The permission name is referenced by the name
XML entity. The entity-type
refers to the database entity (ie, the table) that the permission concerns.
The sql
XML entity represents the SQL statement that must be used to verify the permission.
<entity-permission>
<name>blog-create-post</name>
<entity-type>blog</entity-type>
<description>Permission to create a new post.</description>
<sql>
SELECT acl.id FROM acl
WHERE acl.entity_type = :entity_type
AND acl.user_id = :user_id
AND acl.entity_id = :entity_id
</sql>
</entity-permission>
Adding a permission means to create an ACL
database record that links a given database
entity to the user. This is done easily with the Add_Permission
procedure:
with AWA.Permissions.Services;
...
AWA.Permissions.Services.Add_Permission (Session => DB,
User => User,
Entity => Blog);
Generated by Dynamo from awa-permissions.ads