3 Replies Latest reply: Jan 23, 2012 6:55 PM by EJP RSS

    Rollback in JAVA LDAP API

    912397
      Hi,

      We have been using a single LDAP directory background to add, update, and/or delete attributes (values) by calling the following API (code snippet).
      Hashtable<String,String> authEnv = new Hashtable<String,String>(11);
      authEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
      authEnv.put(Context.PROVIDER_URL, "ldaps://host:636");
      authEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
      authEnv.put(Context.SECURITY_PRINCIPAL, "uid=id,ou=Specials,dc=domain,dc=au");
      authEnv.put(Context.SECURITY_CREDENTIALS, "pwd");
      
      ModificationItem modItem = null;
      ....
      modItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE,new BasicAttribute(bean.getAttribute(), bean.getOldValue()));
      modsList.add(modItem);
      ...
      modItem = new ModificationItem(DirContext.ADD_ATTRIBUTE,new BasicAttribute(bean.getAttribute(), bean.getNewValue()));
      modsList.add(modItem);           
      ...
      ModificationItem [] mods = modsList.toArray(new ModificationItem[modsList.size()]);
      ...
      DirContext context = new InitialDirContext(authEnv);
      try{
      context.modifyAttributes("dn", mods);  
      } catch ....         
      The above code works for single call on all attribute actions (add,update,remove), if any attribute fails in that call, all will be rolled back automatically because that API will takes care of transactions.

      Now we got to do the same transactions on another LDAP directory after the first LDAP directory's successes, but here if any attributes fails during the second LDAP call, all in second must be rolled back and also need to rolled back in first LDAP changes also.

      Do we have any transaction process in this API like JDBC API? I couldn't find anything like that, please give me advice how to control transactions in both LDAP directories?

      Edited by: 909394 on Jan 20, 2012 1:17 PM
        • 1. Re: Rollback in JAVA LDAP API
          EJP
          First you need to discover whether your LDAP servers support transactions.
          • 2. Re: Rollback in JAVA LDAP API
            912397
            I think every LDAP server supports transaction support, otherwise the current application won't workout. As I said in my question our current application works in a transaction( sending collection of mod items and get updated all or none).

            Anyway is there any alternate way to find out the server supports transactions?
            • 3. Re: Rollback in JAVA LDAP API
              EJP
              I think every LDAP server supports transaction support
              1 No. OpenLDAP doesnt support transactions, at least not in the version I am using.
              our current application works in a transaction
              2. So what exactly is your question?
              Anyway is there any alternate way to find out the server supports transactions?
              3. Alternate to what?

              4. If 'every LDAP server supports transaction support' as you claim above, what again is your question?

              This doesn't make any sense.

              The fact of the matter is that you are confused about the terminology. The call above is atomic, not transactional. Transactions require begins and commits and rollbacks. There are extended LDAP operations for transactions: see http://tools.ietf.org/html/rfc5805. Whether your server supports them can be ascertained by querying the supportdExtension and supportedControl attributes of the root element: see the RFC.