Java 尝试将spring数据ldap与ActiveDirectory一起使用
我尝试将SpringDataLDAP与ActiveDirectory一起使用。 我想列出用户并查找特定用户 我的主要班级:Java 尝试将spring数据ldap与ActiveDirectory一起使用,java,active-directory,ldap,spring-data,spring-ldap,Java,Active Directory,Ldap,Spring Data,Spring Ldap,我尝试将SpringDataLDAP与ActiveDirectory一起使用。 我想列出用户并查找特定用户 我的主要班级: @SpringBootApplication @EnableDiscoveryClient @EnableLdapRepositories public class Application { public static void main(String[] args) { SpringApplication.run(Application.cla
@SpringBootApplication
@EnableDiscoveryClient
@EnableLdapRepositories
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
用户报告:
public interface UserRepo extends LdapRepository<User> {
List<User> findByFullNameContains(String name);
}
我得到一个错误:
2017-09-06 14:42:34,551 [ERROR] --- [http-nio-6546-exec-6] o.a.c.c.C.[.[.[.[dispatcherServlet]:181 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.ldap.PartialResultException: Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name '/'] with root cause
javax.naming.PartialResultException: Unprocessed Continuation Reference(s)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2914) ~[na:1.8.0_65]
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2888) ~[na:1.8.0_65]
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1846) ~[na:1.8.0_65]
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769) ~[na:1.8.0_65]
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392) ~[na:1.8.0_65]
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:358) ~[na:1.8.0_65]
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:276) ~[na:1.8.0_65]
at org.springframework.ldap.core.LdapTemplate$3.executeSearch(LdapTemplate.java:303) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:642) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:578) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.find(LdapTemplate.java:1840) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.findAll(LdapTemplate.java:1806) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.findAll(LdapTemplate.java:1814) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.data.ldap.repository.support.SimpleLdapRepository.findAll(SimpleLdapRepository.java:190) ~[spring-data-ldap-1.0.6.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:504) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
.....
我不知道是否必须在application.yml for Active Directory上添加一些特殊内容,或者是否在某些地方出错。发送请求之前,请尝试添加:
ldapTemplate.setIgnorePartialResultException(true)代码>
更新:
如果使用ldap存储库,则可以在配置期间设置此标志:
@Configuration
@EnableLdapRepositories
class ApplicationConfig {
@Bean
ContextSource contextSource() {
LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl("ldap://127.0.0.1:389");
return ldapContextSource;
}
@Bean
LdapTemplate ldapTemplate(ContextSource contextSource) {
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
ldapTemplate.setIgnorePartialResultException(true);
return ldapTemplate;
}
}
在这种情况下,您将忽略每个ldap请求的特定结果异常。在发送请求之前,请尝试添加:
ldapTemplate.setIgnorePartialResultException(true)代码>
更新:
如果使用ldap存储库,则可以在配置期间设置此标志:
@Configuration
@EnableLdapRepositories
class ApplicationConfig {
@Bean
ContextSource contextSource() {
LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl("ldap://127.0.0.1:389");
return ldapContextSource;
}
@Bean
LdapTemplate ldapTemplate(ContextSource contextSource) {
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
ldapTemplate.setIgnorePartialResultException(true);
return ldapTemplate;
}
}
在这种情况下,您将忽略每个ldap请求的特定结果异常。谢谢。它将删除该异常。但是当我尝试userRepo.findAll()@BokC时,结果是空的,用户名:CN=user,CN=Users,DC=groupefdi,DC=priv。为什么要定义CN两次?第一次是login@BokC,请重新检查用户DN。可能是您错过了用户角色或其他什么。我认为userDn还可以。Ma应用程序与Active Directory服务器建立连接。但是我认为SpringDataLDAP所做的查询并不好。也许我必须改变这个方法。谢谢。它将删除该异常。但是当我尝试userRepo.findAll()@BokC时,结果是空的,用户名:CN=user,CN=Users,DC=groupefdi,DC=priv。为什么要定义CN两次?第一次是login@BokC,请重新检查用户DN。可能是您错过了用户角色或其他什么。我认为userDn还可以。Ma应用程序与Active Directory服务器建立连接。但是我认为SpringDataLDAP所做的查询并不好。也许我必须更改调用的方法。