Question

I'm trying to authenticate using ADAM and LDAP. I really have no experience with this stuff, but I've been thrown in the deep end at work to figure it out.

Here's what I know. I'm using a program called JXplorer to look at the ADAM server, running on a VM on my computer. Here are the login details

This works perfectly. What I'm trying to do is replicate this process using VB.NET. I've tried a bunch of stuff and nothing seems to be working, I'm getting constant exceptions, ranging from bad password to unknown error. Here's the code I've started with -

Dim userName As String = "ADAM_TESTER"
Dim userPassword As String = "password"
Dim serverAddress As String = "LDAP://10.0.0.142:389"

Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Try
        Dim de As DirectoryEntry = New DirectoryEntry("LDAP://10.0.0.142:389/OU=Users,DC=TEST,DC=corp", userName, userPassword)
        Dim deSearch As DirectorySearcher = New DirectorySearcher()
        deSearch.SearchRoot = de
        deSearch.Filter = "(&(objectClass=user) (cn=" + userName + "))"
        Dim results As SearchResultCollection = deSearch.FindAll()
        If (results.Count > 0) Then
            Dim d As DirectoryEntry = New DirectoryEntry(results(0).Path, userName, userPassword)
            If (d.Guid.ToString IsNot Nothing) Then
                'The directory entry is valid
                'DoSomething()
            End If

        End If

I've also tried changing the userName above to the details in User DN in JXplorer. I'm really stuck here and have been looking for answers for hours.

Any help would be appreciated.

Was it helpful?

Solution 3

Thanks for the thoughts Geoff, I eventually figured it out. It turned out that I needed the connection string not including the OU=Users. The final string ended up being -

LDAP://10.0.0.142:389/DC=TEST,DC=corp

I've no idea why it didn't want the OU=Users. I spend about a day trying all the different combinations until finally this was accepted.

OTHER TIPS

FYI, Users is a container, not an OU. I believe you could have also used "LDAP://10.0.0.142:389/CN=Users,DC=TEST,DC=corp"

It is almost certainly a need for userName to be the full DN. ADAM needs a full DN for logins in most cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top