Constable Authorization Engine 2.0 BETA

AuthorizationPolicyLoader.SaveToFile Method (AuthorizationPolicy, String)

[This is preliminary documentation and subject to change.]

Stores the authorization policy contained in the AuthorizationPolicy instance in the file identified by the fileName argument.

[Visual Basic]
Overloads Public Shared Sub SaveToFile( _
   ByVal policy As AuthorizationPolicy, _
   ByVal fileName As String _
)
[C#]
public static void SaveToFile(
   AuthorizationPolicy policy,
   string fileName
);

Parameters

policy
The AuthorizationPolicy instance containing the authorization model to be saved.
fileName
The file in which to store the authorization policy. If the file exists, the method will truncate it and overwrite it with the new content.

Remarks

The method writes the file using UTF-8 encoding. In order to use different encoding, use the SaveToFile overload.

Example

The following example populates a simple model and saves it to a file:

[Visual Basic]
' Create and populate the policy.
Dim policy As New AuthorizationPolicy

' States.
policy.States.AddNew("Default")

' Roles.
policy.Roles.AddNew("User")
policy.Roles.Add(New WindowsRole("Admin", @"BUILTIN\Administrators"))

' Actions.
policy.Actions.AddNew("Logoff")
policy.Actions.AddNew("Shutdown")

' Action rules for User.
policy.ActionRules.AddNew("Logoff", "User")
policy.ActionRules.AddNew("Shutdown", "User").IsEnabled = False

' Action rules for Admin.
policy.ActionRules.AddNew("Logoff", "Admin")
policy.ActionRules.AddNew("Shutdown", "Admin")

' Save the model.
AuthorizationPolicyLoader.SaveToFile(policy, "c:\model.xml")

[C#]
// Create and populate the policy.
AuthorizationPolicy policy = new AuthorizationPolicy();

// States.
policy.States.AddNew("Default");

// Roles.
policy.Roles.AddNew("User");
policy.Roles.Add(new WindowsRole("Admin", @"BUILTIN\Administrators"));

// Actions.
policy.Actions.AddNew("Logoff");
policy.Actions.AddNew("Shutdown");

// Action rules for User.
policy.ActionRules.AddNew("Logoff", "User");
policy.ActionRules.AddNew("Shutdown", "User").IsEnabled = false;

// Action rules for Admin.
policy.ActionRules.AddNew("Logoff", "Admin");
policy.ActionRules.AddNew("Shutdown", "Admin");

// Save the model.
AuthorizationPolicyLoader.SaveToFile(policy, @"c:\model.xml");
The resulting c:\model.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by LaMarvin.Constable.AuthorizationPolicyLoader, LaMarvin.Constable, Version=2.0.289.0, Culture=neutral, PublicKeyToken=351c1e2b8552ee8a.-->
<!--Generated on \\PALO at 03/05/2006 12:06:40.-->
<authorizationPolicy id="" currentState="Default">
    <!--Roles-->
    <role id="User" />
    <role id="Admin" type="windows" windowsGroupName="BUILTIN\Administrators" />
    <!--States-->
    <state id="Default" />
    <!--Actions-->
    <action id="Logoff" />
    <action id="Shutdown" />
    <!--Properties-->
    <!--Action authorization rules-->
    <actionRule action="Logoff" role="User" state="Default" targetState="Default" isEnabled="True" isVisible="True" />
    <actionRule action="Shutdown" role="User" state="Default" targetState="Default" isEnabled="False" isVisible="True" />
    <actionRule action="Logoff" role="Admin" state="Default" targetState="Default" isEnabled="True" isVisible="True" />
    <actionRule action="Shutdown" role="Admin" state="Default" targetState="Default" isEnabled="True" isVisible="True" />
    <!--Property authorization rules-->
</authorizationPolicy>

See Also

AuthorizationPolicyLoader Class | LaMarvin.Constable Namespace | AuthorizationPolicyLoader.SaveToFile Overload List