Попробуйте использовать spring-data-ldap с ActiveDirectory.

Я пытаюсь использовать 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 или я где-то ошибся.


person BokC    schedule 06.09.2017    source источник


Ответы (1)


Перед отправкой запроса попробуйте добавить:

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 вы будете игнорировать исключение Patial Results.

person Andrew Nepogoda    schedule 06.09.2017
comment
Спасибо. Он удаляет исключение. Но результат был пустым, когда я попробовал userRepo.findAll() - person BokC; 06.09.2017
comment
@BokC, имя пользователя: CN=user,CN=Users,DC=groupefdi,DC=priv. Почему вы определили CN дважды? - person Andrew Nepogoda; 06.09.2017
comment
Первый - это логин - person BokC; 07.09.2017
comment
@BokC, пожалуйста, дважды проверьте DN пользователя. Возможно, вы пропустили роли пользователей или что-то еще. - person Andrew Nepogoda; 07.09.2017
comment
Я думаю, что userDn в порядке. Ма приложение устанавливает соединение с сервером Active Directory. Но я думаю, что запрос, сделанный Spring-data-ldap, не очень хорош. Возможно, мне нужно изменить вызываемый метод. - person BokC; 07.09.2017
comment
при использовании ldapRepository, как установить логическое значение выше. - person arvin_v_s; 18.09.2018