/**
   * Clear the directory sub-tree starting with the node represented by the supplied distinguished
   * name.
   *
   * @param ctx The DirContext to use for cleaning the tree.
   * @param name the distinguished name of the root node.
   * @throws NamingException if anything goes wrong removing the sub-tree.
   */
  public static void clearSubContexts(DirContext ctx, Name name) throws NamingException {

    NamingEnumeration enumeration = null;
    try {
      enumeration = ctx.listBindings(name);
      while (enumeration.hasMore()) {
        Binding element = (Binding) enumeration.next();
        Name childName = LdapUtils.newLdapName(element.getName());
        childName = LdapUtils.prepend(childName, name);

        try {
          ctx.destroySubcontext(childName);
        } catch (ContextNotEmptyException e) {
          clearSubContexts(ctx, childName);
          ctx.destroySubcontext(childName);
        }
      }
    } catch (NamingException e) {
      e.printStackTrace();
    } finally {
      try {
        enumeration.close();
      } catch (Exception e) {
        // Never mind this
      }
    }
  }
Exemple #2
0
 // 删除用户
 public void deleteUser(String uid) throws NamingException {
   if (!isUserexist(uid)) {
     throw new NamingException("The user(uid: " + uid + ") does not exist!n");
   }
   ctx.destroySubcontext("uid=" + uid + "," + BASE_DN);
   System.out.println("User(uid: " + uid + ") deleted.n");
 }
 /**
  * ************************************************************************* Delete the attribute
  * from the ldap directory
  *
  * @param string The string (dn) value
  *     ************************************************************************
  */
 public static void deleteTest(DirContext dirContext, String string) throws NamingException {
   if (dirContext == null) {
     throw new NamingException(CONTEXT_IS_NULL);
   }
   dirContext.destroySubcontext(string);
 }
Exemple #4
0
 /**
  * Delete the attribute from the ldap directory.
  *
  * @param string the string (dn) value
  */
 public void deleteTest(String string) throws NamingException {
   dirContext.destroySubcontext(string);
 }