简体   繁体   English

如何使用Java获取所有LDAP目录用户并将其存储到文件中

[英]how to get all LDAP directory user and store it to a file using Java

I want to retrieve all users from LDAP AD directory and store it in a file for some processing. 我想从LDAP AD目录中检索所有用户,并将其存储在文件中以进行某些处理。 I am using below code to fetch all AD users but it's returning No Attributes. 我正在使用下面的代码来获取所有AD用户,但是它返回No Attributes。

try {
  DirContext ctx = new InitialDirContext(env);
  connected = "true";

  SearchControls constraints = new SearchControls();
  constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
  String[] attrIDs = { "(&(objectClass=*)(objectCategory=*))"};
  constraints.setReturningAttributes(attrIDs);
  NamingEnumeration<SearchResult> answer = ctx.search(ldapDCinfo, "(&(objectClass=*)(objectCategory=*))", constraints);
  while (answer.hasMore()) {
    Attributes attrs = ((SearchResult) answer.next()).getAttributes();
    sendAry[0]= connected;
    System.out.println(attrs.toString());
  }
String[] attrIDs = { "(&(objectClass=*)(objectCategory=*))"};
constraints.setReturningAttributes(attrIDs);

This is nonsense. 这是无稽之谈。 That's not an array of attribute IDs, it is an array containing one filter string, and the filter string is already specified elsewhere. 那不是属性ID的数组,而是一个包含一个过滤字符串的数组,并且该过滤字符串已在其他位置指定。

If for example you want to return surname, givenName, mail , you would write: 例如,如果要返回surname, givenName, mail ,则应输入:

String[] attrIDs = { "surname", "givenName", "mail"};

If you want all the normal attributes, use "*" . 如果需要所有常规属性,请使用"*" If you want the operational attributes as well, use: 如果还需要操作属性,请使用:

String[] attrIDs = { "*", "+"};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM