ISecuritySnapshot.ApplyFromFile

Syntax

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

ApplyFromFile(System.String, Prognoz.Platform.Interop.Metabase.ISecuritySnapshotCallback);

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, Dal, ForeSystem (for Fore.NET example) system 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;

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

Class CSnapBack: ISecuritySnapshotCallback

Public Constructor Create();
Begin
End Constructor Create;

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

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

End Class CSnapBack;


Public Class Program
    [STAThread]
    
Public Shared Sub Main(Params: StartParams);
    
Var
        MB: IMetabase;
        SE: IMetabaseSecurity;
        SS: ISecuritySnapshot;
        SSL: ISecuritySnapshotLog;
        i: Integer;
        CallBack : CSnapBack;
        sFile: String;
        Lic: Object;
    
Begin
        MB := Params.Metabase;
        
// Get license to work with security manager
        Lic := MB.RequestLicense(UiLicenseFeatureType.lftAdm);
        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
            System.Diagnostics.Debug.Write((SSL.Fields.Item[i].Name 
As String) + " ");
        
End For;
        System.Diagnostics.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 : System.Diagnostics.Debug.Write("None ");
                        
Case 1 : System.Diagnostics.Debug.Write("Create ");
                        
Case 2 : System.Diagnostics.Debug.Write("Change ");
                        
Case 3 : System.Diagnostics.Debug.Write("Error ");
                        
Case 4 : System.Diagnostics.Debug.Write("Deleted ");
                        
End Select;
                    
Else
                        System.Diagnostics.Debug.Write((SSL.Fields.Item[i].Value 
As String) + " ");
                
End If;
            
End For;
            SSL.Next();
            System.Diagnostics.Debug.WriteLine(
"");
        
End While;
        
// Release license
        Lic := Null;
    
End Sub;
End Class;

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