Jump to content
Stew

Active Directory authentication

Recommended Posts

I have been tasked with updating login verification in a number of Delphi applications to use Active Directory rather than the existing method of reading from an internal db table.  I have never used AD in any application before, so I have been looking on  line for helpful files/components that will allow me to access basic user attributes in AD.  Everything I have come across so far is relatively old and frequently the links that are cited no longer work.  Does anybody know of helpful  AD access components, please?  I m using XE3.

Thanks for any pointers :classic_smile:

Share this post


Link to post
12 minutes ago, Stew said:

Does anybody know of helpful  AD access components, please?

You don't need any components. Just use the COM interface: https://docs.microsoft.com/windows/win32/adsi/active-directory-service-interfaces-adsi

I haven't worked with AD but my guess is that you just need to import the relevant type library and work from there (Component > Import Component...):

image.thumb.png.cf7c3977e2e0302e27f9b3af5a6a801d.png

 

but start by reading the documentation.

Share this post


Link to post

That or just find some information on how to access a LDAP server, AD is an extended LDAP server.
(if you search delphi ldap activedirectory, you will find examples)

 

Share this post


Link to post
6 hours ago, Stew said:

any pointers

Once you have the type library imported see: ADsOpenObject

Edited by FredS

Share this post


Link to post

Thank you all for the helpful advice.  I have had some trouble trying to import the Active DS Type Library (registry problem), but nothing that cannot be sorted out today.  In the meantime, following your general reading suggestions, I have been able to use ADO  to access LDAP through OpenQuery and now have a working two-stage authentication process, first to check that the username/password combination is valid, then to verify membership and permissions within an AD group.  Actually didn't take me nearly as long as I had feared it might, and although the current solution is probably not the best it will suffice until I can fix the other problems and familiarise myself further with the workings of AD.  Thanks again for your helpful replies.

Share this post


Link to post

 

Good morning. I'm having the same difficulty accessing my delphi application in Active Directory. Could you show me how you achieved this integration?

Share this post


Link to post
Var
  TokenHandle: THandle;
Begin
  If LogonUser(PChar(UserEdit.Text), PChar(DomainEdit.Text), PChar(PasswordEdit.Text), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, TokenHandle) Then
  Try
    // Credentials are valid...

    // In case needed:
    If ImpersonateLoggedOnUser(TokenHandle) Then
    Try
      // Do stuff in the context of user
    Finally
      RevertToSelf;
    End;
  Finally
    CloseHandle(TokenHandle);
  End;
End;

User must have network login right to the PC, though.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×