0

尽管除了 LDAP 和 AD 的基本功能(在本例中为 Microsoft)之外,我对 LDAP 和 AD 几乎一无所知,但我被要求修改一个程序,以便它可以检索用户的电子邮件地址。该应用程序可以配置为使用 LDAP。我不确定它是如何使用它的——这与将应用程序的密码与用户的 LDAP 密码同步有关。应用程序有一个密码,它可能与用户的 LDAP 密码不同。有一些机制可以同步密码 - 但理论上我不应该担心 - 我被告知它有效。

当然,我们这里没有 LDAP 服务器供我尝试。

所以我在 PC 上安装了 Windows 2003 服务器,并在其上启用了 LDAP(我可以告诉你,这是一个巨大的学习曲线)。我添加了几个用户。甚至设法让其中一个成为域管理员的成员。

在我正在处理的应用程序中,有一个设置工具来配置与 LDAP 的连接。这有一个有用的测试设置按钮。如果我输入服务器 IP 地址和端口号,然后按测试设置,它会告诉我测试成功。嗯——这似乎不太可能。它还要求提供其他信息:

  • 服务帐户 DN
  • 服务帐号密码
  • 用户帐户容器。

如果我将这些留空并保存设置,那么我现在可以启动应用程序,并且只输入用户名并输入任何密码或不输入密码 - 这当然是不正确的 - 它应该会阻止我启动我的应用程序。所以我只能假设我需要设置这三个信息。

我创建的 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
4

1 回答 1

0

看起来它希望您在您的域中创建一个用户帐户以供该应用使用。每个对象都有一个专有名称 (DN)。所以它询问您创建的用户的 DN 及其密码,以及您在其中创建用户的容器的 DN。我不知道您的域名 DNS 名称是什么,但我猜它是 AWare。服务器。因此,如果您使用密码 P@ssw0rd 在默认用户容器中创建用户名为 appuser 的用户,那么您将提供以下内容:

服务帐户 DN:CN=appuser,CN=Users,DC=AWare,DC=Server 服务帐户密码:P@ssw0rd 用户帐户容器:CN=Users,DC=AWare,DC=Server

于 2013-04-03T19:34:00.037 回答