gpt4 book ai didi

java - Spring Boot 安全调用 LDAP

转载 作者:行者123 更新时间:2023-12-02 09:41:20 24 4
gpt4 key购买 nike

尝试实现 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com