gpt4 book ai didi

java - 尝试在 Active Directory 中使用 spring-data-ldap

转载 作者:行者123 更新时间:2023-11-29 08:33:19 27 4
gpt4 key购买 nike

我尝试将 Spring-Data-Ldap 与 ActiveDirectory 一起使用。我想列出用户并查找特定用户。

我的主课:

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

application.yml的一部分

spring:
ldap:
urls: ldap://fr-dc1.groupefdi.priv:389
base: DC=groupefdi,DC=priv
username: CN=user,CN=Users,DC=groupefdi,DC=priv
password: ******

我得到错误:

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 上为 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 请求的部分结果异常。

关于java - 尝试在 Active Directory 中使用 spring-data-ldap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46076222/

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