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 rules.

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;
    Rule: IABACRule;
    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 1 index in the first policies set
    PolicySet := PolicyObject.Policies.Item(0);
    Policy := PolicySet.Policies.Item(
0);
    
// Add a rule
    Rules := Policy.Rules;
    Rule := Rules.Add;
    Rule.Name(LocaleCodeID.Russian) := 
"Test rule";
    Rule.Id := 
"RULE";
    
// Get rule index
    Index := Rules.IndexOf(Rule);
    
// Display rule name and index in the console
    Debug.WriteLine(Rule.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;
    Policy: IABACPolicy;
    Rules: IABACRules;
    Rule: IABACRule;
    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 1 index in the first policies set
    PolicySet := PolicyObject.Policies.Item[0];
    Policy := PolicySet.Policies.Item[
0];
    
// Add a rule
    Rules := Policy.Rules;
    Rule := Rules.Add();
    Rule.Name(LocaleCodeID.lcidRussian) := 
"Test rule";
    Rule.Id := 
"RULE";
    
// Get rule index
    Index := Rules.IndexOf(Rule);
    
// Display rule name and index in the console  
    System.Diagnostics.Debug.WriteLine(Rule.Name[MB.CurrentLocale]);
    System.Diagnostics.Debug.WriteLine(
"Index = " + Index.ToString());
    
// Check in license
    Lic := Null;
End Sub;

After executing the example the console displays the message:

Test rule

Index = 2

See also:

IABACRules