ISecuritySnapshot.ApplyFromFile

Syntax

ApplyFromFile(FileName: String, [CallBack: ISecuritySnapshotCallback = Null]);

Parameters

FileName. Path to the *.pppolicy security policy file.

CallBack. Callback, for example, to confirm whether it is required to create a user.

Description

The ApplyFromFile method applies security policy from the file.

Example

Executing the example requires the C:\test.pppolicy security policy file.

Add links to the Metabase and Dal assemblies.

Class CSnapBack: SecuritySnapshotCallback

Public Constructor Create;
Begin
End Constructor Create;

Public Sub OnSubjectApply(ApplyState: ApplyStateType; Subject: ISecuritySubject; Var State: Integer);
Begin
    Debug.WriteLine(
"OnSubjectApply " + Subject.Name + " " + CultureInfo.Current.FormatTime(DateTime.Now) + " - " + ApplyState.ToString);
End Sub OnSubjectApply;

Public Sub OnOperation(ApplyOperation: SnapshotApplyOperationType; Var State: Integer);
Begin
    Debug.WriteLine(
"OnOperation: " + CultureInfo.Current.FormatTime(DateTime.Now) + " - " + ApplyOperation.ToString);
End Sub OnOperation;

End Class CSnapBack;


Sub UserProc;
Var
    MB: IMetabase;
    SE: IMetabaseSecurity;
    SS: ISecuritySnapshot;
    SSL: ISecuritySnapshotLog;
    i: Integer;
    CallBack : CSnapBack;
    sFile: String;
    Lic: Object;
Begin
    MB := MetabaseClass.Active;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
    SE := MB.Security;
    SS := SE.NewSnapshot;    
    CallBack := 
New CSnapBack.Create;
    SS.ApplyFromFile(
"C:\test.pppolicy", CallBack);
    SSL := SS.Log;
    
For i := 0 To SSL.Fields.Count - 1 Do
        Debug.Write((SSL.Fields.Item(i).Name 
As String) + " ");
    
End For;
    Debug.WriteLine(
"");
    
While Not SSL.Eof Do
        
For i := 0 To SSL.Fields.Count-1 Do
            
If SSL.Fields.Item(i).Name = "APST"
                
Then
                    
Select Case (SSL.Fields.Item(i).Value As Integer)
                    
Case 0 : Debug.Write("None ");
                    
Case 1 : Debug.Write("Create ");
                    
Case 2 : Debug.Write("Change ");
                    
Case 3 : Debug.Write("Error ");
                    
Case 4 : Debug.Write("Deleted ");
                    
End Select;
                
Else
                    Debug.Write((SSL.Fields.Item(i).Value 
As String) + " ");
            
End If;
        
End For;
        SSL.Next;
        Debug.WriteLine(
"");
    
End While;
    
// Check in license
    Lic := Null;
End Sub UserProc;

After executing the example the console window displays information about executed operations when security policy is applied, as well as detailed list of groups/users and manipulations executed with them.

See also:

ISecuritySnapshot