【发布时间】:2018-03-16 06:24:54
【问题描述】:
我正在尝试使用 .NET 3.5 System.DirectoryServices.AccountManagement 命名空间通过我们的 Active Directory LDAP 服务器验证用户凭据通过 SSL 加密的 LDAP 连接。这是示例代码:
using (var pc = new PrincipalContext(ContextType.Domain, "sd.example.com:389", "DC=sd,DC=example,DC=com", ContextOptions.Negotiate))
{
return pc.ValidateCredentials(_username, _password);
}
此代码在不安全的 LDAP(端口 389)上运行良好,但我不希望以明文形式传输用户/密码组合。但是当我更改为 LDAP + SSL(端口 636)时,出现以下异常:
System.DirectoryServices.Protocols.DirectoryOperationException: The server cannot handle directory requests.
at System.DirectoryServices.Protocols.ErrorChecking.CheckAndSetLdapError(Int32 error)
at System.DirectoryServices.Protocols.LdapSessionOptions.FastConcurrentBind()
at System.DirectoryServices.AccountManagement.CredentialValidator.BindLdap(NetworkCredential creds, ContextOptions contextOptions)
at System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password)
at (my code)
端口 636 用于其他活动,例如查找该 LDAP/AD 条目的非密码信息...
UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, _username)
...所以我知道这不是我的 LDAP 服务器的 SSL 设置,因为它可以通过 SSL 进行其他查找。
有没有人接到ValidateCredentials(...) 的电话以通过 SSL 工作?你能解释一下怎么做吗?还是有另一种/更好的方法来安全地验证 AD/LDAP 凭据?
【问题讨论】:
-
这是一篇 MSDN 文章,用于对基于 SSL 的 LDAP 进行故障排除:support.microsoft.com/kb/938703
-
感谢您的链接。但是对于我执行的所有其他 LDAP 查询,我可以再次通过 LDAPS(端口 636)进行通信。
ValidateCredentials()似乎有些不寻常。不过,我会更详细地阅读这篇文章。 -
密码应该以明文传输 - 不是散列 - 通过安全连接到支持密码质量检查和密码历史强制执行的服务器,除非 LDAP 客户端提供密码质量和历史检查,否则服务器将无法强制执行质量和历史记录。
标签: c# .net active-directory ldap directoryservices