使用Unicode进行AD身份验证

时间:2011-10-12 16:50:40

标签: delphi active-directory delphi-xe

使用以下方法在C#中实现AD身份验证:

DirectoryEntry entry = 
  new DirectoryEntry(_path, domainAndUsername, pwd, AuthenticationTypes.Secure);

其中_path是LDAP:// +完全限定的域名(例如,域控制器的ip)。

现在我必须使用Delphi做同样的事情。所以我在http://www.freemeg.com/index.php/projects/projects-2/15-delphi-ldap-authentication-component

找到了Solomon的优秀Delphi 2007 LDAP实现
  1. 有没有人使用Delphi 2009+(unicode)的工作版本?
  2. 是否有人使用简单的AD身份验证处理(例如验证)域\用户ID和密码?
  3. 在C#中,很好的部分是我不需要遍历AD - 我只是通过LDAP执行一级搜索 - 只是为了检查用户是否经过身份验证。

1 个答案:

答案 0 :(得分:1)

Tony Caduto为我提供了Synapse解决方案:

我从我创建的身份验证对象中删除了这些东西,我不想发布整个内容,因为其中有许多其他非相关内容。

这应该让你去,关键是将AD用户名与'@ your.ad.domain.name'连接起来 成功绑定后,可以通过提供基本DN对AD目录进行搜索 并使用ldapsend单元的搜索功能。

我发现这比其他方法更快,而且它很稳固。你需要获得trunk版本 synapse所以它适用于更高版本的delphi。

uses ldapsend

var
    fldap:tldapsend;
    fad_domain,ausername,apassword:string;
begin
ausername:='your AD username';
apassword:='your AD password';
fldap := TLDAPSend.Create;
fad_domain:= 'your.ad.domain';
fldap.TargetHost:=fad_domain;
//next line is the key to getting AD authentication working
fldap.UserName := ausername+'@'+fad_domain;
fldap.Password := apassword;
try
   try
      if fldap.Login then
         if fldap.Bind then
            begin
                    //user is succesfully authenticated at this point

            end else
                raise exception.Create('LDAP bind failed.');
   except
         on e:exception do
            //whatever
   end;
finally
       fldap.logout;
       freeandnil(fldap);
end;
end;

感谢Tony !!!!