12

I want to connect (and get user's group) to a Sun LDAP server with a Delphi program. I think ADSI works only with Microsoft LDAP. I try it with ADO, but I can't connect.

Can someone show some code how I would do this?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Partizan22
  • 129
  • 3
  • ADSI works with third-party LDAP providers - just not quite as good as with AD... (but probably still easier than using ADO) I have a few [Delphi ADSI helpers](http://adsi.mvps.org/adsi/Delphi/index.html) for download - feel free to go grab those and use them! – marc_s May 11 '11 at 15:16
  • Yes I have found previously your site, but your code unfortunately doesn't work because I have a user name and password witch may I should connect. I can't find the way for this in your code... – Partizan22 May 12 '11 at 06:17
  • possible duplicate of [LDAP server access via VBscript/ADO](http://stackoverflow.com/questions/972847/ldap-server-access-via-vbscript-ado) – Chris J Jun 14 '11 at 19:57

1 Answers1

0

I think this code will fit the bill.

There is more to ADSI than just LDAP, and from my experience it is easier to use LDAP client to connect to ActiveDirectory than the other way around - which is what you are trying to do, unfortunatly.

To get you started, here is a fail safe way to authenticate a user.

  1. Establish a connection with your LDAP server with your service account. If possible, use the LDAP protocol over SSL, LDAPS
  2. Search for the username (wich is the CN=jdoe part) to get the full DN (distinguished name)
  3. If you have duplicate result, stop here with an error
  4. Bind to the LDAP with the DN and password you are trying to validate. Make shure you are using the same validation method on both side.
  5. If it binds, the password is valid.
  6. Close the connection you just established
  7. Depending on your needs, either hold on to the connection you made a step 1 or tear it down, too.
ixe013
  • 9,559
  • 3
  • 46
  • 77