使用SSL联系Active Directory
我有一个方法来validation针对Active Directory的用户凭据。 我想在SSL中使用这种方法,但我无法使用它。
主要问题是我有一个服务器在我们的网络之外(它叫做DMZ?)。 从那里我想联系我的活动目录,这就是我想使用SSL的原因。
在我的本地计算机(而不是DMZ)上使用它时,我收到此错误:
System.DirectoryServices.AccountManagement.PrincipalServerDownException:无法联系服务器。 —> System.DirectoryServices.Protocols.LdapException:LDAP服务器不可用。
在System.DirectoryServices.Protocols.LdapConnection.Connect()
在System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest请求,Int32和messageID)
在System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest请求,TimeSpan requestTimeout)
在System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest请求)
在System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName,ServerProperties&properties)—内部exception堆栈跟踪结束—
在System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName,ServerProperties&properties)
在System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType,String name,String container,ContextOptions options,String userName,String password)
在System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType,String name,String container,ContextOptions options)
at Authorization.AuthorizeAD.ValidateCredentials(String username,String password)
我认为在我从服务器上尝试之前,让它从本地使用SSL会很好。
我的方法:
public bool ValidateCredentials(string username, string password) { using ( var context = new PrincipalContext(ContextType.Domain, ContextName, ContextContainer, ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing | ContextOptions.SecureSocketLayer)) { return context.ValidateCredentials(username, password); } }
如前所述,没有ContextOptions.SecureSocketLayer
它工作正常(如果参数为null,其他三个默认情况下)
有谁知道我应该如何使用SSL正确使用PrincipalContext
?
您确定它支持SSL并且防火墙是否已打开以允许该连接?
LDAP使用端口389.LDAPS使用端口636。
如果安装了telnet客户端,则可以使用它来检查连接:
telnet yourdomain.com 636
如果你得到一个空白的屏幕,它的工作原理。 如果它无法连接,它会告诉你。
如果它已打开但仍然无效,则可能是使用自签名SSL证书。 检查Windows事件日志中是否存在与证书相关的错误。
我还使用Chrome来检查证书。 你必须像这样运行chrome:
chrome.exe --explicitly-allowed-ports=636
然后浏览到https://yourdomain.com:636
并查看它是否为您提供任何证书错误。 然后你就可以看到证书了。 如果这是问题所在,您可以导入证书并明确信任它。
- 如何在Powershell中模拟Active Directory用户?
- System.DirectoryServices很慢?
- 遍历属性时,ActiveDirectory错误0x8000500c
- 如何将AcquireTokenAsync中收到的令牌与Active Directory一起存储
- PrincipalSearcher和DirectorySearcher之间的区别
- UserPrincipals.GetAuthorizationGroups枚举组时发生错误(1301)。 升级到Server 2012域控制器后
- ASP.NET / Active Directory – 支持域用户的自动登录
- 从Active Directory PrincipalContext获取所有用户
- C# – 查找Active Directory用户的所有电子邮件地址