Note that there are some explanatory texts on larger screens.

plurals
  1. POLDAP JNDI subtree searching
    primarykey
    data
    text
    <p>I have a problem of searching LDAP. If I use the following code, I can get level 2 using the following code. But I want to get Level 4 object. Thanks for any kind help.</p> <p>The current search base: <code>ou=HQ2-BR</code>, filter: <code>"(ou=*)";</code></p> <p>Regards, Man Pak Hong, Dave manpakhong@hotmail.com manpakhong@gmail.com</p> <p>LDAP structure</p> <ul> <li>o=com,dc=rabbitforever #(level 0) <ul> <li>ou=HQ2-BR // referal to other ad #(level 1) <ul> <li>ou=TSB // #(level 2)</li> <li>ou=BM1 // #(level 2)</li> <li>ou=IIC // #(level 2) <ul> <li>ou=People // #(level 3) <ul> <li>uid=IICCIO // #(level 4)</li> <li>uid=IICSIO1 // #(level 4)</li> </ul></li> </ul></li> </ul></li> </ul></li> </ul> <p>The code:</p> <pre><code>public void loopLDAP() { String adminName = "uid=writer,ou=People,o=com,dc=rabbitforever"; String adminPassword = "password"; Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //env.put(Context.PROVIDER_URL, // "ldap://192.168.1.127:389/dc=rabbitforever,dc=com"); env.put(Context.PROVIDER_URL, "ldap://10.10.176.156:389/o=com,dc=rabbitforever"); //env.put(Context.SECURITY_AUTHENTICATION, "none"); env.put(Context.SECURITY_PRINCIPAL, adminName); env.put(Context.SECURITY_CREDENTIALS, adminPassword); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.REFERRAL, "follow"); try { LdapContext ctx = new InitialLdapContext(env, null); ctx.setRequestControls(null); String filter = "(ou=*)"; NamingEnumeration&lt;?&gt; namingEnum = ctx.search("ou=HQ2-BR", filter, getSimpleSearchControls()); while (namingEnum.hasMore()) { SearchResult result = (SearchResult) namingEnum.next(); Attributes attrs = result.getAttributes(); String cn = ""; String sn = ""; String description = ""; String uid = ""; if (null != attrs.get(cn)) { cn = attrs.get("cn").toString(); } if (null != attrs.get("sn")) { sn = attrs.get("sn").toString(); } if (null != attrs.get("description")) { description = attrs.get("description").toString(); } if (null != attrs.get("uid")) { uid = attrs.get("uid").toString(); } System.out.println(cn + " | " + sn + " | " + description + " | " + uid); } } catch (Exception ex) { ex.printStackTrace(); } } // end loopLDAP() </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.
 

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