Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

LDAP & eDirectory

Posted on 2006-06-27
7
Medium Priority
?
1,107 Views
Last Modified: 2009-04-24
I need to authenticate users logging into our applications using their Novell user ID and password. There are some different teams where I work doing this but they are all Java teams and we are a VB team. I have be given the following information to use to connect to the test LDAP resource:

host is 10.99.88.33
port 389
base dn is o=abcauth
credentials cn=ldap_wed,ou=datacenter,o=abcauth
password is ldap9977

I was told I use this information to connect to the server. Then I query the system using the user’s name and password they supplied my application. I was told several of the Java teams here do it that way.

Can someone give me a simple version of how to do this using VB.net? Using the information above to connect to the LDAP server. Then verify the user name and password entered into textboxes txtUser and txtPassword are correct for the Novell account the user of my application has entered?

Thank you for your help.
0
Comment
Question by:TheRoyalFalcon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
bman9111 earned 1000 total points
ID: 16997752
0
 
LVL 8

Expert Comment

by:bman9111
ID: 16997754
0
 
LVL 1

Author Comment

by:TheRoyalFalcon
ID: 17001856
Thank you. I must confess I've read through both and I'm still unsure how to take the above and make it work. The Admin for our LDAP resource stated I must connect using the connection info above. Then find the user and verify their password. From both of these it would look like I would use the user name and password in the textboxes to connect?

I may just be reading all this wrong. I've barely slept. My son (less than 1), wife, and I are all stick. We were up all night and I am crawling (you know how it can be).

Could you help me a little further here (I'll even up the points). Could you, using the info from these links, show me how to plug in the information I listed above (the info our eDirectory-Novell LDAP resource gave me) if I wanted to verify a Novell userID="bobr" with a password="password" which were typed into the textboxes listed above?

I really need your help. THANK YOU!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Bill_PSC
ID: 17001909
Here is how I do it using Active Directory.  This function returns an email addy but it shows how to interface with ldap.

Public Property getEmail() As String
        Get
            getEmail = mEmail
        End Get
        Set(ByVal value As String)
            Dim input As String
            input = value
            Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://YourDirectory")
            Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
            mySearcher.Filter = ("(&(objectClass=user)(name=" & input & "))")
            Dim resEnt As SearchResult
            For Each resEnt In mySearcher.FindAll()
                mEmail = resEnt.Properties("mail")(0).ToString
            Next
        End Set
    End Property
0
 
LVL 8

Expert Comment

by:bman9111
ID: 17002086
not sure but try this....


Imports System
Imports System.Text
Imports System.Collections
Imports System.DirectoryServices
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(96, 144)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(120, 40)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = "TextBox1"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(120, 80)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.TabIndex = 2
        Me.TextBox2.Text = "TextBox2"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(0, 40)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "username"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(0, 80)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "password"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        IsAuthenticated("10.99.88.33", TextBox1.Text, TextBox2.Text)

    End Sub
    Public Function IsAuthenticated(ByVal domain As String, ByVal username As String, ByVal pwd As String) As Boolean
        Dim ldapinfo As String = "LDAP://" + "10.99.88.33"
        Dim domainAndUsername As String = domain & "\" & username
        Dim entry As DirectoryEntry = New DirectoryEntry(ldapinfo, domainAndUsername, pwd)

        Try
            'Bind to the native AdsObject to force authentication.
            Dim obj As Object = entry.NativeObject
            Dim search As DirectorySearcher = New DirectorySearcher(entry)
            search.Filter = "(SAMAccountName=" & username & ")"
            search.PropertiesToLoad.Add("cn")
            'if gets here then the user exists
            MessageBox.Show("User exists")

        Catch ex As Exception
            MessageBox.Show("Error authenticating user. " & ex.Message)
        End Try

        Return True
    End Function

End Class

u will need to reference directoryservices.
0
 
LVL 1

Author Comment

by:TheRoyalFalcon
ID: 17053736
Thank you both. These are very similar to different things I found when I went Googling at first. However none of them seemed to address how to tap into eDirectory just Active Directory. I did a bunch of reading on Java examples for eDirectory and then tried to modify what I had. It is basically the same code but what information is entered is different. Here is what I ended up doing.

<snip from above>
   host is 10.99.88.33
   port 389
   base dn is o=abcauth
   credentials cn=ldap_wed,ou=datacenter,o=abcauth
   password is ldap9977
<end snip>

'How to call the modified function
IsAuthenticated("389", "10.99.88.33", " cn=ldap_wed,ou=datacenter,o=abcauth", " ldap9977")

Public Function IsAuthenticated(ByVal strPort As String, ByVal strDomain As String, ByVal strUsername As String, ByVal strPwd As String) As Boolean

        Dim strName As String
        Dim entry As DirectoryEntry = New DirectoryEntry("LDAP://" & strDomain & ":" & strPort)
        entry.Username = strUsername
        entry.Password = strPwd
        entry.AuthenticationType = AuthenticationTypes.None

        strName = entry.Name
        MsgBox("Welcome to '" + strName + "'")

        Catch ex As Exception
            MessageBox.Show("Error authenticating user. " & ex.Message)
        End Try
        Return TRUE
End Funciton

This isn’t how I’m going to ultimately implement it but for anyone looking for a VB.net to eDirectory this is the basics. Like I mentioned it’s really the same code floating around on the web for Active Directory but it shows how to enter the connection information properly for eDirectory which is what I was looking for. Hopefully this will help someone down the line.

Thank you both for your assistance. I appreciate it. This is bascially a spen off on bman9111 referenced examples, one of which also touched on the port. That had to be passed for it to work at my employer, so I am passing the points to him. But agian I appreciate you both taking the time to respond. Thanks agian.

TheRoyalFalcon.
0
 
LVL 1

Author Comment

by:TheRoyalFalcon
ID: 17090563
BTW - For anyone looking for ieDirectory help here on this post there is one more thing I should have mentioned. On the user name parm "cn=" is the user Id. So say you need to auth user opRR123 it would read "cn=opRR123,ou=datacenter,o=abcauth". The rest of the information in the string is the pathing info where the accounts are located.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question