Impersonation: ICredentials;
The Impersonation property determines the credentials for impersonation of the user.
Impersonation can be used on creating new connections to the repository from the application code. The initial instance of credentials is taken from required repository description. Credentials are saved using the PP.Util application 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:
If the user, whose credentials are specified in the Impersonation property has more privileges than the user corresponding to the credentials of the current ICredentials, then the connection is impossible.
After connecting the permissions will be updated due to the permissions of the specified user.
The access protocol will contain records on behalf of the name of the specified user.
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).
See also: