Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please referred the following code.</p> <pre><code>package active.security.util.ldap; import java.util.Date; import java.util.Hashtable; import javax.naming.*; import javax.naming.directory.*; //import javax.naming.ldap.PagedResultsControl; import active.security.util.DateTool; public class JNDISearch { public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory"; // driver public static String MY_HOST = "ldap://dcserver:389"; // server and port public static String MY_SEARCHBASE = "DC=active,DC=local"; // base DC public static String MY_FILTER = "(&amp;(objectclass=User)(!(objectclass=computer)))"; // filter public static String MGR_DN = "domain\\username"; // username public static String MGR_PW = "password"; // password public static String MY_ATTRS[] = {/* "cn","userpassword","mail", */"cn" }; public static String temp = new String(); public static void main(String[] ags) throws Exception{ new JNDISearch().search(); } @SuppressWarnings({ "rawtypes", "unchecked" }) public String search() throws Exception { int userCount = 0; Date begin = new Date(); try { Hashtable env = new Hashtable(); //PagedResultsControl control = new PagedResultsControl(5000, true); env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX); env.put(Context.PROVIDER_URL, MY_HOST); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, MGR_DN); env.put(Context.SECURITY_CREDENTIALS, MGR_PW); DirContext ctx = new InitialDirContext(env); SearchControls constraints = new SearchControls(); constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_FILTER,constraints); while (results != null &amp;&amp; results.hasMore()) { SearchResult sr = (SearchResult) results.next(); // String dn = sr.getName(); String dn = sr.getName() + "," + MY_SEARCHBASE; Attributes ar = ctx.getAttributes(dn, MY_ATTRS); if (ar == null) { System.out.println("Entry " + dn + " has none of the specified attributes\n"); } else { Attribute attr = ar.get("cn"); String cn = (String)attr.get(0); System.out.println(cn); } userCount++; } } catch (Exception e) { e.printStackTrace(); } finally{ Date end = new Date(); long seconds = DateTool.getSenconds(begin, end); System.out.println("total user: "+userCount); System.out.println("time cost: "+seconds+" seconds"); } return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload