Beispiel #1
0
  private String remove_from_ldap(String dn) {
    CMS.debug("UpdateDomainXML: delete_from_ldap: starting dn: " + dn);
    String status = SUCCESS;
    ILdapConnFactory connFactory = null;
    LDAPConnection conn = null;
    IConfigStore cs = CMS.getConfigStore();

    try {
      IConfigStore ldapConfig = cs.getSubStore("internaldb");
      connFactory = CMS.getLdapBoundConnFactory("UpdateDomainXML");
      connFactory.init(ldapConfig);
      conn = connFactory.getConn();
      conn.delete(dn);
    } catch (LDAPException e) {
      int resultCode = e.getLDAPResultCode();
      if (resultCode != LDAPException.NO_SUCH_OBJECT) {
        status = FAILED;
        CMS.debug("Failed to delete entry" + e.toString());
      }
    } catch (Exception e) {
      CMS.debug("Failed to delete entry" + e.toString());
    } finally {
      try {
        if ((conn != null) && (connFactory != null)) {
          CMS.debug("Releasing ldap connection");
          connFactory.returnConn(conn);
        }
      } catch (Exception e) {
        CMS.debug("Error releasing the ldap connection" + e.toString());
      }
    }
    return status;
  }
Beispiel #2
0
  private String add_to_ldap(LDAPEntry entry, String dn) {
    CMS.debug("UpdateDomainXML: add_to_ldap: starting");
    String status = SUCCESS;
    ILdapConnFactory connFactory = null;
    LDAPConnection conn = null;
    IConfigStore cs = CMS.getConfigStore();

    try {
      IConfigStore ldapConfig = cs.getSubStore("internaldb");
      connFactory = CMS.getLdapBoundConnFactory("UpdateDomainXML");
      connFactory.init(ldapConfig);
      conn = connFactory.getConn();
      conn.add(entry);
    } catch (LDAPException e) {
      if (e.getLDAPResultCode() == LDAPException.ENTRY_ALREADY_EXISTS) {
        CMS.debug("UpdateDomainXML: Entry already exists");
        try {
          conn.delete(dn);
          conn.add(entry);
        } catch (LDAPException ee) {
          CMS.debug("UpdateDomainXML: Error when replacing existing entry " + ee.toString());
          status = FAILED;
        }
      } else {
        CMS.debug("UpdateDomainXML: Failed to update ldap domain info. Exception: " + e.toString());
        status = FAILED;
      }
    } catch (Exception e) {
      CMS.debug("Failed to add entry" + e.toString());
    } finally {
      try {
        if ((conn != null) && (connFactory != null)) {
          CMS.debug("Releasing ldap connection");
          connFactory.returnConn(conn);
        }
      } catch (Exception e) {
        CMS.debug("Error releasing the ldap connection" + e.toString());
      }
    }
    return status;
  }