Reputation: 805
This question is on best practice and if possible.
I need to know if I can dynamically change the base of ldap context source within code?
With my ldap bean wired with the following
<ldap:context-source
url="ldap://<url>"
base="dc=example,dc=local"
username="<user>@example.local"
password="<pass>"
/>
can I in code change the context source to another base depending on a given dynamically changing parameter?
For instance if i want to change base to dc=example2,dc=local .
If I was programmatically setting up LdapContextSource this would be no problem.
Upvotes: 4
Views: 5200
Reputation: 805
So this was simpler and easier than I thought.
All i had to do was go ahead and create
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl("ldap://<url>");
ctxSrc.setBase("dc=example,dc=local");
ctxSrc.setUserDn("<user>@example.local");
ctxSrc.setPassword("<pass>");
ctxSrc.afterPropertiesSet(); // this method should be called.
LdapTemplate tmpl = new LdapTemplate(ctxSrc);
setLdapTemplate(tmpl);
and base my LdapContextSource values on the properties that in my case is a dynamic source.
I was thinking that there was something more Spring like to do .
Upvotes: 6