【问题标题】:Spring Boot Security call to LDAPSpring Boot 对 LDAP 的安全调用
【发布时间】:2019-11-24 12:23:22
【问题描述】:

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

但总是遇到这种类型的错误

LDAP 处理期间发生未分类的异常;嵌套的 异常是 javax.naming.NamingException: [LDAP: error code 1 - 000004DC:LdapErr:DSID-0C09075A,注释:为了执行这个 操作一个成功的绑定必须在连接上完成。,数据 0,v1db1];剩余名称 'uid=UserName,OU=users,DC=ad,DC=corpName,DC=com'

我的整个网络安全课现在看起来像这样

@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");
    }


}

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

【问题讨论】:

    标签: java spring ldap


    【解决方案1】:

    LDAP 错误:DSID-0C09075A 表示您的 LDAP 服务器需要经过身份验证的用户(绑定)才能执行搜索。要进行身份验证,您的 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()

    【讨论】:

    • 这些 .managerDn() 和 .managerPassword() 是某种可以查询 AD 的系统 ID,对吧?
    • @Sithole 似乎对我来说还有其他问题;它返回错误代码 52e;这个基于错误代码列表的应该是 - “密码错误”,但即使我输入随机测试作为登录名和密码,它也会返回相同的错误;
    猜你喜欢
    • 2017-07-02
    • 2016-09-18
    • 1970-01-01
    • 2018-10-15
    • 2014-02-15
    • 2016-01-06
    • 2021-03-25
    • 2011-09-22
    • 2020-04-14
    相关资源
    最近更新 更多