I have a catch 22.
I am implementing a service client whose responsibility is to authenticate a user at an LDAP server. The client accepts a userid and password, determines the userDn, and invoke a request to the LDAP server.
My problem is the way spring ldap template is setup at the moment. The LdapTemplate
requires a ContextSource
at bean creationtime. The ContextSource
is configured at creation time to some value (ldapurl, userdn, password). But I realized that my ContextSource
will change with each user. Each user opens a connection based on the user's DN. So, my contextsource is different per user and therefor creating a ContextSource
at beancreation time(container startup) is not the right place. And, there is no way of overriding the ContextSource
(with the userid/password) through the LdapTemplate
AFAIK.
So, is it a good idea to create an Ldap ContextSource
object explicitly in my code by initializing it explicitly with the actual userid and password (and the url of which is a constant over all users) and update my LdapTemplate
bean by using the setter method of LdapTemplate
? After my client call I will dispose the ContextSource
by setting it to null
(the template outlives the operation because it is a bean living in the spring container. So it could be reused and therefor the previous information on the context must not be available.)
Question: Is there another solution to this problem as described above?