尽管我对LDAP和AD几乎一无所知,除了它的基本功能(在本例中是Microsoft)之外,我还是被要求修改一个程序,以便它能够检索用户的电子邮件地址。可以将应用程序配置为使用LDAP。我不确定它是如何使用的--与同步应用程序的密码和用户的LDAP密码有关。应用程序有一个密码,它可能与用户的LDAP密码不一样。有一些机制来同步密码--但理论上这不应该让我担心--有人告诉我,它可以工作。
当然,我们这里没有LDAP服务器供我试用。
因此,我在PC上安装了Windows 2003服务器,并在其上启用了LDAP (我可以告诉您,这是一个巨大的学习曲线)。我增加了几个用户。甚至设法让他们中的一人成为域管理的成员。
在我正在开发的应用程序中,有一个设置工具来配置到LDAP的连接。这有一个有用的测试设置按钮。如果我输入服务器IP地址和端口号,然后按Test,它就会告诉我测试是成功的。嗯-那似乎不太可能。它还要求提供其他资料:
如果我保留这些空白,并保存设置,那么我现在可以启动应用程序,只将用户名与任何或没有密码-这是不对的,当然-它应该会阻止我启动我的应用程序。所以我只能假设我需要设置这三条信息。
我创建的LDAP服务器被称为,我相信,Aware.Server
因此,我已经将DC=AWare, DC=Server放入服务帐户DN (我只是在这里猜测,不太确定应该在其中包含什么),并将cn=Users, DC=AWare.Server放入用户帐户容器(同样,我也不知道它是什么,也不知道其中意味着什么)。
我不知道什么是服务帐户密码,所以我留下了空白。
当我按下测试设置时,它会问我用户名和密码。
如果我把这些空白处留下,它就会说测试是成功的。我开始担心了。
如果我输入了我输入到LDAP中的用户名,并带有密码,它就说明测试是成功的。
事实上,如果我把任何东西放进这些盒子里,它就说明它是成功的。
但是,如果我将某些内容放入服务帐户密码中,那么测试就不会成功--测试表明所提供的服务帐户具有无效的用户名或密码。
因此,目前的主要问题是--我如何知道服务帐户密码是什么?
我的行为是否是人们所期望的?谢谢史蒂夫
验证登录的代码包括:
Public Shared Function ValidateUser(ByVal server As String, ByVal port As Integer, ByVal userBase As String, ByVal userName As String, ByVal password As String, ByVal bindUser As String, ByVal bindPassword As String) As LdapValidatorResult
Dim retVal As New LdapValidatorResult
Dim conn As New Novell.Directory.Ldap.LdapConnection()
Try
'connect to the specificed server for user validation
conn.Connect(server, port)
retVal.Result = LdapValidatorResultType.Success
Try
'now authenticate to we can then go on to see if the username specificed exists
conn.Bind(bindUser, bindPassword)
'construct the distinguished name to uniquely id the specified user
Dim searchString As String = String.Format("CN={0},{1}", userName, userBase)
'look to see if the user attempting to login to a-ware exists
Dim sResults As LdapSearchResults = conn.Search(searchString, Novell.Directory.Ldap.LdapConnection.SCOPE_SUB, Nothing, Nothing, False) '"(&(!(objectClass=computer)))"
If sResults.hasMore Then
Try
'now validate the user with the password as the final check
Dim userDN As String = sResults.next.DN
conn.Bind(userDN, password)
retVal.Result = LdapValidatorResultType.Success
Catch ex As Novell.Directory.Ldap.LdapException
If ex.ResultCode = Novell.Directory.Ldap.LdapException.INVALID_CREDENTIALS Then
retVal.Result = LdapValidatorResultType.InvalidUserNameOrPassword
End If
retVal.ExceptInfo = ex
End Try
Else
retVal.Result = LdapValidatorResultType.NonExistentUser
End If
Catch ex As Novell.Directory.Ldap.LdapException
Select Case ex.ResultCode
Case Novell.Directory.Ldap.LdapException.INVALID_CREDENTIALS
retVal.Result = LdapValidatorResultType.InvalidBindUserNameOrPassword
Case Novell.Directory.Ldap.LdapException.CONNECT_ERROR
retVal.Result = LdapValidatorResultType.ServerDown
End Select
retVal.ExceptInfo = ex
End Try
Catch ex As Novell.Directory.Ldap.LdapException
Dim cause As System.Net.Sockets.SocketException = TryCast(ex.Cause, System.Net.Sockets.SocketException)
If cause IsNot Nothing Then
Select Case cause.ErrorCode
Case 1101
retVal.Result = LdapValidatorResultType.InvalidNameIp
Case 1106
retVal.Result = LdapValidatorResultType.RefusedConnectionOnPort
Case 10060
retVal.Result = LdapValidatorResultType.ServerDown
End Select
End If
retVal.ExceptInfo = ex
End Try
Return retVal
End Function发布于 2013-04-03 19:34:00
看起来它希望您在您的域中创建一个用户帐户,供应用程序使用。每个对象都有一个可分辨的名称(DN)。因此,它请求您创建的用户的DN及其密码,以及您在其中创建用户的容器的DN。我不知道你的域名域名是什么,但我猜它是AWare.Server。因此,如果您使用密码P@ssw0rd在默认用户容器中创建一个用户名appuser的用户,那么您将提供以下内容:
服务帐户DN: CN=appuser、CN=Users、DC=AWare、DC=Server服务帐户密码: P@ssw0rd用户帐户容器: CN=Users、DC=AWare、DC=Server
https://stackoverflow.com/questions/15782587
复制相似问题