text
stringlengths
0
234
elsif not (M.all in Permission_Manager'Class) then
Log.Info ("Permission manager is not a AWA permission manager");
return null;
else
return Permission_Manager'Class (M.all)'Access;
end if;
end Get_Permission_Manager;
-- ------------------------------
-- Get the permission manager associated with the security context.
-- Returns null if there is none.
-- ------------------------------
function Get_Permission_Manager (Context : in ASC.Service_Context_Access)
return Permission_Manager_Access is
Manager : constant Security.Policies.Policy_Manager_Access
:= Context.Get_Application.Get_Security_Manager;
begin
return Permission_Manager'Class (Manager.all)'Access;
end Get_Permission_Manager;
-- ------------------------------
-- Get the application instance.
-- ------------------------------
function Get_Application (Manager : in Permission_Manager)
return AWA.Applications.Application_Access is
begin
return Manager.App;
end Get_Application;
-- ------------------------------
-- Set the application instance.
-- ------------------------------
procedure Set_Application (Manager : in out Permission_Manager;
App : in AWA.Applications.Application_Access) is
begin
Manager.App := App;
end Set_Application;
-- ------------------------------
-- Initialize the permissions.
-- ------------------------------
procedure Start (Manager : in out Permission_Manager) is
package Perm renames Security.Permissions;
DB : ADO.Sessions.Master_Session := Manager.App.Get_Master_Session;
Cache : constant Permission_Cache.Cache_Type_Access := new Permission_Cache.Cache_Type;
Count : constant Perm.Permission_Index := Perm.Get_Last_Permission_Index;
Last : ADO.Identifier := 0;
Insert : ADO.Statements.Insert_Statement;
Stmt : ADO.Statements.Query_Statement;
Load_Count : Natural := 0;
Add_Count : Natural := 0;
begin
Log.Info ("Initializing {0} permissions", Perm.Permission_Index'Image (Count));
DB.Begin_Transaction;
-- Step 1: load the permissions from the database.
Stmt := DB.Create_Statement ("SELECT id, name FROM awa_permission");
Stmt.Execute;
while Stmt.Has_Elements loop
declare
Id : constant Integer := Stmt.Get_Integer (0);
Name : constant String := Stmt.Get_String (1);
begin
Log.Debug ("Loaded permission {0} as {1}", Name, Util.Strings.Image (Id));
Permission_Cache.Insert (Cache.all, Name, Id);
Load_Count := Load_Count + 1;
if ADO.Identifier (Id) > Last then
Last := ADO.Identifier (Id);
end if;
Function Definition: procedure Add_Permission (Manager : in Permission_Manager;
Function Body: Entity : in ADO.Identifier;
Kind : in ADO.Entity_Type;
Workspace : in ADO.Identifier;
Permission : in Security.Permissions.Permission_Index) is
Ctx : constant AWA.Services.Contexts.Service_Context_Access
:= AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Perm : AWA.Permissions.Models.ACL_Ref;
begin
Log.Info ("Adding permission");
Ctx.Start;
Perm.Set_Entity_Type (Kind);
Perm.Set_User_Id (Ctx.Get_User_Identifier);
Perm.Set_Entity_Id (Entity);
Perm.Set_Writeable (False);
Perm.Set_Workspace_Id (Workspace);
Perm.Set_Permission (Manager.Map (Permission));
Perm.Save (DB);
Ctx.Commit;
end Add_Permission;
-- ------------------------------
-- Check that the current user has the specified permission.
-- Raise NO_PERMISSION exception if the user does not have the permission.
-- ------------------------------