刚刚在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上找到了所罗门卓越的Delphi2007LDAP实现
在C#中,好的部分是我不需要遍历AD --我只是通过LDAP执行一级搜索--只是为了检查用户是否经过身份验证。
发布于 2011-11-10 18:35:31
托尼·卡普托为我提供了Synapse解决方案:
我把这些东西从我创建的身份验证对象中删除,我不想发布全部内容,因为里面还有很多其他无关的东西。
这应该会让您开始工作,关键是在成功绑定之后,将AD用户名与'@your.ad.domain.name‘连接起来,然后可以通过提供基本DN并使用ldapsend单元的搜索函数对AD目录进行搜索。
我发现这个方法比其他方法更快,而且是可靠的。您确实需要获得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;感谢托尼!
https://stackoverflow.com/questions/7743601
复制相似问题