Signature: String;
Signature: String;
The Signature property determines block of data digitally signed.
The certificate, which is used to check digital signature, must be saved with the repository description, to which the connection is made. To save the certificate, use the PP.Util.exe application in Foresight Analytics Platform.
Executing the example requires file with private certificate key which will be used to set digital signature. The certificate should be saved to the repository to which it is connected.
Function Connect(Repository: String; PrivateKeyPath: String): IMetabase;
Var
MbDef: IMetabaseDefinition;
Package: ISecurityPackage;
Provider: ICertProvider;
Cookie, Code, Signature: String;
FStream: IFileStream;
Signer: ICertSigner;
CertCreds: ICertCredentials;
Mb: IMetabase;
MbManager: IMetabaseManager;
Begin
MbManager := MetabaseManagerFactory.Active;
MbDef := MbManager.Definitions.FindById(Repository);
If MbDef <> Null Then
Package := MbManager.Packs.FindById(MbDef.SecurityPackage).Package;
//Certificate provider
Provider := Package.CertProvider;
Provider.NewCode(Cookie, Code);
//Private key
FStream := New FileStream.Create(PrivateKeyPath, FileOpenMode.Read, FileShare.DenyNone);
Signer := Provider.OpenSigner("sp", FStream);
//Digital signature of data block
Signature := Signer.Sign(Code);
//Credentials to connect using certificate
CertCreds := Package.CreateCredentials(AuthenticationMode.Certificate) As ICertCredentials;
CertCreds.UserName := "test";
CertCreds.RolesStr := "ADMINISTRATOTRS";
CertCreds.Cookie := Cookie;
CertCreds.Signature := Signature;
CertCreds.Certificate := "sp";
//Connection
Mb := MbDef.Open(CertCreds);
If Mb <> Null Then
Return Mb;
Else
Return Null;
End If;
Else
Return Null;
End If;
End Function Connect;
On executing the specified function, the check of the repository description specified in the first parameter is done. If repository exists, the connection to it is performed using digital signature. For digital signature, it is necessary to have private key, path to which is sent in the second parameter of the function. If connection is successful, the function returns open connection with repository, otherwise - Null.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Metabase;
Function Connect(Repository: String; PrivateKeyPath: String): IMetabase;
Var
MbManagerCls: MetabaseManagerFactory = New MetabaseManagerFactoryClass();
MbDef: IMetabaseDefinition;
Package: ISecurityPackage;
Provider: ICertProvider;
Cookie, Code, Signature: String;
FStream: FileStream = New FileStream(PrivateKeyPath, FileMode.Open, FileAccess.Read);
Signer: ICertSigner;
CertCreds: ICertCredentials;
Mb: IMetabase;
MbManager: IMetabaseManager;
Begin
MbManager := MbManagerCls.Active;
MbDef := MbManager.Definitions.FindById(Repository);
If MbDef <> Null Then
Package := MbManager.Packs.FindById(MbDef.SecurityPackage).Package;
//Certificate provider
Provider := Package.CertProvider;
Provider.NewCode(Var Cookie, Var Code);
Signer := Provider.OpenSigner("sp", FStream);
//Digital signature of data block
Signature := Signer.Sign(Code);
//Credentials to connect using certificate
CertCreds := Package.CreateCredentials(AuthenticationMode.amCertificate) As ICertCredentials;
CertCreds.UserName := "test";
CertCreds.RolesStr := "ADMINISTRATOTRS";
CertCreds.Cookie := Cookie;
CertCreds.Signature := Signature;
CertCreds.Certificate := "sp";
//Connection
Mb := MbDef.Open(CertCreds, ApplicationMode.amWin, LocaleCodeID.lcidRussian);
If Mb <> Null Then
Return Mb;
Else
Return Null;
End If;
Else
Return Null;
End If;
End Function;
See also: