如何配置LDAP服务器并从中获取证书以在本地进行测试? [英] How to configure LDAP server and fetch the certificates from the same to test locally?

查看:266
本文介绍了如何配置LDAP服务器并从中获取证书以在本地进行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置LDAP服务器并从中获取证书以在本地进行测试?

尝试下面的代码,但得到服务器无法运行的异常。

< b>

 DirectoryEntry rootEntry =  new  DirectoryEntry(  LDAP://some.ldap.server.com); 
rootEntry.AuthenticationType = AuthenticationTypes.None; // 或者无论需要什么
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
string searchString = (CN = EFTS -CA-TEST);

searcher.Filter = searchString; // 搜索你想要的方式。谷歌LDAP过滤器了解更多。
foreach (SearchResult结果搜索者.FindAll())
{
Console.WriteLine( account name:{0} ,result.Properties [ samaccountname]。计算> 0 ?result.Properties [ samaccountname] [ 0 ]: string .Empty);
Console.WriteLine( 通用名称:{0},result.Properties [< span class =code-string>
cn]。计算> < span class =code-digit> 0 ?result.Properties [ cn ] [ 0 ]: string .Empty);
}

解决方案

好吧,你不要告诉我们异常的来源,所以...



我会逐步检查代码,特别检查一下这是不是


 DirectoryEntry rootEntry = new DirectoryEntry(LDAP://some.ldap.server.com); 





rootEntry在该调用后为null - 您可能需要指定该连接,例如



 DirectoryEntry rootEntry = new DirectoryEntry(LDAP://some.ldap.server.com, userid,password); 





不言而喻,这些条目: -



LDAP://some.ldap.server.com

userid

密码



对于你的LDAP / AD服务器必须是正确的(我希望你刚刚更改了'some.ldap.server.com'以便在这里显示代码)



顺便说一下,这种语法更好即释放连接并整理目录条目使用(DirectoryEntry ...
{
...
}





您可能还需要像这样指定LDAP连接和/或提供目标OU,从哪里搜索LDAP:/ / CN =服务器,DC =域,DC = COM


How to configure LDAP server and fetch the certificates from the same to test locally?
Tried below code but getting the exception that the server is not operational.

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://some.ldap.server.com");
              rootEntry.AuthenticationType = AuthenticationTypes.None; //Or whatever it need be
              DirectorySearcher searcher = new DirectorySearcher(rootEntry);
              string searchString = "(CN = EFTS-CA-TEST)";
                          
              searcher.Filter = searchString;//Search how you want.  Google "LDAP Filter" for more.
              foreach (SearchResult result in searcher.FindAll())
              {
                  Console.WriteLine("account name: {0}", result.Properties["samaccountname"].Count > 0 ? result.Properties["samaccountname"][0] : string.Empty);
                  Console.WriteLine("common name: {0}", result.Properties["cn"].Count > 0 ? result.Properties["cn"][0] : string.Empty);
              }

解决方案

Well, you dont tell us where the exception is coming from, so ...

I'd step through the code and check in particular to see if this

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://some.ldap.server.com");



rootEntry is null after that call - you might need to specify that connection like

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://some.ldap.server.com","userid","password");



it goes without saying, that these entries :-

"LDAP://some.ldap.server.com"
"userid"
"password"

must be correct for your LDAP/AD server (I hope you just changed 'some.ldap.server.com' for the purposes of displaying the code here)

btw this syntax is 'better' ie to release the connection and tidy up the directory entries

using (DirectoryEntry ...
{
...
}



You might also need to specify the LDAP Connection like this and/or supply a target OU from where to search "LDAP://CN=server,DC=domain,DC=com"


这篇关于如何配置LDAP服务器并从中获取证书以在本地进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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