javax.naming.directory.SearchResult result = answers.nextElement(); String user = result.getNameInNamespace();
public static void delete(DirContext ctx, String dn) throws NamingException { Stack<String> toDelete = new Stack<String>(); toDelete.push(dn); while (!toDelete.empty()) { String delDn = toDelete.pop(); final NamingEnumeration<NameClassPair> childrens = ctx.list(delDn); if (childrens.hasMoreElements()) { toDelete.push(delDn); while (childrens.hasMoreElements()) { toDelete.push(childrens.nextElement().getNameInNamespace()); } } else { ctx.unbind(delDn); } } }
public static void delete(DirContext ctx, String dn) throws NamingException { Stack<String> toDelete = new Stack<String>(); toDelete.push(dn); while (!toDelete.empty()) { String delDn = toDelete.pop(); final NamingEnumeration<NameClassPair> childrens = ctx.list(delDn); if (childrens.hasMoreElements()) { toDelete.push(delDn); while (childrens.hasMoreElements()) { toDelete.push(childrens.nextElement().getNameInNamespace()); } } else { ctx.unbind(delDn); } } }
while (retEnum.hasMore()) { SearchResult sr = (SearchResult) retEnum.next(); System.out.println(">>" + sr.getNameInNamespace());
System.out.println(">>" + s.getNameInNamespace());
public synchronized void destroySubcontextWithChilds(String name) throws NamingException { NamingEnumeration<NameClassPair> list = ctx.list(name); try { while (list.hasMore()) destroySubcontextWithChilds(list.next().getNameInNamespace()); } finally { LdapUtils.safeClose(list); } ctx.destroySubcontext(name); }
public synchronized void destroySubcontextWithChilds(String name) throws NamingException { NamingEnumeration<NameClassPair> list = ctx.list(name); try { while (list.hasMore()) destroySubcontextWithChilds(list.next().getNameInNamespace()); } finally { LdapUtils.safeClose(list); } ctx.destroySubcontext(name); }
/** * print out a naming enumeration * @param namingEnumeration * @throws NamingException */ public static void printNamingEnumeration(NamingEnumeration<?> namingEnumeration) throws NamingException { while (namingEnumeration.hasMore()) { Object nextElement = namingEnumeration.next(); if (nextElement instanceof Attribute) { Attribute attribute = (Attribute)nextElement; printAttribute(attribute); } else if (nextElement instanceof SearchResult) { SearchResult searchResult = (SearchResult)nextElement; System.out.println("Search result: " + searchResult.getNameInNamespace()); Attributes attributes = searchResult.getAttributes(); printAttributes(attributes); } else if (nextElement instanceof NameClassPair) { NameClassPair nameClassPair = (NameClassPair)namingEnumeration.nextElement(); System.out.println("Name class pair: " + nameClassPair.getClassName() + ", " + nameClassPair.getNameInNamespace()); } else { throw new RuntimeException("Not expecting type: " + nextElement); } } }
/** * print out a naming enumeration * @param namingEnumeration * @throws NamingException */ public static void printNamingEnumeration(NamingEnumeration namingEnumeration) throws NamingException { while (namingEnumeration.hasMore()) { Object nextElement = namingEnumeration.next(); if (nextElement instanceof Attribute) { Attribute attribute = (Attribute)nextElement; printAttribute(attribute); } else if (nextElement instanceof SearchResult) { SearchResult searchResult = (SearchResult)nextElement; System.out.println("Search result: " + searchResult.getNameInNamespace()); Attributes attributes = searchResult.getAttributes(); printAttributes(attributes); } else if (nextElement instanceof NameClassPair) { NameClassPair nameClassPair = (NameClassPair)namingEnumeration.nextElement(); System.out.println("Name class pair: " + nameClassPair.getClassName() + ", " + nameClassPair.getNameInNamespace()); } else { throw new RuntimeException("Not expecting type: " + nextElement); } } }
System.out.println("distinguisedName: " + result.getNameInNamespace() ); // CN=Firstname Lastname,OU=Mycity,DC=mydomain,DC=com
ret = sr.getNameInNamespace(); break;
String userDN = sr.getNameInNamespace();