IABACPolicies.IndexOf

Syntax

IndexOf(Value: IABACPolicy): Integer;

IndexOf(Prognoz.Platform.Interop.ABAC.IABACPolicy): System.Int32;

Parameters

Value. Policy value.

Description

The IndexOf method returns policy index in attribute-based access control structure.

Comments

If the specified policy is not found, the method returns -1.

Policies indexing starts with zero.

To get attribute-based access control structure element by its index, use the IABACPolicies.Item property.

Example

To execute the example, make sure that attribute-based access control contains a policies set with two nested policies.

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

Sub Main;
Var
    PolicyObject: IABACRootPolicyObject;
    PolicySet: IABACPolicySet;
    Policies: IABACPolicies;
    Policy: IABACPolicy;
    MB: IMetabase;
    MS: IMetabaseSecurity;
    Lic: Object;
    Index: Integer;
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 policy with the 0 index in the first policies set
    PolicySet := PolicyObject.Policies.Item(0);
    Policies := PolicySet.Policies;
    
// Add a policy
    Policy := PolicySet.Policies.Add;
    Policy.Name(LocaleCodeID.Russian) := 
"Test policy";
    Policy.Id := 
"POLICY";
    
// Get policy index
    Index := Policies.IndexOf(Policy);
    
// Display policy name and index in the console
    Debug.WriteLine(Policy.Name(MB.CurrentLocale));
    Debug.WriteLine(
"Index = " + Index.ToString);
    
// Check in license
    Lic := Null;
End Sub Main;

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;
    Policies: IABACPolicies;
    Policy: IABACPolicy;
    MB: IMetabase;
    MS: IMetabaseSecurity;
    Lic: Object;
    Index: Integer;
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 policy with the 0 index in the first policies set
    PolicySet := PolicyObject.Policies.Item[0];
    Policies := PolicySet.Policies;
    
// Add a policy
    Policy := PolicySet.Policies.Add();
    Policy.Name(LocaleCodeID.lcidRussian) := 
"Test policy";
    Policy.Id := 
"POLICY";
    
// Get policy index
    Index := Policies.IndexOf(Policy);
    
// Display policy name and index in the console
    System.Diagnostics.Debug.WriteLine(Policy.Name[MB.CurrentLocale]);
    System.Diagnostics.Debug.WriteLine(
"Index = " + Index.ToString());
    
// Check in license
    Lic := Null;
End Sub;

After executing the example the following message is displayed in the console:

Test policy

Index = 2

See also:

IABACPolicies