List of usage examples for javax.naming.ldap LdapContext list
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException;
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); Control[] connectCtls = new Control[] { null }; LdapContext ctx = new InitialLdapContext(env, null); Control[] ctxCtls = new Control[] { new SortControl(new String[] { "cn" }, Control.CRITICAL) }; ctx.setRequestControls(ctxCtls);/* w ww. ja va 2 s . c o m*/ NamingEnumeration answer = ctx.list(""); while (answer.hasMore()) { NameClassPair item = (NameClassPair) answer.next(); } }
From source file:edu.vt.middleware.ldap.AbstractLdap.java
/** * This will enumerate the names bounds to the specified context, along with * the class names of objects bound to them. The resulting <code> * Iterator</code> is a deep copy of the original search results. See {@link * javax.naming.Context#list(String)}.//from w ww . j a v a2s . com * * @param dn <code>String</code> LDAP context to list * * @return <code>Iterator</code> - LDAP search result * * @throws NamingException if the LDAP returns an error */ protected Iterator<NameClassPair> list(final String dn) throws NamingException { if (this.logger.isDebugEnabled()) { this.logger.debug("list with the following parameters:"); this.logger.debug(" dn = " + dn); if (this.logger.isTraceEnabled()) { this.logger.trace(" config = " + this.config.getEnvironment()); } } List<NameClassPair> results = null; LdapContext ctx = null; NamingEnumeration<NameClassPair> en = null; try { for (int i = 0; i <= this.config.getOperationRetry() || this.config.getOperationRetry() == -1; i++) { try { ctx = this.getContext(); en = ctx.list(dn); results = NCP_COPY_RESULT_HANDLER.process(null, en, this.config.getHandlerIgnoreExceptions()); break; } catch (NamingException e) { this.operationRetry(ctx, e, i); } } } finally { if (en != null) { en.close(); } if (ctx != null) { ctx.close(); } } return results.iterator(); }