使用Novell.Directory.Ldap.NETStandard库进行C#netcore ldap身份validation

这是我第一次使用LDAP和Active Directory。 我必须使用.NetCore创建一个必须使用ActiveDirectory(WindowsServer 2008 r2)进行身份validation的web api,我正在关注Novell.Directory.Ldap.NETStandard中的示例,但我无法理解我必须设置参数的方式。 这是我在ActiveDirectory Server中创建的用户:

http://sofzh.miximages.com/c%23/A7iGq.jpg

在Novell的样本中

if (args.Length != 5) { System.Console.Out.WriteLine("Usage: mono VerifyPassword " + "   \n" + " "); System.Console.Out.WriteLine("Example: mono VerifyPassword Acme.com " + "\"cn=Admin,o=Acme\" secret\n" + " \"cn=JSmith,ou=Sales,o=Acme\" testPassword"); System.Environment.Exit(0); } int ldapPort = LdapConnection.DEFAULT_PORT; int ldapVersion = LdapConnection.Ldap_V3; System.String ldapHost = args[0]; System.String loginDN = args[1]; System.String password = args[2]; System.String objectDN = args[3]; System.String testPassword = args[4]; LdapConnection conn = new LdapConnection(); try { // connect to the server conn.Connect(ldapHost, ldapPort); // authenticate to the server conn.Bind(ldapVersion, loginDN, password); LdapAttribute attr = new LdapAttribute("userPassword", testPassword); bool correct = conn.Compare(objectDN, attr); System.Console.Out.WriteLine(correct?"The password is correct.":"The password is incorrect.\n"); // disconnect with the server conn.Disconnect(); } 

在Novell的示例中,“用户”参数看起来像“ou = sales,o = Acme”,所以我试图:

 int ldapPort = LdapConnection.DEFAULT_PORT; int ldapVersion = LdapConnection.Ldap_V3; bool compareResults = false; String ldapHost = "192.168.58.251"; String loginDN = @"cn=jperez"; String password1 = "Jperez123"; String dn = "mydn"; LdapConnection lc = new LdapConnection(); LdapAttribute attr = null; try { // connect to the server lc.Connect(ldapHost, ldapPort); var sdn = lc.GetSchemaDN(); // authenticate to the server lc.Bind(ldapVersion, loginDN, password1); ... } catch (LdapException e) { Console.WriteLine("Error: " + e.ToString()); } 

但我得到这个错误:LDAP:

LdapException:无效的凭据(49)无效的凭据LdapException:服务器消息:80090308:LdapErr:DSID-0C0903A8,注释:AcceptSecurityContext错误,数据52e,v1db1 \ u0000 LdapException:匹配的DN:

我还使用此函数获取schemaDn: lc.GetSchemaDN() ,返回此结果: CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=local

谷歌搜索后没有太多关于.Netcore信息, .Netcore不是Novell's samples ,请我帮忙。

一直在努力,并遇到了同样的错误。 我不得不使用Windows域和用户名登录:

 String loginDN = "DOMAIN\\jperez"; String password1 = "Jperez123"; lc.Bind(loginDN, password1); 

一旦我这样做,我就没有问题。

在我使用它之前,我遇到了同样的问题

lc.Bind("uid=" + objUser.UserName + ",ou=SomeValue,dc=SomeValue,dc=SomeValue",password);

我也没有提供像你的例子中的版本

它也适用于我:

 var ldapVersion = LdapConnection.Ldap_V3; var loginDN = "CN=victor,CN=Users,DC=example,DC=com"; var password = "123"; conn.Bind(ldapVersion, loginDN, password); 

适用于具有默认域设置的Windows Server 2012r2。 如果要为域用户获取loginDN,只需在域控制器上执行next cmd命令:

 dsquery user 

更多信息在这里