我正在尝试使用spring连接到LDAP服务器。
有关LDAP服务器的可用信息如下:
对于与用户名匹配的uid = {0}或cn = {0}等过滤方法,我没有任何信息。
这是我的密码
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
import org.springframework.ldap.core.support.LdapContextSource;
@Configuration
public class LdapConfiguration {
@Bean
public LdapContextSource contextSource() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://ip:port");
contextSource.setBase("dc=y,dc=z");
return contextSource;
}
@Bean
public LdapTemplate ldapTemplate() {
LdapTemplate template = new LdapTemplate(contextSource());
return template;
}
}然后在另一个类中,这里是身份验证方法。
@Service
public class LdapUserServiceImpl implements LdapUserService, BaseLdapNameAware {
@Autowired
protected LdapTemplate ldapTemplate;
@Autowired
protected ContextSource contextSource;
@Override
public Boolean authenticate(String userDn, String credentials) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("uid", userDn));
boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), credentials);
return authenticated;
}
}我有以下错误:
LDAP处理过程中发生的[org.springframework.ldap.UncategorizedLdapException:未分类异常;嵌套异常为javax.naming.NamingException:[LDAP:错误代码1- 000004DC: LdapErr: DSID-0C090A7D,注释:为了执行此操作,必须在连接.、数据0、v3839上完成成功的绑定“。
我的问题是,这个错误的原因是什么?如果没有一个模式被称为uid={0}或它是标准的,我还能做什么?
此外,我还试图输入ContextSource初始化用户名和密码,尽管我认为它们是不可用的。
contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z");
contextSource.setPassword("password");这给了我以下错误:
已解决的[org.springframework.ldap.AuthenticationException:[LDAP:错误代码49 - 80090308: LdapErr: DSID-0C090453,注释: AcceptSecurityContext错误,数据52e,v3839
在application.properties文件中,我将
spring.ldap.embedded.base-dn=dc=y,dc=z
spring.ldap.embedded.port=port发布于 2020-09-09 17:11:14
将userDn设置为username@domainname.com。在我看来,contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z");,ou=x,看起来是额外的,下面的语句应该能让它工作。contextSource.setUserDn("uid=username,dc=y,dc=z");
问候阿比
https://stackoverflow.com/questions/63707703
复制相似问题