【问题标题】:Why does open OpenLDAP require a cn=username?为什么打开 OpenLDAP 需要 cn=username?
【发布时间】:2013-03-31 02:18:59
【问题描述】:

我正在使用 C# 连接到 OpenLDAP,当我传入我的用户名和密码时,我必须将它们作为 cn=Username, Password 传递到我的 LdapConnection 对象中。如果我只是传入用户名和密码,我对 Bind 的调用将失败。为什么我必须这样做?我的 OpenLDAP 服务器是否配置错误?

【问题讨论】:

  • CN= 前缀是 LDAP 规范的一部分 - 它是 Common Name 的缩写 - 不,没有任何错误配置 - 这正是 LDAP 识别对象(如用户)

标签: c# openldap


【解决方案1】:

这只是实施的副产品。 Novell 的 eDirectory 解决方案采用了非常相似的方法,我使用相同的 Novell.Directory.Ldap 代码来处理对 eDirectory 和 OpenLDAP 的绑定请求。现在显然,用户自己在授权时不必输入整个 CN - 我们可以根据他们的 UID 对他们进行搜索:

//Setup the initial bind for the admin user
var lc = new LdapConnection();
lc.SecureSocketLayer = SSL;
lc.UserDefinedServerCertValidationDelegate += delegate { return true; };
lc.Connect(ServerName, Port);
lc.Constraints.TimeLimit = Timeout;
lc.Bind(AdminUsername, AdminPassword);

现在我只过滤用户,并使用他们的专有名称或完整的容器名称 (CN) 进行绑定:

//Ex. (uid=jsmith)
string filter = config.LdapAuth.LdapFilter.Replace("{{uid}}", username);

//Find the user we're trying to authorize
var lsc = lc.Search(config.LdapAuth.LdapDomain, LdapConnection.SCOPE_SUB, filter, null, false);

if (lsc.hasMore())
{
    LdapEntry nextEntry = lsc.next();

    //Check the Entries DN so we can properly bind 
    lc.Bind(nextEntry.DN, Password);
}

这是我能找到的最广泛使用的方法,到目前为止效果很好。

【讨论】:

    猜你喜欢
    • 2019-03-08
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    相关资源
    最近更新 更多