public Message list(String base) { // "ou=users,dc=dexels,dc=com" try { if (initialDir == null) { startup(); } DirContext dc = (DirContext) initialDir.lookup(base); NamingEnumeration e = dc.list(""); while (e.hasMore()) { NameClassPair o = (NameClassPair) e.next(); logger.info("NAME: " + o.getName()); logger.info("NAMESp: " + o.getNameInNamespace()); // o.getSchema(""); logger.info("o: " + o); } } catch (NamingException e) { e.printStackTrace(); } return null; }
public void testBasic() throws Exception { LdapFactoryHelper helper = (LdapFactoryHelper) lookup(LdapFactoryHelper.ROLE); PersonLdapFactory.setHelper(helper); InitialDirContext context = apacheDs.getAdminContext(); context.addToEnvironment(Context.OBJECT_FACTORIES, PersonLdapFactory.class.getName()); context.addToEnvironment(Context.STATE_FACTORIES, PersonLdapFactory.class.getName()); LdapName name = new LdapName("uid=trygvis,dc=test"); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- try { context.unbind(name); } catch (NamingException e) { // ignore } Person person = new Person(); person.setName("Trygve"); context.bind(name, person); Object o = context.lookup(name); assertEquals(Person.class, o.getClass()); person = (Person) o; assertEquals("Trygve", person.getName()); assertEquals(null, person.getDescription()); context.close(); }