我遵循了微软的ADAM Step by Step Guide,并在我的本地机器上设置了一个ADAM实例。我尝试使用"Mary Baker“帐户进行身份验证,但每次在下面的if (entry.Guid != null)行上都会收到COM异常。异常声明存在未知的用户名或错误的密码。
但是,我可以使用ldp实用程序连接到ADAM并成功执行简单的绑定-这样我就知道用户名和密码都是正确的。
此外,我还将用户的msDS-UserAccountDisabled属性设置为false,并将用户添加到管理员和读者角色。
有什么想法吗?
path = "LDAP://localhost:50000/O=Microsoft,c=US";
userId = "CN=Mary Baker,OU=ADAM users,";
password = "Mary@101";
DirectoryEntry entry = new DirectoryEntry(path, userId, password, AuthenticationTypes.None);
if (entry.Guid != null)
LoadWelcomeScreen();谢谢。
发布于 2011-06-09 11:06:45
ADAM将用户的惟一标识符存储在user类的displayName属性中。它们在ADAM实例中必须是唯一的,以便用户进行身份验证。如果两个用户的displayName属性都设置为'jsmith‘,那么两个用户都不能在ADAM中进行身份验证。
使用ldp实用程序查询Mary Baker的displayName。它可以是类似'mbaker‘的东西。在给定代码中使用该值作为userId。
发布于 2013-05-09 23:35:18
感谢瑞安在displayName上的提示。在我本地的ADAM实例上发布了我的测试类,以供感兴趣的人使用。
[TestMethod]
public void CreateUserAccount()
{
var username = "amurray";
var password = "ADAMComplexPassword1234";
var firstname = "Andy";
var lastname = "Murray";
const AuthenticationTypes authTypes = AuthenticationTypes.Signing |
AuthenticationTypes.Sealing |
AuthenticationTypes.Secure;
var ldapPath = "LDAP://localhost:389/OU=MyProject,OU=Applications,DC=Company,DC=ADAM";
using (var dirEntry = new DirectoryEntry(ldapPath, "MyPC\\adamuser", "Password1!", authTypes))
{
DirectoryEntry user = null;
const int ADS_PORT = 389;
const long ADS_OPTION_PASSWORD_PORTNUMBER = 6;
const long ADS_OPTION_PASSWORD_METHOD = 7;
const int ADS_PASSWORD_ENCODE_CLEAR = 1;
try
{
user = dirEntry.Children.Add(string.Format("CN={0} {1}", firstname, lastname), "user");
user.Properties["displayName"].Value = username;
user.Properties["userPrincipalName"].Value = username;
user.Properties["msDS-UserAccountDisabled"].Value = false;
user.Properties["msDS-UserDontExpirePassword"].Value = true;
user.CommitChanges();
var userid = user.Guid.ToString();
// Set port number, method, and password.
user.Invoke("SetOption", new object[]{ADS_OPTION_PASSWORD_PORTNUMBER,ADS_PORT});
user.Invoke("SetOption", new object[]{ADS_OPTION_PASSWORD_METHOD,ADS_PASSWORD_ENCODE_CLEAR});
user.Invoke("SetPassword", new object[] {password});
user.CommitChanges();
user.Close();
}
catch (Exception e)
{
var msg = e.GetBaseException().Message;
Console.WriteLine(e);
System.Diagnostics.Debug.Print(msg);
}
}
}
[TestMethod]
public void TestUserAuthentication()
{
try
{
var ldsContext = new PrincipalContext(ContextType.ApplicationDirectory, "localhost:389",
"OU=MyProject,OU=Applications,DC=Company,DC=ADAM",
ContextOptions.SimpleBind);
// Returns true if login details are valid
var isValid = ldsContext.ValidateCredentials("amurray", "ADAMComplexPassword1234", ContextOptions.SimpleBind);
}
catch (Exception e)
{
var msg = e.GetBaseException().Message;
Console.WriteLine(e);
System.Diagnostics.Debug.Print(msg);
}
}发布于 2008-11-20 03:29:32
我没有使用过ADAM或System.DirectoryServices,但我有使用LDAP和AD的经验;希望以下内容适用。
我以前从未见过以这种格式给出的用户ID。(它看起来像某种相对DN,如后面的逗号所示?)您是否尝试过将用户ID指定为完整DN (标准LDAP所要求的)或空用户名(如果ADAM支持)?
在诊断这样的网络协议问题时(查看我的程序是否在做我认为我告诉它要做的事情,并查看它正在做的事情与功能程序正在做的事情相比),我发现对非功能和功能操作都运行Wireshark是很有帮助的,看看它们有什么不同。如果你从未使用过Wireshark,希望它不会太难入门:
下载、安装并启动software.
Wireshark可以为您分析协议,因此您不必自己太熟悉协议细节,尽管您知道的越多,解释所有细节就越容易。您可以启动几个Wireshark实例来轻松比较两个不同的捕获(您的代码和LDP)。
https://stackoverflow.com/questions/303625
复制相似问题