Я уже подключаюсь к AD с весенней загрузки для целей входа, но я не могу выполнять поиск. Моя конфигурацияВесенняя загрузка Active Directory/LDAP-соединение SOLVED
@Configuration
public class LdapTemplateConfig {
@Bean
public LdapTemplate ldapTemplate() {
LdapTemplate ldapTemplate = new LdapTemplate(ldapContextSource());
return ldapTemplate;
}
@Bean
public LdapContextSource ldapContextSource() {
String url = "ldap://127.0.0.1:389";
String base = "DC=demo1,DC=demo2,DC=demo3,DC=demo4";
LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(url);
ldapContextSource.setUserDn(
"CN=User Name,OU=Common Users OU,OU=RDP enabled Users OU,OU=Operator Users OU,OU=Admin Users OU,DC=demo1,DC=demo2,DC=demo3,DC=demo4");
ldapContextSource.setPassword("password");
// ldapContextSource.setReferral("follow");
ldapContextSource.afterPropertiesSet();
return ldapContextSource;
}
}
@Service
public class LDAPServiceImpl {
@Autowired
private LdapTemplate ldapTemplate;
public void getUserDetails(String userName) {
if (null != ldapTemplate) {
List<String> vals = ldapTemplate.search(query().where("objectclass").is("person"),
new AttributesMapper<String>() {
@Override
public String mapFromAttributes(Attributes attributes) throws NamingException {
return attributes.get("sAMAccountName").get().toString();
}
});
for (String s : vals) {
log.info("attr : " + s);
}
} else {
log.info("Templates is null");
}
}
}
Так что, когда я вызываю функцию getUserDetails() от контроллера возвращает «Шаблоны является нулевым» инъекция зависимостей
попробуйте добавить геттер и сеттер для ldapTemplate –
Вы установили 'component-scan' правильно? – Jens
Я пробовал геттер и сеттер, но он не работает. Я использую проект с https://jhipster.github.io/, а в Application.class есть аннотация @ComponentScan. –