IABACPolicies.AddCopy

Syntax

AddCopy(Value: IABACPolicy): IABACPolicy;

AddCopy(Prognoz.Platform.Interop.ABAC.IABACPolicy): Prognoz.Platform.Interop.ABAC.IABACPolicy;

Description

The AddCopy method adds copies of the specified policy to attribute-based access control structure.

Example

To execute the example, make sure that the attribute-based access control structure contains two policies sets. The first policies set contains an additional nested policy.

Add links to the ABAC, Metabase, ForeSystem (for the Fore.NET example) system assemblies.

Sub UserProc;
Var
    PolicyObject: IABACRootPolicyObject;
    PolicySet: IABACPolicySet;
    Policy: IABACPolicy;
    Policies: IABACPolicies;
    MB: IMetabase;
    MS: IMetabaseSecurity;
    Lic: Object;
Begin
    MB := MetabaseClass.Active;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
    MS := MB.Security;
    
// Get attribute-based access control structure
    PolicyObject := MB.Security.Policy.ABACRules;
    
// Get the first policy in policies set with the 0 index
    PolicySet := PolicyObject.Policies.Item(0);
    Policy := PolicySet.Policies.Item(
0);
    
// Get policies set with the 1 index
    PolicySet := PolicyObject.Policies.Item(1);
    Policies := PolicySet.Policies;
    
// Copy the first policy from policies set with the 0 index to policies set with the 1 index
    Policies.AddCopy(Policy);
    
// Change name of copied policy
    Policies.Item(0).Name(MB.CurrentLocale) := "Copied policy";
    
// Apply changes in security manager
    MS.Apply;
    
// Check in license
    Lic := Null;
End Sub UserProc;

Imports Prognoz.Platform.Interop.ABAC;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.ForeSystem;

Public Shared Sub Main(Params: StartParams);
Var
    PolicyObject: IABACRootPolicyObject;
    PolicySet: IABACPolicySet;
    Policy: IABACPolicy;
    Policies: IABACPolicies;
    MB: IMetabase;
    MS: IMetabaseSecurity;
    Lic: Object;
Begin
    MB := Params.Metabase;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.lftAdm);
    MS := MB.Security;
    
// Get attribute-based access control structure
    PolicyObject := MB.Security.Policy.ABACRules;
    
// Get the first policy in policies set with the 0 index
    PolicySet := PolicyObject.Policies.Item[0];
    Policy := PolicySet.Policies.Item[
0];
    
// Get policies set with the 1 index
    PolicySet := PolicyObject.Policies.Item[1];
    Policies := PolicySet.Policies;
    
// Copy the first policy from policies set with the 0 index to policies set with the 1 index
    Policies.AddCopy(Policy);
    
// Change name of copied policy
    Policies.Item[0].Name[MB.CurrentLocale] := "Copied policy";
    
// Apply changes in security manager
    MS.Apply();
    
// Check in license
    Lic := Null;
End Sub;

After executing the example the existing policy from the policies set with the 0 index and new name is copied to the specified policies set with the 1 index:

See also:

IABACPolicies