java - Spring Boot 安全调用 LDAP

标签 java spring ldap

尝试实现 Spring 关于如何连接的官方教程 to Active directory

但是总是出现这种类型的错误

Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C09075A, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1]; remaining name 'uid=UserName,OU=users,DC=ad,DC=corpName,DC=com'

我的整个网络安全类(class)现在看起来像这样

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().fullyAuthenticated()
                .and()
                .formLogin();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
                .userDnPatterns("uid={0},OU=users,DC=ad,DC=corpName,DC=com")
//                .userSearchFilter("(sAMAccountName={0})")
//                .userSearchBase("DC=ad,DC=corpName,DC=com")
                .groupSearchBase("ou=users")
//                .groupSearchFilter("member={0}")
                .contextSource()
                    .url("ldap://ad.corpName.com")
                    .and()
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }


}

你能帮我理解我做错了什么吗?

最佳答案

LDAP 错误:DSID-0C09075A 表示您的 LDAP 服务器需要经过身份验证的用户(绑定(bind))才能执行搜索。要进行身份验证,您的 AuthenticationManagerBuilder 需要如下所示:

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
                .userDnPatterns("uid={0},OU=users,DC=ad,DC=corpName,DC=com")
                .managerDn(<bindDn>)
                .managerPassword(<bindPassword>
                .groupSearchBase("ou=users")
//                .groupSearchFilter("member={0}")
                .contextSource()
                    .url("ldap://ad.corpName.com")
                    .and()
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }

注意.managerDn().managerPassword()

关于java - Spring Boot 安全调用 LDAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57045842/

相关文章:

spring - Camel : Jetty response encoding

java - 内存中存储和处理大型数据列表 Spring Boot 2 java

linux - 是否可以从 linux 机器查询 windows ldap 服务器

python - 使用 Django Auth Ldap 将 LDAP 用户映射到 Django 用户

active-directory - sonarqube - 事件目录 ldap 错误代码 49

Java 小程序在 Mac 上闪烁

java - 带有可序列化列表的 SonarQube catch 22

java.lang.NoSuchMethodError : org. hibernate.ogm.cfg.OgmConfiguration.addAnnotatedClass

java - 如果我们更改字符串值,字符串池如何管理引用?

java - byte[] 到 bufferedImage 转换给出 null