【问题标题】:Spring LDAP Spring Ldap Embedded doesn't set ldaptemplate baseSpring LDAP Spring Ldap Embedded 没有设置 ldaptemplate base
【发布时间】:2022-10-21 02:45:49
【问题描述】:

测试 ma LDAP 服务。我像这样设置嵌入式 LDAP 配置:

spring:
  ldap:
    base: OU=Internals,DC=int,DC=springboot,DC=dev
    username: uid=admin
    password: secret
    urls: ldap://localhost:8389/
    embedded:
      base-dn: DC=springboot,DC=dev
      credential:
        username: uid=admin
        password: secret
      ldif: classpath:export2-ldap.ldif
      port: 8389
      validation:
        enabled: false

我注意到 ldaptemplate 基础设置不正确:

我研究了EmbeddedLdapAutoConfigurationLdapAutoConfiguration 代码,我注意到EmbeddedLdapAutoConfiguration 在LdapAutoConfiguration 类之前创建了一个没有基础的bean LdapContextSource

@Configuration(proxyBeanMethods = false)
    @ConditionalOnClass(ContextSource.class)
    static class EmbeddedLdapContextConfiguration {

        @Bean
        @DependsOn("directoryServer")
        @ConditionalOnMissingBean
        LdapContextSource ldapContextSource(Environment environment, LdapProperties properties,
                EmbeddedLdapProperties embeddedProperties) {
            LdapContextSource source = new LdapContextSource();
            if (embeddedProperties.getCredential().isAvailable()) {
                source.setUserDn(embeddedProperties.getCredential().getUsername());
                source.setPassword(embeddedProperties.getCredential().getPassword());
            }
            source.setUrls(properties.determineUrls(environment));
            return source;
        }

    }

是否正常,不能同时使用 spring.ldap.base 和 spring.ldap.embedded.* ?或者我的项目中可能没有正确设置某些东西。

【问题讨论】:

    标签: java spring spring-boot ldap spring-ldap


    【解决方案1】:

    我通过以下方法解决了这个问题:

    @Bean
    public LdapContextSource createLdapConfig(LdapProperties properties, Environment environment,
            ObjectProvider<DirContextAuthenticationStrategy> dirContextAuthenticationStrategy) {
        LdapAutoConfiguration config = new LdapAutoConfiguration();
        return config.ldapContextSource(properties, environment, dirContextAuthenticationStrategy);
    }
    

    正如@Saikat 所指出的,它似乎是spring 和unboundid 嵌入式LDAP 服务器都配置为创建一个LdapContextSource 如果它尚不存在......听起来嵌入式LDAP 服务器正在赢得比赛,并且搞砸了其他所有人。

    上面的代码通过强制创建/配置LdapContextSource 解决了这个问题,因此不让Spring 和嵌入式ldap 服务器尝试创建LdapContextSource

    【讨论】:

      猜你喜欢
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      相关资源
      最近更新 更多