使用 Novell.Directory.Ldap.NETStandard 库的 C# netcore ldap 身份验证 [英] C# netcore ldap authentication using Novell.Directory.Ldap.NETStandard library

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

问题描述

这是我第一次使用 LDAP 和 Active Directory.我必须使用 .NetCore 制作一个必须使用 ActiveDirectory (WindowsServer 2008 r2) 进行身份验证的 web api,我正在关注

在 Novell 的示例中

if (args.Length != 5){System.Console.Out.WriteLine("用法:mono VerifyPassword <主机名>" + " <登录 dn> <密码> <对象 dn>
" + " <测试密码>");System.Console.Out.WriteLine("示例:mono VerifyPassword Acme.com" + ""cn=Admin,o=Acme" secret
" + " "cn=JSmith,ou=Sales,o=Acme"测试密码");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 密码 = args[2];System.String objectDN = args[3];System.String testPassword = args[4];LdapConnection conn = new LdapConnection();尝试{//连接到服务器conn.Connect(ldapHost, ldapPort);//向服务器认证conn.Bind(ldapVersion, loginDN, 密码);LdapAttribute attr = new LdapAttribute("userPassword", testPassword);bool 正确 = conn.Compare(objectDN, attr);System.Console.Out.WriteLine(正确吗?"密码正确.":"密码错误.
");//与服务器断开连接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;尝试{//连接到服务器lc.Connect(ldapHost, ldapPort);var sdn = lc.GetSchemaDN();//向服务器认证lc.Bind(ldapVersion, loginDN, password1);...}捕获(LdapException e){Console.WriteLine("错误:" + e.ToString());}

但我收到此错误:LDAP:

<块引用>

LdapException: Invalid Credentials (49) Invalid CredentialsLdapException:服务器消息:80090308:LdapErr:DSID-0C0903A8,评论:AcceptSecurityContext 错误,数据 52e,v1db1u0000LdapException: 匹配的 DN:

我也用这个函数得到schemaDn:lc.GetSchemaDN(),返回这个结果:CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=本地

谷歌搜索后,.Netcore 没有比 Novell 的示例 多的信息,我需要你的帮助.

解决方案

也一直在处理这个问题,但遇到了同样的错误.我必须使用 Windows 域和用户名登录:

String loginDN = "DOMAIN\jperez";String password1 = "Jperez123";lc.绑定(登录DN,密码1);

一旦我这样做了,我就毫无问题地进入了.

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:

In Novell's samples

if (args.Length != 5)
{
    System.Console.Out.WriteLine("Usage:   mono VerifyPassword <host name>" + " <login dn> <password> <object dn>
" + "         <test password>");
    System.Console.Out.WriteLine("Example: mono VerifyPassword Acme.com " + ""cn=Admin,o=Acme" secret
" + "         "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.
");

    // disconnect with the server
    conn.Disconnect();
}

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

But I get this error: LDAP:

LdapException: Invalid Credentials (49) Invalid Credentials LdapException: Server Message: 80090308: LdapErr: DSID-0C0903A8, comment: AcceptSecurityContext error, data 52e, v1db1u0000 LdapException: Matched DN:

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

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

解决方案

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 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆