Java SpringLDAP不使用LDAP模板
我正在尝试使用spring连接到LDAP服务器Java SpringLDAP不使用LDAP模板,java,spring,ldap,Java,Spring,Ldap,我正在尝试使用spring连接到LDAP服务器 有关LDAP服务器的可用信息如下: 主机/ip 港口 域=>ou=x,dc=y,dc=z 我没有任何关于过滤方法的信息,例如与用户名匹配的uid={0}或cn={0} 这是我的密码 import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframe
有关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;
}
}
我有以下错误:
m、 m.a.ExceptionHandlerExceptionResolver:已解决
[org.springframework.ldap.UncategorizedLdapException:未分类
LDAP处理期间发生异常;嵌套异常为
javax.naming.NamingException:[LDAP:错误代码1-000004DC:LDAPPER:
DSID-0C090A7D,注释:要执行此操作,请
必须在连接上完成成功绑定。数据0,v3839
我的问题是这个错误的原因是什么,如果没有被称为uid={0}的模式或者它是标准的此外,我还尝试输入ContextSource初始化用户名和密码,尽管我认为它们不可用
contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z");
contextSource.setPassword("password");
这给了我以下错误:
[nio-8005-exec-5].m.a.ExceptionHandlerExceptionResolver:已解决
[org.springframework.ldap.AuthenticationException:[ldap:错误代码
49-80090308:LDAPPER:DSID-0C09053,注释:AcceptSecurityContext
错误,数据52e,v3839
在application.properties文件中,我将
spring.ldap.embedded.base-dn=dc=y,dc=z
spring.ldap.embedded.port=port
将userDn设置为username@domainname.com.
contextSource.setUserDn(“uid=username,ou=x,dc=y,dc=z”);
这里对我来说,ou=x,看起来是额外的,下面的语句应该可以让它工作。
contextSource.setUserDn(“uid=username,dc=y,dc=z”);
问候
Abhi非常感谢,但我的问题是,我没有在配置类中设置UserDn的初始用户名