javax.naming.directory.DirContext#list ( )源码实例Demo

下面列出了javax.naming.directory.DirContext#list ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void testRunning() throws Exception {
   DirContext ctx = getContext();

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
 
@Test
public void testRunning() throws Exception {
   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
 
@Test
public void testRunning() throws Exception {
   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
 
源代码4 项目: activemq-artemis   文件: LDAPSecurityTest.java
@Test
public void testRunning() throws Exception {
   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));

   ctx.close();
}
 
@Test
public void testRunning() throws Exception {
   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));

   ctx.close();
}
 
@Test
public void testOpen() throws Exception {
   DirContext ctx = authMap.open();
   HashSet<String> set = new HashSet<>();
   NamingEnumeration<NameClassPair> list = ctx.list("ou=destinations,o=ActiveMQ,ou=system");
   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }
   assertTrue(set.contains("ou=topics"));
   assertTrue(set.contains("ou=queues"));
}
 
源代码7 项目: activemq-artemis   文件: LDAPLoginModuleTest.java
@Test
public void testRunning() throws Exception {

   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   assertTrue(set.contains("uid=admin"));
   assertTrue(set.contains("ou=users"));
   assertTrue(set.contains("ou=groups"));
   assertTrue(set.contains("ou=configuration"));
   assertTrue(set.contains("prefNodeName=sysPrefRoot"));

}
 
@Test
public void testRunning() throws Exception {

   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   assertTrue(set.contains("uid=admin"));
   assertTrue(set.contains("ou=users"));
   assertTrue(set.contains("ou=groups"));
   assertTrue(set.contains("ou=configuration"));
   assertTrue(set.contains("prefNodeName=sysPrefRoot"));

}
 
源代码9 项目: iaf   文件: LdapSender.java
/** 
 * Return a list of all of the subcontexts of the current context, which is relative to parentContext. 
 * @return an array of Strings containing a list of the subcontexts for a current context.
 */ 
public String[] getSubContextList (DirContext parentContext, String relativeContext, IPipeLineSession session) {
	String[] retValue = null;

	try {
		// Create a vector object and add the names of all of the subcontexts
		//  to it
		Vector n = new Vector();
		NamingEnumeration list = parentContext.list(relativeContext);
		if (log.isDebugEnabled()) log.debug("getSubCOntextList(context) : context = " + relativeContext);
		for (int x = 0; list.hasMore(); x++) {
			NameClassPair nc = (NameClassPair)list.next();
			n.addElement (nc);
		}

		// Create a string array of the same size as the vector object
		String contextList[] = new String[n.size()];
		for (int x = 0; x < n.size(); x++) {
			// Add each name to the array
			contextList[x] = ((NameClassPair)(n.elementAt(x))).getName();
		}
		retValue = contextList;

	} catch (NamingException e) {
		storeLdapException(e, session);
		log.error("Exception in operation [" + getOperation()+ "] ", e);
	}
	
	return retValue;
}
 
源代码10 项目: spring-ldap   文件: LdapTemplate.java
/**
    * {@inheritDoc}
    */
   @Override
public void list(final String base, NameClassPairCallbackHandler handler) {
	SearchExecutor searchExecutor = new SearchExecutor() {
		public NamingEnumeration executeSearch(DirContext ctx) throws javax.naming.NamingException {
			return ctx.list(base);
		}
	};

	search(searchExecutor, handler);
}
 
源代码11 项目: spring-ldap   文件: LdapTemplate.java
/**
    * {@inheritDoc}
    */
   @Override
public void list(final Name base, NameClassPairCallbackHandler handler) {
	SearchExecutor searchExecutor = new SearchExecutor() {
		public NamingEnumeration executeSearch(DirContext ctx) throws javax.naming.NamingException {
			return ctx.list(base);
		}
	};

	search(searchExecutor, handler);
}
 
源代码12 项目: spring-ldap   文件: SchemaViewer.java
private static void printSchema(String contextName, DirContext schemaContext) throws NameNotFoundException,
        NamingException {

    outstream.println();

    NamingEnumeration<NameClassPair> schemaList = schemaContext.list(contextName);

    while (schemaList.hasMore()) {
        NameClassPair ncp = schemaList.nextElement();

        printObject(contextName, ncp.getName(), schemaContext);
        outstream.println();
    }

    outstream.println();
}