【问题标题】:Setting spring ldap base dynamically for a new connection each usage为每次使用的新连接动态设置spring ldap base
【发布时间】:2017-10-30 00:55:51
【问题描述】:

这个问题是关于最佳实践的,如果可能的话。

我需要知道是否可以在代码中动态更改 ldap 上下文源的基础?

用我的 ldap bean 连接以下

<ldap:context-source
    url="ldap://<url>"
    base="dc=example,dc=local"
    username="<user>@example.local"
    password="<pass>"
/>

我可以在代码中根据给定的动态变化参数将上下文源更改为另一个基吗?

例如,如果我想将 base 更改为 dc=example2,dc=local 。

如果我以编程方式设置 LdapContextSource,这将没有问题。

【问题讨论】:

    标签: spring-ldap


    【解决方案1】:

    所以这比我想象的要简单和容易。

    我所要做的就是继续创作

    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);
    

    并将我的 LdapContextSource 值基于在我的情况下是动态源的属性。

    我在想还有什么比 Spring 更喜欢做的事情。

    【讨论】:

      猜你喜欢
      • 2022-10-21
      • 2016-07-18
      • 1970-01-01
      • 2013-01-05
      • 2016-08-29
      • 1970-01-01
      • 2016-04-13
      • 1970-01-01
      • 2011-03-30
      相关资源
      最近更新 更多