繁体   English   中英

LDAP连接IP地址和端口号

[英]LDAP Connecting with IP address and Port Number

我工作的公司有一个产品,该产品使用Active Directory通过包含DirectoryEntryDirectorySearcher组件的库来启用我们产品的安全功能。

如果某人是FOO组的成员,则他们具有标准访问权限。 如果他们是FOO-ADMIN的成员,则具有管理员权限。

我们有一个不使用Active Directory的潜在客户。 他们有一个运行LDAP的Apache服务器,并且提供了此屏幕截图。

客户属性

在上面,看来我需要连接到xxx.xxx.5.101:389的域(即DirectoryEntry(“ LDAP://xxx.xxx.5.101:389”) ),但是该“ DN或用户”是怎么做的字段是否适合密码?

Active Directory组件是否能够在Apache系统上进行LDAP身份验证,或者代码需要完全不同的控件?

这是我整理的一些原始代码:

/// <summary>
/// Untested Method
/// </summary>
/// <param name="hostIp">String (EX: xxx.xxx.5.101)</param>
/// <param name="port">Int (EX: 389)</param>
/// <param name="user">String (EX: cn=danibla,ou=sysdata,ou=townhall,o=toh)</param>
/// <param name="password">String - provided password</param>
/// <param name="groupsLike">String (EX: find all groups like FOO)</param>
/// <returns>String[] array of matching membership groups</returns>
public static String[] GetMemberships(String hostIp, int port, String user, String password, String groupsLike)
{
    var results = new List<String>();
    var path = String.Format("LDAP://{0}:{1}", hostIp, port);
    using (var entry = new DirectoryEntry(path, user, password))
    {
        using (var search = new DirectorySearcher(entry, String.Format("(CN={0}*)", groupsLike)))
        {
            var expression = new Regex("CN=([^,]*),", RegexOptions.Compiled & RegexOptions.IgnoreCase);
            foreach (SearchResult item in search.FindAll())
            {
                var match = expression.Match(item.Path);
                var name = match.Groups[1].Value;
                if (name.StartsWith(groupsLike, StringComparison.OrdinalIgnoreCase))
                {
                    if (!results.Contains(name))
                    {
                        results.Add(name);
                    }
                }
            }
        }
    }
    return results.ToArray();
}

我为它们为“ DN或用户”字段传入的“路径类似”参数感到困扰,特别是当它显示使用它们提供密码时。

我们没有Apache环境可以对此进行测试。 我们公司不希望我向这个客户提出很多不必要的问题。

更新:
仍然需要一种方法来做到这一点。 开始赏金。 也许对此有所注意会给我一个解决方案。

当前状态

在上面的屏幕截图中,代码中的username值分别为cn-mikead,ou=sysdata,ou=townhall,o=toh mikead和单独的mikead ,在调用FindAll()都具有相同的COM异常。

这是我现在的代码。

public static String[] Groups(String domain, int port, String username, int authenticationValue, String startsWith)
{
    String name;
    var results = new List<String>();
    var ldapPath =
        String.IsNullOrEmpty(domain) ? null :
        (0 < port) ?
        String.Format("LDAP://DC={0}:{1}", domain, port) :
        String.Format("LDAP://DC={0}", domain);
    using (var entry = new DirectoryEntry(String.Format("WinNT://{0}/{1}", Environment.UserDomainName, username)))
    {
        name = String.Format("{0}", entry.Properties["fullName"].Value);
    }
    var filter = String.Format("(CN={0}", name);
    var expression = new Regex("CN=([^,]*),", RegexOptions.Compiled & RegexOptions.IgnoreCase);
    using (var entry = new DirectoryEntry(ldapPath))
    {
        entry.AuthenticationType = (AuthenticationTypes)authenticationValue;
        using (var search = new DirectorySearcher(entry) { Filter = filter })
        {
            search.PropertiesToLoad.Add("memberOf");
            try
            {
                foreach (SearchResult item in search.FindAll())
                {
                    foreach (var property in item.Properties["memberOf"])
                    {
                        var name = expression.Match(String.Format("{0}", property)).Groups[1].Value;
                        if (name.StartsWith(startsWith, StringComparison.OrdinalIgnoreCase))
                        {
                            if (!results.Contains(name))
                            {
                                results.Add(name);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                LogError("Groups", err);
            }
        }
    }
    return results.ToArray();
}

Apache可以运行LDAP,我的建议是确保您的客户端在其服务器上正确配置了LDAP。 这可以在其服务器上的httpd.conf中完成

希望我有更多时间给您更完整的答案。 但是,让我看看这是否有帮助。 组成员资格在eDirectory中的工作方式不同,并且没有memberOf属性。 您还可能会发现自己必须比DirectoryEntry,DirectorySearcher等级别更低(因为它们是针对AD量身定制的)。 System.DirectoryServices.Protocols将为您提供较低级别的访问权限。

另外,Novell还具有您可以考虑使用的c#库: https : //www.novell.com/developer/ndk/ldap_libraries_for_c_sharp.html

  1. 我建议您首先以具有所需搜索权限的用户身份或匿名(如果可以匿名搜索)绑定到数据库,然后搜索(&(cn = USERNAME)(objectclass = Person))以查找所需的dn绑定为。
  2. 现在,使用提供的凭据将您绑定为用户dn并获得groupMembership属性。
  3. 检查groupMembership属性以确定您的特权。

如果您无法使groupMembership属性正常工作,则可以在目录中搜索该组:((cn = GROUPNAME)(objectclass = groupOfNames))然后,您可以查看groupOfNames:member属性以查找您的用户名。

我将首先尝试进行绑定/身份验证,然后添加组内容。 这里有一个绑定示例: https : //www.codeproject.com/Articles/5969/Authentication-against-Active-Directory-and-Edirec

如果您遇到证书问题,也可以在这里使用另一种方法: https : //www.codeproject.com/Articles/19097/eDirectory-Authentication-using-LdapConnection-and

以下是一些有用的参考:

https://www.mediawiki.org/wiki/扩展名:LDAP_Authentication / Examples#Configuration_for_non-AD_domains

https://docs.oracle.com/cd/E36500_01/E36503/html/ldap-filters-attrs-users.html#ldap-filters-attrs-users-openldap

https://www.ibm.com/support/knowledgecenter/zh-CN/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_config_edirectoryLdapFilterProperties.html

使用DirectoryServices从C#连接到LDAP

https://forums.novell.com/showthread.php/491292-Is-user-member-of-group-in-C

https://www.novell.com/documentation/developer/ldapcsharp/?page=/documentation/developer/ldapcsharp/cnet/data/bovtz77.html

http://mikemstech.blogspot.com/2013/03/searching-non-microsoft-ldap.html

https://www.sqlservercentral.com/Forums/Topic811694-391-1.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM