DomainCredentials: IDomainCredentials;
The DomainCredentials property determines the credentials, under which domain authentication is performed on search.
To execute the example, add a link to the Metabase system assembly.
Sub FindSubject;
Var
MB: IMetabase;
Pack: ISecurityPackage;
DomainCreds: IDomainCredentials;
Search: ISecuritySubjectsSearch;
Subjects: ISecuritySubjects;
Subject: ISecuritySubject;
Begin
MB := MetabaseClass.Active;
Search := MB.Security.NewSubjectsSearch;
Search.NameCriteria := "TestDomain\*";
Search.SubjectCriteria(SecuritySubjectType.User) := True;
Search.SubjectCriteria(SecuritySubjectType.Group) := True;
Search.AreaIncludeDB := False;
Search.AreaIncludeNT := True;
//Settings for search in domain
Pack := New StandardSecurityPackage.Create;
//Use credentials of the current user authenticated in domain
DomainCreds := Pack.CreateCredentials(AuthenticationMode.Domain) As IDomainCredentials;
DomainCreds.LogonAsCurrentUser := True;
Search.DomainSelectCriteria := DomainSelectType.SpecifiedDomain;
Search.ProtocolSelectCriteria := ProtocolSelectType.GC;
//Search
Search.ExecuteSearch;
Subjects := Search.Subjects;
If Subjects.Count > 0 Then
For Each Subject In Subjects Do
Debug.WriteLine("Distinguished Name: " + Subject.DistinguishedName);
If Subject.Type = SecuritySubjectType.User Then
Debug.WriteLine("Domain User Name: " + Subject.UserPrincipalName);
End If;
End For;
End If;
End Sub FindSubject;
On executing the example all security subjects registered in the TestDomain domain are searched. Different names for the found subjects are displayed in the development environment console. Domain names are also displayed for domain users.
See also: