CredentialsSet: ICredentialsSet;
CredentialsSet: Prognoz.Platform.Interop.Metabase.ICredentialsSet;
The CredentialsSet property returns the collection of credentials under which the connection can be performed.
The CredentialsSet collection is used on working with the description of the repository. User credentials, stored in the collection can be used on user impersonation. All credentials added to the collection are encrypted and saved to the registry of the operating system.
Add a link to the Metabase system assembly.
Function SetCredentials(Definition: String; Realm: String; User: String; Password: String): Boolean;
Var
MBMan: IMetabaseManager;
MBDef: IMetabaseDefinition;
Link: IMetabaseLink;
ScPack: ISecurityPackage;
DefCrsSet: ICredentialsSet;
CrsRealm: ICredentialsRealm;
Crs: IPasswordCredentials;
Begin
MBMan := MetabaseManagerFactory.Active;
MBDef := MBMan.Definitions.FindById(Definition);
If MBDef = Null Then
Return False;
Else
Link := MBDef As IMetabaseLink;
End If;
If Realm.IsEmpty Then
Crs := Link.Credentials As IPasswordCredentials;
Crs.UserName := User;
Crs.Password := Password;
Else
ScPack := MBMan.Packs.FindById(MbDef.SecurityPackage).Package;
Crs := ScPack.CreateCredentials(AuthenticationMode.Password) As IPasswordCredentials;
//New credentials
Crs.UserName := User;
Crs.Password := Password;
//Collection of description credentials
DefCrsSet := Link.CredentialsSet;
//Search for a record by the scope
//If the record is found then update the credentials
//Otherwise create new record
CrsRealm := DefCrsSet.Find(Realm);
If CrsRealm = Null Then
CrsRealm := DefCrsSet.Add(Realm);
CrsRealm.Credentials := Crs;
Else
CrsRealm.Credentials := Crs;
End If;
End If;
Mbdef.Save;
Return True;
End Function SetCredentials;
Function SetCredentials(Definition: String; Realm: String; User: String; Password: String): Boolean;
Var
Man: MetabaseManagerFactory = New MetabaseManagerFactoryClass();
MBMan: IMetabaseManager;
MBDef: IMetabaseDefinition;
Link: IMetabaseLink;
ScPack: ISecurityPackage;
DefCrsSet: ICredentialsSet;
CrsRealm: ICredentialsRealm;
Crs: IPasswordCredentials;
Begin
MBMan := Man.Active;
MBDef := MBMan.Definitions.FindById(Definition);
If MBDef = Null Then
Return False;
Else
Link := MBDef As IMetabaseLink;
End If;
If String.IsNullOrEmpty(Realm) Then
Crs := Link.Credentials As IPasswordCredentials;
Crs.UserName := User;
Crs.Password := Password;
Else
ScPack := MBMan.Packs.FindById(MbDef.SecurityPackage).Package;
Crs := ScPack.CreateCredentials(AuthenticationMode.amPassword) As IPasswordCredentials;
//New credentials
Crs.UserName := User;
Crs.Password := Password;
//Collection of description credentials
DefCrsSet := Link.CredentialsSet;
//Search for a record by the scope
//If the record is found then update the credentials
//Otherwise create new record
CrsRealm := DefCrsSet.Find(Realm);
If CrsRealm = Null Then
CrsRealm := DefCrsSet.Add(Realm);
CrsRealm.Credentials := Crs;
Else
CrsRealm.Credentials := Crs;
End If;
End If;
Mbdef.Save();
Return True;
End Function;
The specified function can be applied to update the credentials saved together with the description of the repository or for adding new records to the collection of credentials. On function executing the search for the description of the repository passed in the Definition parameter is performed. If the description is missing then the function returns False. If the scope is not specified, the credentials for the default description will be updated. On specifying the scope in the collection the new record will be created or the existing one will be updated.
See also: