A dignified successor to unsupported CData components suite - Active Directory
Connecting your information system with Active Directory is an expected and favourable option for many business solutions written in Delphi. Frankly, we can use a couple of approaches how to achieve it - however, the time-saving and efficient solution will be probably the best way.
There was a suitable option for all Delphi developers till its version 11 - CData components package. It's a very huge set of components, you can connect to almost all imagineable and popular services like social media, online shopping, mail providers, weather services and many more. These components are based on an easy approach when the communication with a given service is FireDac-like so that you can use all known and traditional dataset/datasource methods.
For a comprehensive information, a price tag of CData suite must be mentioned. Honestly, the Enterprise+ package (contains tens of additional components for approaching many popular services, including Active Directory) costs about USD 2000. On one side, the value you get is great - on the other hand, the price is simply exorbitant, especially for small developers (individuals, sole traders).
As a matter of fact, pricing is only one bottleneck. The most important one is that CData suite is available and supported not any longer for Delphi 12 and above. It was a very sad discovery for me when I had found that these components - implemented rather deeply into our concerned systems - weren't available and some replacement must be obtained.
Based on a long-term positive collaboration with nSoftware Inc., I downloaded a trial package of their IPWorks suite. After exchanging a few e-mails with their technical support (I must highlight that they are real professionals and react very quickly and comprehensively) I was assured that TipwLDAP component will meet all of my expectations and functionality towards Active Directory.
Main migration from CData to IPWorks was a question of approximately one man-day. In fact, connection to Active Directory server is very simple, based on providing the credentials, server address and filter for searching. The basic idea is to perform a search and handle the OnSearchResult event. For each returned result OnSearchResult will fire once.
Screen.Cursor:=crHourGlass;
ipwLDAP1.ServerName:=edADURL.Text;
ipwLDAP1.ServerPort:=StrToIntDef(edADPort.Text,389);
ipwLDAP1.DN:=edADUserName.Text;
ipwLDAP1.Password:=edADPassword.Text;
ipwLDAP1.Bind;
ipwLDAP1.DN:=edADBaseDN.Text;
ipwLDAP1.Timeout:=0;
if Pos('\',edADUserName.Text)>0 then ADUNClear:=StrAfter(edADUserName.Text,'\') else ADUNClear:=edADUserName.Text;
ipwLDAP1.Search('SamAccountName='+ADUNClear);
The values of particular attributes related to searched account can be retrieved very comfortably by evaluating OnSearchResult event:
procedure TForm1.ipwLDAP1SearchResult(Sender: TObject; MessageId: Integer;
const DN: string);
var I:integer;
begin
if DN<>'' then
begin
for I:=0 to ipwLDAP1.Attributes.Count-1 do
begin
if AnsiLowerCase(ipwLDAP1.Attributes[I].AttributeType)=AnsiLowerCase('DisplayName') then
Xosoba:=ipwLDAP1.Attributes[I].Value;
if AnsiLowerCase(ipwLDAP1.Attributes[I].AttributeType)=AnsiLowerCase('TelephoneNumber') then
UID1:=ipwLDAP1.Attributes[I].Value;
if AnsiLowerCase(ipwLDAP1.Attributes[I].AttributeType)=AnsiLowerCase('FacsimileTelephoneNumber') then
UID2:=ipwLDAP1.Attributes[I].Value;
...
end;
As a finalization, calling of Unbind method is recommended after the searching is finished:
procedure TFormServAD.ipwLDAP1SearchComplete(Sender: TObject;
MessageId: Integer; const DN: string; ResultCode: Integer;
const ResultDescription: string);
begin
ipwLDAP1.Unbind;
Screen.Cursor:=crDefault;
end;
Compared to CData Active Directory component, solution from IPWorks is lightweight, faster and less expensive - the price of IPWorks package is about USD 1 500. And the most important fact for every developer, I think that support for future versions of Delphi is guaranteed.
About the Author Ing. Karel Janecek, MBA, MSc.www.torry.net