本文介绍了使用Novell.Directory.Ldap.NETStandard库的C#netcore ldap身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是我第一次使用LDAP和Active Directory.我必须使用.NetCore制作一个必须通过ActiveDirectory(WindowsServer 2008 r2)进行身份验证的Web api,我正在按照 Novell.Directory.Ldap.NETStandard ,但我不明白我必须设置参数的方式.这是我在ActiveDirectory Server中创建的用户:

it is the first time I'm working with LDAP and Active Directory. I have to make a web api with .NetCore that have to authenticate with ActiveDirectory (WindowsServer 2008 r2), I'm following the samples in Novell.Directory.Ldap.NETStandard but i can't understand the way that I must set the parameters.This is the users that I created in ActiveDirectory Server:

在Novell的示例中

In Novell's samples

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();
}

在Novell的示例中,用户"参数看起来像这样的"ou = sales,o = Acme",所以我正在尝试:

In Novell's samples the "user" parameters looks like this "ou=sales,o=Acme", so I was trying:

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:

But I get this error:LDAP:

我还获得具有以下功能的schemaDn:lc.GetSchemaDN(),返回此结果:CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=local

I also get the schemaDn with this funciton: lc.GetSchemaDN(), that return this result: CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=local

使用Google谷歌搜索后,除了Novell's samples之外,没有更多有关.Netcore的信息,请帮助我.

After googling there is no much information with .Netcore than the Novell's samples, please I need your help.

推荐答案

同样也对此进行了研究,并遇到了相同的错误.我必须使用Windows域和用户名登录:

Been working on this as well and ran into the same error. I had to use the Windows domain and username to log in:

String loginDN = "DOMAIN\\jperez";
String password1 = "Jperez123";

lc.Bind(loginDN, password1);

一旦我这样做,我就没问题了.

Once I did that, I got in without issue.

这篇关于使用Novell.Directory.Ldap.NETStandard库的C#netcore ldap身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 23:32