Я пытаюсь аутентифицировать пользователя через Spring ldap. Ниже приведен код для инициализации шаблона ldap.
contextSource = new LdapContextSource();
contextSource.setUrl("ldaps://ldap.example.com");
contextSource.setBase("DC=example,DC=com");
contextSource.setUserDn("backend-app");
contextSource.setPassword("password");
contextSource.afterPropertiesSet();
PoolingContextSource pooledContextSource = new PoolingContextSource();
pooledContextSource.setDirContextValidator(new
DefaultDirContextValidator());
pooledContextSource.setContextSource(contextSource);
ldapTemplate = new LdapTemplate(pooledContextSource);
ldapTemplate.afterPropertiesSet();
Когда я пытаюсь использовать метод аутентификации ldapTemplate, он возвращает false.
// below line fails
ldapTemplate.authenticate("OU=Service Accounts,OU=Pseudo-Users", "frontend-web", "password");
Но когда я использую контекст каталога, он работает
DirContext ctx = null;
try {
ctx = contextSource.getContext("frontend-web", "password");
return true;
} catch (Exception e) {
logger.error("Login failed", e);
return false;
} finally {
LdapUtils.closeContext(ctx);
}
Вопрос 1: Есть ли способ заставить метод ldaptemplate authenticate работать?
Вопрос 2: Почему бы нам не предоставить baseDn, когда мы непосредственно используем DirectoryContext. Как ldap знает, где найти пользователя "frontend-web". Ищет ли он весь каталог для пользователя "frontend-web"
Может ли кто-нибудь помочь.