[英]Get list of users & persons by login with ldap java
I'm currently working on a app that contains official employees information even the login. 我目前正在使用一个包含正式员工信息甚至登录信息的应用程序。
I would like to do an LDAP search filter that retrieve for me all the information concerning specific users that corresspond to a list of logins I provide. 我想做一个LDAP搜索过滤器,为我检索有关与我提供的登录列表相对应的特定用户的所有信息。
A bit like a select statement in sql : select * from ldap where login in(my list of login)
有点像sql中的select语句:
select * from ldap where login in(my list of login)
I'm using the basic javax.naming.directory with all the blah blah comming with. 我正在使用基本的javax.naming.directory和所有类似的东西。
// set properties for our connection and provider
Properties properties = new Properties();
properties.put( Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory" );
properties.put( Context.PROVIDER_URL, "ldap://myserver.somewhere.com:389"; );
properties.put( Context.REFERRAL, "ignore" );
// set properties for authentication
properties.put( Context.SECURITY_PRINCIPAL, "User Name" );
properties.put( Context.SECURITY_CREDENTIALS, "password" );
InitialDirContext context = new InitialDirContext( properties );
The only thing I could do so far is lising all the object users if I could get directly those I'm looking for that could be very nice :) 到目前为止,我唯一能做的就是让所有对象用户都受益,如果我可以直接得到那些我正在寻找的对象,那可能会非常好:)
Thanks a lot for your help guys :) 非常感谢您的帮助:)
String searchFilter = "your_query";
String ldapSearchBase = "dc=ad,dc=my-domain,dc=com"
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> results = context.search(ldapSearchBase, searchFilter, searchControls);
an query might be like this: 查询可能是这样的:
(&(objectClass=user)(sAMAccountName=" + accountName + "))
complete example here: http://www.adamretter.org.uk/blog/entries/LDAPTest.java 此处的完整示例: http : //www.adamretter.org.uk/blog/entries/LDAPTest.java
So the final query in the search filter I had to put is : 因此,我必须在搜索过滤器中输入的最后一个查询是:
(&(objectCategory=person)
(|
(sAMAccountName=login1)
(sAMAccountName=login2)
(sAMAccountName=login3)
)
)
Thanks for you help :) 谢谢您的帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.