【问题标题】:C# netcore ldap authentication using Novell.Directory.Ldap.NETStandard library使用 Novell.Directory.Ldap.NETStandard 库的 C# netcore ldap 身份验证
【发布时间】:2017-06-27 15:51:08
【问题描述】:

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

在 Novell 的示例中

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”,所以我在尝试:

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: Invalid Credentials (49) Invalid Credentials 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 没有比Novell's samples 更多的信息,我需要你的帮助。

【问题讨论】:

    标签: c# authentication active-directory .net-core novell


    【解决方案1】:

    也一直在解决这个问题,但遇到了同样的错误。我必须使用 Windows 域和用户名才能登录:

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

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

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我让它工作的唯一方法是提供这样的登录名

      lc.Bind("user@domain", "pwd")
      

      【讨论】:

      • 这适用于 windows 但不适用于 linux openldap 用户。
      【解决方案3】:

      在我使用这个之前我遇到了同样的问题

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

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

      【讨论】:

        【解决方案4】:

        它也适用于我:

        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,只需在域控制器上执行下一个 cmd 命令:

        dsquery user 
        

        更多信息here

        【讨论】:

          【解决方案5】:

          然而另一个变体,我发现我必须登录为:

          AD 用户名的“PartA PartB”。 (注意名称中的空格。)

          示例为"App Alerts",而我通常可以使用"AppAlerts" 登录...但这是我使用dsquery user 找到的完全限定名称:

          "CN=App Alerts,OU=SBSUsers,OU=Users,OU=MyBusiness,DC=myinc,DC=local"
          

          【讨论】:

            猜你喜欢
            • 2015-12-04
            • 1970-01-01
            • 1970-01-01
            • 2012-09-01
            • 2014-12-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多