Constable Authorization Engine 2.0 BETA

AuthorizationPolicy.ActionExecuted Event

[This is preliminary documentation and subject to change.]

Occurs after an Action is executed as a result of calling one of the ExecuteAction overloaded methods.

[VisualBasic]
PublicEventActionExecutedAsActionExecutionEventHandler
[C#]
publiceventActionExecutionEventHandlerActionExecuted;

Event Data

The event handler receives an argument of type ActionExecutionEventArgs containing data related to this event. The following ActionExecutionEventArgs property provides information specific to this event.

Property Description
ActionRule Returns the ActionRule for the action being executed.

Example

The following example illustrates programming with the ActionExecuting and ActionExecuted events:

[VisualBasic]
Imports System
Imports System.Diagnostics
Imports System.Security.Principal

Imports LaMarvin.Constable
Imports LaMarvin.Constable.Model
Imports LaMarvin.Constable.Principal


Public Class ActionExecutingActionExecutedEvents
  Public Shared Sub Main()
    ' Create policy and hook the action execution events.
    Dim policy As AuthorizationPolicy = New AuthorizationPolicy
    AddHandler policy.ActionExecuting, AddressOf HandleActionExecutingEvent
    AddHandler policy.ActionExecuted, AddressOf HandleActionExecutedEvent

    ' Populate the policy with a simple model - the Author can execute the Save
    ' action that moves the policy from the New to the Saved state. (More precisely, the Save action
    ' moves the policy's subject, such as 'document', from New to the Saved state.)
    policy.Roles.AddNew("Author")
    policy.States.AddNew("New")
    policy.States.AddNew("Saved")
    policy.Actions.AddNew("Save")
    policy.ActionRules.AddNew("Save", "Author", "New", "Saved")

    ' Initialize the authorization context.
    policy.CurrentPrincipal = New ExtendedPrincipal(New GenericIdentity("John"), New String() {"Author"})
    policy.CurrentState = policy.States("New")

    ' Executing the Save action will raise the action execution events.
    Console.WriteLine("Executing Save action")
    policy.ExecuteAction("Save")
    Console.WriteLine("Save action executed")
  End Sub


  Private Shared Sub HandleActionExecutingEvent(ByVal sender As Object, ByVal e As ActionExecutionEventArgs)
    Console.WriteLine(" ** ActionExecuting: {0}", e.ActionRule.Action)
  End Sub


  Private Shared Sub HandleActionExecutedEvent(ByVal sender As Object, ByVal e As ActionExecutionEventArgs)
    Console.WriteLine(" ** ActionExecuted: {0}", e.ActionRule.Action)
  End Sub

End Class

[C#]
using System;
using System.Diagnostics;
using System.Security.Principal;

using LaMarvin.Constable;
using LaMarvin.Constable.Model;
using LaMarvin.Constable.Principal;

public class ActionExecutingActionExecutedEvents
{
  public static void Main()
  {
    // Create policy and hook the action execution events.
    AuthorizationPolicy policy = new AuthorizationPolicy();
    policy.ActionExecuting += new ActionExecutionEventHandler(HandleActionExecutingEvent);
    policy.ActionExecuted += new ActionExecutionEventHandler(HandleActionExecutedEvent);
   
    // Populate the policy with a simple model - the Author can execute the Save
    // action that moves the policy from the New to the Saved state. (More precisely, the Save action
    // moves the policy's subject, such as 'document', from New to the Saved state.)
    policy.Roles.AddNew("Author");
    policy.States.AddNew("New"); 
    policy.States.AddNew("Saved");
    policy.Actions.AddNew("Save");
    policy.ActionRules.AddNew("Save", "Author", "New", "Saved");

    // Initialize the authorization context.
    policy.CurrentPrincipal = new ExtendedPrincipal(new GenericIdentity("John"), new string[] {"Author"});
    policy.CurrentState = policy.States["New"];
    
    // Executing the Save action will raise the action execution events.
    Console.WriteLine("Executing Save action");
    policy.ExecuteAction("Save");
    Console.WriteLine("Save action executed");
  }


  private static void HandleActionExecutingEvent(object sender, ActionExecutionEventArgs e)
  {
    Console.WriteLine(" ** ActionExecuting: {0}", e.ActionRule.Action);
  }


  private static void HandleActionExecutedEvent(object sender, ActionExecutionEventArgs e)
  {
    Console.WriteLine(" ** ActionExecuted: {0}", e.ActionRule.Action);
  }

}
The code above produces the following console output:
Executing Save action
 ** ActionExecuting: Save
 ** ActionExecuted: Save
Save action executed

See Also

AuthorizationPolicy Class | LaMarvin.Constable Namespace