使用Novell.Directory.ldap.NETStandard库进行C#netcore ldap身份验证
这是我第一次使用LDAP和Active Directory。我必须使用.NetCore制作一个web api,该api必须使用ActiveDirectory(WindowsServer 2008 r2)进行身份验证,我正在按照中的示例进行操作,但我无法理解设置参数的方法。 这是我在ActiveDirectory服务器中创建的用户: 在Novell的样本中使用Novell.Directory.ldap.NETStandard库进行C#netcore ldap身份验证,c#,authentication,active-directory,.net-core,novell,C#,Authentication,Active Directory,.net Core,Novell,这是我第一次使用LDAP和Active Directory。我必须使用.NetCore制作一个web api,该api必须使用ActiveDirectory(WindowsServer 2008 r2)进行身份验证,我正在按照中的示例进行操作,但我无法理解设置参数的方法。 这是我在ActiveDirectory服务器中创建的用户: 在Novell的样本中 if (args.Length != 5) { System.Console.Out.WriteLine("Usage: mon
if (args.Length != 5)
{
System.Console.Out.WriteLine("Usage: mono VerifyPassword <host name>" + " <login dn> <password> <object dn>\n" + " <test password>");
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();
}
但我得到了这个错误:
LDAP:
LdapException:无效凭据(49)无效凭据
LdapException:服务器消息:80090308:LdapErr:DSID-0C09003A8,
注释:AcceptSecurityContext错误,数据52e,v1db1\u0000
LdapException:匹配的DN:
我还使用以下函数获取schemaDn:lc.GetSchemaDN()
,它返回以下结果:CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=local
在谷歌搜索
.Netcore
之后,没有比Novell的样本
更多的信息了,我需要你的帮助。在我使用这个之前,我也遇到过同样的问题
lc.Bind(“uid=“+objUser.UserName+”,ou=SomeValue,dc=SomeValue,dc=SomeValue”,password)代码>
另外,我没有提供像您示例中那样的版本,我也一直在处理这个问题,并且遇到了相同的错误。我必须使用Windows域和用户名登录:
String loginDN = "DOMAIN\\jperez";
String password1 = "Jperez123";
lc.Bind(loginDN, password1);
一旦我做到了这一点,我就毫无问题地加入了。它也适用于我:
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上工作。
如果您想获得域用户的登录,只需在域控制器上执行next cmd命令:
dsquery user
更多信息另一个变体,我发现我必须以以下身份登录:
广告用户名的“PartA PartB”。(请注意名称中的空格。)
例如“App Alerts”
,而我通常可以使用“AppAlerts”
登录。。。但这是我在dsquery user
中找到的完全限定名:
"CN=App Alerts,OU=SBSUsers,OU=Users,OU=MyBusiness,DC=myinc,DC=local"
我也有同样的问题,我唯一能让它工作的方法就是像这样提供登录名
lc.Bind("user@domain", "pwd")
lc.Bind("user@domain", "pwd")