ICredentialsEx.Impersonation

Fore Syntax

Impersonation: ICredentials;

Fore.NET Syntax

Impersonation: Prognoz.Platform.Interop.Metabase.ICredentials;

Description

The Impersonation property determines the credentials for impersonation of the user.

Comments

Impersonation can be used on creating new connections to the repository from the application code. Initial instance of credentials is taken from required repository description. Credentials are saved using the PP.Util.exe application included in Foresight Analytics Platform.

As the value of the Impersonation property, specify the credentials of any other user, who is necessary to pass the credentials of the current instance of ICredentials. The specified user must be created in the security manager of the repository. The actual connection will be performed under the current credentials, and all further work will be performed from the user specified in the Impersonation property:

Fore Example

Function MBConnect(Definition: String; ImpUser: String; ImpPassword: String): IMetabase;
Var
    MBMan: IMetabaseManager;
    MBDef: IMetabaseDefinition;
    ScPack: ISecurityPackage;
    DefCrs, ImpCrs: ICredentials;
    DefEx: ICredentialsEx;
    MB: IMetabase;
Begin
    MBMan := MetabaseManagerFactory.Active;
    MBDef := MBMan.Definitions.FindById(Definition);
    If MBDef = Null Then
        Return Null;
    End If;
    DefCrs := (MBDef As IMetabaseLink).Credentials;
    ScPack := MBMan.Packs.FindById(MbDef.SecurityPackage).Package;
    ImpCrs := ScPack.CreateCredentials(AuthenticationMode.Password);
    //Credentials
    (ImpCrs As IPasswordCredentials).UserName := ImpUser;
    (ImpCrs As IPasswordCredentials).Password := ImpPassword;
    DefEx := DefCrs As ICredentialsEx;
    DefEx.Impersonation := ImpCrs;
    Try
        //Connecting with DefCrs credentials with ImpCrs impersonation
        MB := MBDef.Open(DefCrs);
    Except On e: Exception Do
        Debug.Write(Connection error: );
        Debug.Write(e.Message);
        Return Null;
    End Try;
    Return MB;
End Function MBConnect;

The specified function can be applied to create the connection to the repository with the impersonation of the user, the credentials of which are passed as the input parameters ImpUser and ImpPassword. On function executing the search for the description of the repository passed in the Definition parameter is performed. If the description is missing or any other errors occurs on connecting then the function returns the Null value. After obtaining the description the credentials for the impersonated user will be created. After specifying all the parameters the connection is established. The factual connection is performed with the credentials which should be saved for the specified description of the repository (see description of IMetabaseLink.Credentials).

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example. Use Fore.NET analogs instead of Fore components.

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

Function MBConnect(Definition: String; ImpUser: String; ImpPassword: String): IMetabase;
Var
    Man: MetabaseManagerFactory = New MetabaseManagerFactoryClass();
    MBMan: IMetabaseManager;
    MBDef: IMetabaseDefinition;
    ScPack: ISecurityPackage;
    DefCrs, ImpCrs: ICredentials;
    DefEx: ICredentialsEx;
    MB: IMetabase;
Begin
    MBMan := Man.Active;
    MBDef := MBMan.Definitions.FindById(Definition);
    If MBDef = Null Then
        System.Diagnostics.Debug.Write(Repository description is missing);
        Return Null;
    End If;
    DefCrs := (MBDef As IMetabaseLink).Credentials;
    ScPack := MBMan.Packs.FindById(MbDef.SecurityPackage).Package;
    ImpCrs := ScPack.CreateCredentials(AuthenticationMode.amPassword);
    //Credentials
    (ImpCrs As IPasswordCredentials).UserName := ImpUser;
    (ImpCrs As IPasswordCredentials).Password := ImpPassword;
    DefEx := DefCrs As ICredentialsEx;
    DefEx.Impersonation := ImpCrs;
    Try
        //Connecting with DefCrs credentials with ImpCrs impersonation
        MB := MBDef.Open(DefCrs, ApplicationMode.amWin, LocaleCodeID.lcidNone);
    Except On e: System.Exception Do
        Begin
            System.Diagnostics.Debug.Write(Connection error: );
            System.Diagnostics.Debug.Write(e.Message);
            Return Null;
        End;
    End Try;
    Return MB;
End Function;

See also:

ICredentialsEx