[This is preliminary documentation and subject to change.]
Provides an implementation of the IPrincipal interface whose role membership can be controlled by setting the IsInRoleResult property.
For a list of all members of this type, see DynamicPrincipal Members.
System.Object
LaMarvin.Constable.Principal.DynamicPrincipal
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
This class is useful primarily for testing scenarios, where you can achieve principals in all roles / no roles with a simple setting of the IsInRoleResult property.
The following example populates a very simple authorization model, associates the model with an "almighty" principal (who is member of all roles) and then asserts some implied facts. The principal is the turned to an "infirm" principal and once again, some implied facts are asserted.
[Visual Basic] Imports System Imports System.Diagnostics Imports LaMarvin.Constable Imports LaMarvin.Constable.Model Imports LaMarvin.Constable.Principal ' Create and populate the policy. Dim policy As New AuthorizationPolicy policy.States.AddNew("") ' default state policy.Roles.AddNew("User") policy.Roles.AddNew("Admin") policy.Actions.AddNew("LogOff") policy.Actions.AddNew("ShutDown") policy.ActionRules.AddNew("LogOff", "User") policy.ActionRules.AddNew("LogOff", "Admin") policy.ActionRules.AddNew("ShutDown", "Admin") ' Associate the model with an "almighty" principal policy.CurrentPrincipal = New DynamicPrincipal(True) Debug.Assert(policy.IsActionExecutable("LogOff")) Debug.Assert(policy.IsActionExecutable("ShutDown")) ' Make the principal "infirm" :-) DirectCast(policy.CurrentPrincipal, DynamicPrincipal).IsInRoleResult = False Debug.Assert(Not policy.IsActionExecutable("LogOff")) Debug.Assert(Not policy.IsActionExecutable("ShutDown")) [C#] using System; using System.Diagnostics; using LaMarvin.Constable; using LaMarvin.Constable.Model; using LaMarvin.Constable.Principal; // Create and populate the policy. AuthorizationPolicy policy = new AuthorizationPolicy(); policy.States.AddNew(""); // default state policy.Roles.AddNew("User"); policy.Roles.AddNew("Admin"); policy.Actions.AddNew("LogOff"); policy.Actions.AddNew("ShutDown"); policy.ActionRules.AddNew("LogOff", "User"); policy.ActionRules.AddNew("LogOff", "Admin"); policy.ActionRules.AddNew("ShutDown", "Admin"); // Associate the model with an "almighty" principal policy.CurrentPrincipal = new DynamicPrincipal(true); Debug.Assert(policy.IsActionExecutable("LogOff")); Debug.Assert(policy.IsActionExecutable("ShutDown")); // Make the principal "infirm" :-) ((DynamicPrincipal)policy.CurrentPrincipal).IsInRoleResult = false; Debug.Assert(!policy.IsActionExecutable("LogOff")); Debug.Assert(!policy.IsActionExecutable("ShutDown"));
Namespace: LaMarvin.Constable.Principal
Assembly: LaMarvin.Constable (in LaMarvin.Constable.dll)
DynamicPrincipal Members | LaMarvin.Constable.Principal Namespace