1 Reply Latest reply: May 2, 2012 9:47 PM by handat RSS

    TreeDeleteControl

    934335
      Hi

      I am exceuting a program regarding TreeDeleteControl in Java accessing the Sun Directory Server Version 7.0. I want to delete a sub-tree functionality entirely 'ou=xxx,ou=aaa,dc=example,dc=com'. The program is as follows:

      /**
      * A code example of Tree Delete Control JNDI Client for AD
      * Note: This example has been tested to work with Active Directory 2003
      */
      import javax.naming.*;
      import javax.naming.directory.*;
      import javax.naming.ldap.*;
      import java.util.Hashtable;

      public class TreeDeleteControlJndiClient
      {            
      static final String TREE_DELETE_CONTROL_OID = "1.2.840.113556.1.4.805";

      public static void main(String[] args)
      {
      Hashtable env = new Hashtable();

      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
      env.put(Context.PROVIDER_URL, "ldap://myAactiveDirectory:389");
      env.put(Context.SECURITY_AUTHENTICATION, "simple");
      env.put(Context.SECURITY_PRINCIPAL, "testUser@myDomain.com");
      env.put(Context.SECURITY_CREDENTIALS, "password");
           
      try{
           
      // Create the initial directory context
      LdapContext ctx = new InitialLdapContext(env, null);
                
      System.out.println("Initial binding done!");

      /* Query the server to see if the Tree Delete Control is supported */
      if (!isTreeDeleteControlSupported(ctx)){
      System.out.println("The server does not support Tree Delete Control.");
      System.exit(1);
      }

      /* Activate the control */
      Control[] tdCtls = new Control[]{new TreeDeleteControl()};
      ctx.setRequestControls(tdCtls);
      String delete_dn = "ou=xxx,ou=aaa,dc=example,dc=com";
      ctx.destroySubcontext(delete_dn);
           
      // Close the LDAP association
      ctx.close();
           
      }catch (Exception e){
           e.printStackTrace();
      }
      }

      /**
      * Is Tree Delete Control supported?
      *
      * Query the rootDSE object to find out if the Tree Delete Control
      * is supported.
      */
      static boolean isTreeDeleteControlSupported(LdapContext ctx)
           throws NamingException
      {
      SearchControls ctl = new SearchControls();
      ctl.setReturningAttributes(new String[]{"supportedControl"});
      ctl.setSearchScope(SearchControls.OBJECT_SCOPE);

      /* search for the rootDSE object */
      NamingEnumeration results = ctx.search("", "(objectClass=*)", ctl);

      while(results.hasMore()){
      SearchResult entry = (SearchResult)results.next();
      NamingEnumeration attrs = entry.getAttributes().getAll();
      while (attrs.hasMore()){
           Attribute attr = (Attribute)attrs.next();
           NamingEnumeration vals = attr.getAll();
      while (vals.hasMore()){
      String value = (String) vals.next();
      if (value.equals(TREE_DELETE_CONTROL_OID))
      return true;
      }
      }
      }
      return false;
      }
      }


      class TreeDeleteControl implements Control
      {
      public byte[] getEncodedValue() {
      return new byte[] {};
      }

      public String getID() {
      return "1.2.840.113556.1.4.805";
      }

      public boolean isCritical() {
      return true;
      }
      }


      When I run the program, I get the following error:
      javax.naming.OperationNotSupportedException: [LDAP: error code 12 - Unavailable Critical Extension]; remaining name 'ou=xxx,ou=aaa,dc=example,dc=com'
           at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3127)
           at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3013)
           at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
           at com.sun.jndi.ldap.LdapCtx.c_destroySubcontext(LdapCtx.java:847)
           at com.sun.jndi.toolkit.ctx.ComponentContext.p_destroySubcontext(ComponentContext.java:653)
           at com.sun.jndi.toolkit.ctx.PartialCompositeContext.destroySubcontext(PartialCompositeContext.java:336)
           at com.sun.jndi.toolkit.ctx.PartialCompositeContext.destroySubcontext(PartialCompositeContext.java:326)
           at javax.naming.InitialContext.destroySubcontext(InitialContext.java:456)
           at vih.sources.TreeDeleteControlJndiClient.main(TreeDeleteControlJndiClient.java:53)

      I have browsed a little bit and found out that this error means that my server doesn't support TreeDeleteControl. But, is there any other way which I am using or am I wrong in saying that my server doesn't support TreeDeleteControl?.

      If my server doesn' really support TreeDeleteControl, can you tell me which Version of SUNOne has this control functionality included?

      ANy Help on this is highly appreciated?

      Thanks in Advance
      Sandeep
        • 1. Re: TreeDeleteControl
          handat
          931332 wrote:

          I have browsed a little bit and found out that this error means that my server doesn't support TreeDeleteControl. But, is there any other way which I am using or am I wrong in saying that my server doesn't support TreeDeleteControl?.

          If my server doesn' really support TreeDeleteControl, can you tell me which Version of SUNOne has this control functionality included?
          Try OpenDS or OUD11g instead for OID 1.2.840.113556.1.4.805 functionality.