Reputation: 1775
i am new to the LDAP concept and i am able to connect to the LDAP server successfully. And also able to insert and delete records to/from LDAP database. Next thing i need to do is authenticate the user based on LDAP database records.. Help me out please. I will share the source code if needed. Thanks.
Upvotes: 0
Views: 986
Reputation: 11026
We have several samples which can help you if you need to use JNDI and LDAP.
We prefer to use a real LDAP SDK like the ones shown at https://www.ldap.com/developing-clients-apps (We use and reccomend UnboundID LDAP SDK for Java)
You should probably also consider using OpenID Connect as you can then abstract the Authentication to become agnostic to how authentication takes place.
Upvotes: 1
Reputation: 199
Try to create an Object of InitialDirContext with security_principal(user dn) and security_credentials(password) of the user you want to authenticate. If you are able to create the object the user is authenticated else catch the exception and throw it.
Upvotes: 0
Reputation: 8641
If you don't mind to use Spring Security, check out this article. It will ease the implementation and configuration. Here is and example of LDAP configuration:
auth.authenticationProvider(ldapAuthenticationProvider)
.ldapAuthentication()
.ldapAuthoritiesPopulator(ldapAuthoritiesPopulator)
.userSearchBase("ou=users")
.userSearchFilter("(uid={0})")
.groupSearchBase("ou=roles")
.groupSearchFilter("(member={0})")
.groupRoleAttribute("cn")
.contextSource(contextSource);
Upvotes: 0
Reputation: 1186
I also used LDAP for auth. I recommand the token based auth. If you can obtain the JWT
token by request. This repo java-jwt will be helpful.
Upvotes: 0