You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Security LDAP报错49如何强制指定LDAP v3协议版本

Spring Security强制指定LDAP v3版本方案

配置方式

你可以根据自己项目的配置方式选择对应方案:

方案1:Spring Boot自动配置场景(推荐)

直接在项目配置文件中添加全局LDAP环境参数即可:

  • application.properties配置
    spring.ldap.base-environment.java.naming.ldap.version=3
    
  • application.yml配置
    spring:
      ldap:
        base-environment:
          java.naming.ldap.version: 3
    

方案2:手动定义LdapContextSource场景

如果你项目中手动注册了LdapContextSource Bean,直接在构造时添加版本参数:

@Bean
public LdapContextSource ldapContextSource() {
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl("ldap://你的LDAP服务地址");
    contextSource.setUserDn("绑定用户DN");
    contextSource.setPassword("绑定用户密码");
    
    // 强制指定使用LDAP v3版本
    Map<String, Object> envProps = new HashMap<>();
    envProps.put("java.naming.ldap.version", "3");
    contextSource.setBaseEnvironmentProperties(envProps);
    
    contextSource.afterPropertiesSet();
    return contextSource;
}

方案3:Spring Security LDAP认证单独配置

如果你需要仅在Spring Security的LDAP认证逻辑中指定版本,直接将配置好版本的LdapContextSource注入到认证配置即可:

@Configuration
public class LdapSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private LdapContextSource contextSource;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication()
                .userSearchFilter("(uid={0})")
                .userSearchBase("ou=用户根节点")
                .contextSource(contextSource);
    }
}

生效验证

配置完成后重启应用发起LDAP认证请求即可,该配置是LDAP客户端标准参数,会在所有和服务端的交互请求中强制携带v3版本标识,适配你排查到的其他语言客户端的统一配置逻辑。

内容的提问来源于stack exchange,提问作者skaz76

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 08:27:01