如何确保我可以成功连接到LDAP? [英] How to ensure I could connect to LDAP successfully?

查看:175
本文介绍了如何确保我可以成功连接到LDAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是客户提供的详细信息(样本).使用给定的详细信息,我想确认是否可以使用给定的凭据成功连接LDAP.如何确保?

请注意,我们使用C#.NET作为开发语言.提前谢谢.



DEV LDAP:
------------------
用户名:MyUser
密码:敏感

绑定帐户:
------------------------
uid = MyUser,ou = Application,ou = Infrastructure,dc = MyDomain,dc = com

Below details (sample) given by customer. With the given details I would like to confirm that I could successfully connect with the LDAP with the given credentials. How to ensure that?

Please note that we are using C#.NET as development language. Thanks in advance.



DEV LDAP:
------------------
UserName: MyUser
Password: Sensitive

Bind Account:
------------------------
uid=MyUser,ou=Application,ou=Infrastructure,dc=MyDomain,dc=com

推荐答案

如果要创建LDAP连接,可以尝试与此类似的操作.这在我的应用程序中对我有用.
You can try similar to this if you want to create an LDAP connection. This worked for me in my app.
LdapConnection ldapConn = new LdapConnection(string.Format("{0}:{1}", "Your Server Name", "3268"));

ldapConn.SessionOptions.PingLimit = 500;

ldapConn.Credential = new NetworkCredential(username, password, domain);
ldapConn.AuthType = AuthType.Negotiate;
ldapConn.SessionOptions.Sealing = true;
ldapConn.SessionOptions.Signing = true;
ldapConn.Timeout = TimeSpan.FromHours(2);

try
{
  ldapConn.Bind();

}
catch (LdapException ldapEx)
{
   //exception handling
}



或者,如果您只想验证凭据,则可以尝试此



Or if you want to validate only the credentials you can try this

using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
   if (!context.ValidateCredentials(userName, password, ContextOptions.ServerBind))
   {
       // put your logic here.
   }
}



如果该解决方案适合您,请投票:)



If the solution worked for you, please vote :)


如果您可以访问该LDAP服务器,则可以使用现有工具(例如LdapAdmin [ ^ ].但是,如果您没有访问权限,则必须相信,或者不是您的关注,而是他们的关注,才能为您提供适当的凭据.
If you have access to that LDAP server, you can test it with an existing tool, like LdapAdmin[^]. But if you don''t have access, you have to believe, or it is not your concern, it is theirs, to give you proper credentials.


这篇关于如何确保我可以成功连接到LDAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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