简体   繁体   English

LDAP连接IP地址和端口号

[英]LDAP Connecting with IP address and Port Number

The company I work for has a product that uses Active Directory to enable our product's security features using a library that includes DirectoryEntry and DirectorySearcher components. 我工作的公司有一个产品,该产品使用Active Directory通过包含DirectoryEntryDirectorySearcher组件的库来启用我们产品的安全功能。

If someone is a member of group FOO , they have standard access. 如果某人是FOO组的成员,则他们具有标准访问权限。 If they are a member of FOO-ADMIN , they have Admin rights. 如果他们是FOO-ADMIN的成员,则具有管理员权限。

We have a potential client who does not use Active Directory. 我们有一个不使用Active Directory的潜在客户。 They have an Apache server running their LDAP, and they have provided this screenshot. 他们有一个运行LDAP的Apache服务器,并且提供了此屏幕截图。

客户属性

Above, it looks like I would need to connect to a domain of xxx.xxx.5.101:389 (ie DirectoryEntry("LDAP://xxx.xxx.5.101:389") ), but how does that "DN or user" field fit with the password? 在上面,看来我需要连接到xxx.xxx.5.101:389的域(即DirectoryEntry(“ LDAP://xxx.xxx.5.101:389”) ),但是该“ DN或用户”是怎么做的字段是否适合密码?

Are Active Directory components able to do LDAP authentication on an Apache system, or would the code need completely different controls? Active Directory组件是否能够在Apache系统上进行LDAP身份验证,或者代码需要完全不同的控件?

Here is some crude code that I have put together: 这是我整理的一些原始代码:

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

I am bothered by the "path like" parameters they pass in for the "DN or user" field, particularly when it shows them providing a password with it. 我为它们为“ DN或用户”字段传入的“路径类似”参数感到困扰,特别是当它显示使用它们提供密码时。

We do not have an Apache environment to test this on. 我们没有Apache环境可以对此进行测试。 Our company does not want me going to this client with a lot of unnecessary questions. 我们公司不希望我向这个客户提出很多不必要的问题。

UPDATE: 更新:
Still need a way to do this. 仍然需要一种方法来做到这一点。 Starting a bounty. 开始赏金。 Maybe bringing some attention to this will get me a solution. 也许对此有所注意会给我一个解决方案。

当前状态

In the screenshot above, the value for username in the code was both cn-mikead,ou=sysdata,ou=townhall,o=toh and separately mikead , both with the same COM Exception at the call to FindAll() . 在上面的屏幕截图中,代码中的username值分别为cn-mikead,ou=sysdata,ou=townhall,o=toh mikead和单独的mikead ,在调用FindAll()都具有相同的COM异常。

Here is the code I have now. 这是我现在的代码。

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 can run LDAP, my advice would be to make sure your client has LDAP configured properly on their server. Apache可以运行LDAP,我的建议是确保您的客户端在其服务器上正确配置了LDAP。 This could be done in the httpd.conf on their server 这可以在其服务器上的httpd.conf中完成

I wish I had more time to give you a more complete answer. 希望我有更多时间给您更完整的答案。 But let me see if this helps at all. 但是,让我看看这是否有帮助。 Group membership works differently in eDirectory and there is no memberOf attribute. 组成员资格在eDirectory中的工作方式不同,并且没有memberOf属性。 You also may find that you have to go lower level than the DirectoryEntry, DirectorySearcher, etc... (as these are tailored for AD). 您还可能会发现自己必须比DirectoryEntry,DirectorySearcher等级别更低(因为它们是针对AD量身定制的)。 The System.DirectoryServices.Protocols will give you lower level access. System.DirectoryServices.Protocols将为您提供较低级别的访问权限。

Alternately, Novell also has c# libraries that you could consider using: https://www.novell.com/developer/ndk/ldap_libraries_for_c_sharp.html 另外,Novell还具有您可以考虑使用的c#库: https : //www.novell.com/developer/ndk/ldap_libraries_for_c_sharp.html

  1. I suggest you first bind to the database as a user with the rights you need to search or anonymously (if anonymous can search) , and search for the (&(cn=USERNAME)(objectclass=Person)) to find the dn you need to bind as. 我建议您首先以具有所需搜索权限的用户身份或匿名(如果可以匿名搜索)绑定到数据库,然后搜索(&(cn = USERNAME)(objectclass = Person))以查找所需的dn绑定为。
  2. Now bind as the user dn you found with the supplied credentials and get the groupMembership attribute. 现在,使用提供的凭据将您绑定为用户dn并获得groupMembership属性。
  3. Examine the groupMembership attribute to determine your privileges. 检查groupMembership属性以确定您的特权。

If you can't get the groupMembership attribute to work, alternately, you can search the directory for the group: ((cn=GROUPNAME)(objectclass=groupOfNames)) Then you can look through the groupOfNames:member attributes to find your username. 如果您无法使groupMembership属性正常工作,则可以在目录中搜索该组:((cn = GROUPNAME)(objectclass = groupOfNames))然后,您可以查看groupOfNames:member属性以查找您的用户名。

I'd start by trying to get just binding/authenticating up and then add the group stuff. 我将首先尝试进行绑定/身份验证,然后添加组内容。 There's an example of binding here: https://www.codeproject.com/Articles/5969/Authentication-against-Active-Directory-and-Edirec 这里有一个绑定示例: https : //www.codeproject.com/Articles/5969/Authentication-against-Active-Directory-and-Edirec

Or an alternate method here if you have certificate issues: https://www.codeproject.com/Articles/19097/eDirectory-Authentication-using-LdapConnection-and 如果您遇到证书问题,也可以在这里使用另一种方法: https : //www.codeproject.com/Articles/19097/eDirectory-Authentication-using-LdapConnection-and

Here are some useful references: 以下是一些有用的参考:

https://www.mediawiki.org/wiki/Extension:LDAP_Authentication/Examples#Configuration_for_non-AD_domains 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://docs.oracle.com/cd/E36500_01/E36503/html/ldap-filters-attrs-users.html#ldap-filters-attrs-users-openldap

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

Connecting to LDAP from C# using DirectoryServices 使用DirectoryServices从C#连接到LDAP

https://forums.novell.com/showthread.php/491292-Is-user-member-of-group-in-C 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 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 http://mikemstech.blogspot.com/2013/03/searching-non-microsoft-ldap.html

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

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

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