这个问题是关于最佳实践以及如果可能的话。
我需要知道是否可以在代码中动态更改 ldap 上下文源的基础?
我的 ldap bean 连接了以下内容
<ldap:context-source
url="ldap://<url>"
base="dc=example,dc=local"
username="<user>@example.local"
password="<pass>"
/>
Run Code Online (Sandbox Code Playgroud)
我可以在代码中根据给定的动态变化参数将上下文源更改为另一个基础吗?
例如,如果我想将基数更改为 dc=example2,dc=local 。
如果我以编程方式设置 LdapContextSource 这将没有问题。
所以这比我想象的更简单、更容易。
我所要做的就是继续创造
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);
Run Code Online (Sandbox Code Playgroud)
并将我的 LdapContextSource 值基于在我的情况下是动态源的属性。
我在想Spring还有更多喜欢做的事情。
| 归档时间: |
|
| 查看次数: |
4972 次 |
| 最近记录: |