【问题标题】:How to specify connection to data source for LDAPs context source?如何为 LDAP 上下文源指定与数据源的连接?
【发布时间】:2015-02-12 14:06:06
【问题描述】:

我正在使用 Spring mvc 和针对活动目录的 LDAP 身份验证。我现在拥有的东西可以工作,但我的 contextSource 属性:url、managerDN 和 managerPassword 是硬编码的。我想将这些属性作为资源移动到我的 server.xml 中,并使用数据源来指定这些连接设置。我的想法是 managerDN 可以像用户名一样使用,然后剩下的就可以了。唯一的问题是 contextSource 没有任何方法。 contextSource 是从 contextSourceBuilder 创建的对象。有人对如何做到这一点有任何想法吗?

@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userSearchFilter("sAMAccountName={0}")
                .userSearchBase("OU=Accounts")
                .groupSearchFilter("member={0}")
                .groupSearchBase("OU=Groups")
                .contextSource()
                    .url("ldap://myurl:portNum")
                    .managerDn("stuff")
                    .managerPassword("things");
    }
}

【问题讨论】:

    标签: java spring ldap datasource


    【解决方案1】:

    只需在 *.properties 文件中设置,让 Spring 加载它然后使用:

    @Value(${ldap.manager})
    String managerDn;
    @Value(${ldap.manager.password})
    String managerPassword;
    [...]
    .managerDn(managerDn)
         .managerPassword(managerPassword);
    

    或者: 使用 org.springframework.security.ldap.DefaultSpringSecurityContextSource 在设置器中设置用户/密码并将其设置在

    .contextSource(youFancySpringContext);
    

    【讨论】:

      猜你喜欢
      • 2011-12-25
      • 2011-03-28
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多