[This is preliminary documentation and subject to change.]
Gets a XML string representing the given AuthorizationPolicy.
A String with XML representing the policy instance.
The following example populates a simple authorization policy and writes its XML representation to the console:
[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")
// Get a XML representation of the model.
Dim xml As String = AuthorizationPolicyLoader.GetXml(policy)
Console.WriteLine(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");
// Get a XML representation of the model.
string xml = AuthorizationPolicyLoader.GetXml(policy);
Console.WriteLine(xml);
The console output generated by the above code looks like this: <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>
AuthorizationPolicyLoader Class | LaMarvin.Constable Namespace