Constable Authorization Engine 2.0 BETA

AuthorizationPolicy.CurrentPrincipal Property

[This is preliminary documentation and subject to change.]

Sets or returns the IPrincipal implementation used to resolve role membership.

[VisualBasic]
OverridablePublicPropertyCurrentPrincipalAsIPrincipal
[C#]
publicvirtualSystem.Security.Principal.IPrincipalCurrentPrincipal{get;set;}

Remarks

If you don't set this property explicitly, the AuthorizationPolicy instance will return the System.Threading.Thread.CurrentPrincipal reference. However, once you set the property, the assigned value will be used even if you set it to a null reference (Nothing in Visual Basic).

Note If you set the property to a a null reference (Nothing in Visual Basic), no authorization rules will be enabled for the given AuthorizationPolicy instance. That is, all calls to IsActionExecutable and IsPropertyChangeable will return false and the ExecuteAction will always throw PermissionDeniedException.
This is logical if you realize that a a null reference (Nothing in Visual Basic) principal cannot be member of any role.

Example

The following example initializes a new instance of the AuthorizationPolicy class and sets the authorization context to a GenericPrincipal that is member of an "Author" role.

[VisualBasic]
Dim policy As New AuthorizationPolicy
policy.CurrentPrincipal = New GenericPrincipal( _
  New GenericIdentity("Default User"), _
  New String() {"Author"})
Debug.Assert(policy.CurrentPrincipal.IsInRole("Author"))

[C#]
AuthorizationPolicy policy = new AuthorizationPolicy();
AuthorizationPolicy.CurrentPrincipal = new GenericPrincipal(
  new GenericIdentity("Default User"),
  new string[] {"Author"});
Debug.Assert(policy.CurrentPrincipel.IsInRole("Author"));

See Also

AuthorizationPolicy Class | LaMarvin.Constable Namespace