Frage

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.

War es hilfreich?

Lösung

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 .

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top