IABACRules.IndexOf

Syntax

IndexOf(Value: IABACRule): Integer;

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

Parameters

Value. Rule value.

Description

The IndexOf method returns index of a rule in attribute-based access control policy.

Comments

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

Rules indexing starts with zero.

To get element of attribute-based access control structure by its index, use the IABACRules.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;
    Policy: IABACPolicy;
    Rules: IABACRules;
    Rule1, Rule2: IABACRule;
    MB: IMetabase;
    MS: IMetabaseSecurity;
    Lic: Object;
    Index1, Index2: 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 1 index in the first policies set
    PolicySet := PolicyObject.Policies.Item(0);
    Policy := PolicySet.Policies.Item(
1);
    
// Find rule with the RULE1 identifier
    Rules := Policy.Rules;
    Rule1 := Rules.FindById(
"RULE1");
    
// Get rule index
    Index1 := Rules.IndexOf(Rule1);
    
// Display rule name and index in the console
    Debug.WriteLine(Rule1.Name(MB.CurrentLocale));
    Debug.WriteLine(
"Index = " + Index1.ToString);
    
// Find rule with the RULE2 identifier
    Rule2 := Rules.FindById("RULE2");
    
// Get rule index
    Index2 := Rules.IndexOf(Rule2);
    
// Display rule name and index in the console  
    Debug.WriteLine(Rule2.Name(MB.CurrentLocale));
    Debug.WriteLine(
"Index = " + Index2.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;
    Policy: IABACPolicy;
    Rules: IABACRules;
    Rule1, Rule2: IABACRule;
    MB: IMetabase;
    MS: IMetabaseSecurity;
    Lic: Object;
    Index1, Index2: 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 1 index in the first policies set
    PolicySet := PolicyObject.Policies.Item[0];
    Policy := PolicySet.Policies.Item[
1];
    
// Find rule with the RULE1 identifier
    Rules := Policy.Rules;
    Rule1 := Rules.FindById(
"RULE1");
    
// Get rule index
    Index1 := Rules.IndexOf(Rule1);
    
// Display rule name and index in the console
    System.Diagnostics.Debug.WriteLine(Rule1.Name[MB.CurrentLocale]);
    System.Diagnostics.Debug.WriteLine(
"Index = " + Index1.ToString());
    
// Find rule with the RULE2 identifier
    Rule2 := Rules.FindById("RULE2");
    
// Get rule index
    Index2 := Rules.IndexOf(Rule2);
    
// Display rule name and index in the console  
    System.Diagnostics.Debug.WriteLine(Rule2.Name[MB.CurrentLocale]);
    System.Diagnostics.Debug.WriteLine(
"Index = " + Index2.ToString());
    
// Check in license
    Lic := Null;
End Sub;

After executing the example the console displays the message:

Test rule

Index = 0

Test rule 2

Index = 1

See also:

IABACRules