sam*_*r11 1 c# authentication directoryservices adam
我已经设置了一个ADAM实例并添加了一些测试用户.从c#我可以使用Windows帐户绑定到ADAM,但我无法使用其中一个ADAM用户进行绑定.(我可以成功绑定ldp中的adam用户)我确保通过将msDS-UserAccountDisabled属性设置为false来启用用户.当我与我的Windows帐户绑定时,我可以成功搜索并恢复ADAM用户的属性,但我仍在努力验证它们,当我尝试使用ADAM用户帐户绑定时,我收到错误:
错误:System.Runtime.InteropServices.COMException(0x8007052E):登录失败:未知的用户名或密码错误.在System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
这是我正在使用的代码:
string userName = txtUserName.Text;
string password = txtPassword.Text;
string ADConnectionString = "LDAP://localhost:389/CN=sandbox,DC=ITOrg";
DirectoryEntry entry = new DirectoryEntry(ADConnectionString);
entry.Username = "myComputer\\Administrator";
entry.Password = "myPassword";
try
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(CN=" + userName + "))";
SearchResultCollection result = searcher.FindAll();
if (result.Count > 0)
{
//bind with simple bind
using (DirectoryEntry de = new DirectoryEntry(result[0].Path, userName, password,AuthenticationTypes.None))
{
if (de.Guid != null) // this is the line where it dies
{
Label1.Text = "Successfully authenticated";
Label2.Text = result[0].Properties["displayName"][0].ToString();
Label3.Text = result[0].Properties["telephoneNumber"][0].ToString();
} else
{
Lable1.Text = "Unable to Authenticate";
}
}
}
else
{
Lable1.Text = "UserName :" + userName + " not found";
}
} catch(Exception ex)
{
Label1.Text = "Error searching: " + ex.ToString();
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助,非常感谢!
小智 6
这可能是用户名格式问题.在SDS中验证ADAM用户时,必须使用LDAP简单绑定并使用ADAM支持的名称格式.ADAM在技术上也允许您使用摘要身份验证,但这在SDS(仅限SDS.Protocols)中不可用,因此不适用于您的代码方法.
您正在使用简单绑定,因为您已设置AuthenticationTypes.None以使该部分正常.那么可能错误的部分是用户名格式.
ADAM接受用户的完整DN,他们的displayName(如果设置且唯一)和/或userPrincipalName(如果设置且唯一)作为"可绑定"用户名,因此从用户的完整DN开始,并查看是否有效.如果是这样,您也可以尝试其他用户名值.请注意,您可以在ADAM中为displayName或userPrincipalName添加任何内容.没有验证.只需确保值是唯一的.
如果你真的想对ADAM做一些类型的绑定认证,你可以通过使用.NET 3.5中的PrincipalContext的ValidateCredentials方法获得更好的性能和扩展.
这种东西在http://www.directoryprogramming.net上的论坛中被记录和讨论,并且是一个我经常更频繁的地方,因为它是我的网站.:)一位朋友告诉我这篇文章或者我从未见过它.
| 归档时间: |
|
| 查看次数: |
4857 次 |
| 最近记录: |