[英]Spring LDAP, setting connection details in java
I want to set LDAP connection to list all users from AD. 我想设置LDAP连接以列出AD中的所有用户。 I successfully accomplished this with information stored in XML
我用存储在XML中的信息成功完成了此任务
<ldap:context-source
url="ldap://<url>"
base="dc=example,dc=local"
username="<user>@example.local"
password="<pass>" />
But how I can set this informations from Java, not in XML? 但是,如何从Java而不是XML设置此信息? Tried with:
尝试过:
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl("ldap://<url>");
ctxSrc.setBase("dc=example,dc=local");
ctxSrc.setUserDn("<user>@example.local");
ctxSrc.setPassword("<pass>");
LdapTemplate tmpl = new LdapTemplate(ctxSrc);
setLdapTemplate(tmpl);
But when runing 但是跑步时
List users = (List<User>) ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectCategory=person)(objectClass=user))", new UserAttributesMapper());
I get NullPointerExeption . 我得到NullPointerExeption 。 Runing that without setting up properties from java (ie reading from xml) everything works fine
运行该程序而无需从Java设置属性(即从xml读取),一切正常
please try this 请尝试这个
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl("ldap://<url>");
ctxSrc.setBase("dc=example,dc=local");
ctxSrc.setUserDn("<user>@example.local");
ctxSrc.setPassword("<pass>");
ctxSrc.afterPropertiesSet(); // this method should be called.
LdapTemplate tmpl = new LdapTemplate(ctxSrc);
setLdapTemplate(tmpl);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.