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;
  }
  public LDAPSourceImpl(
      Logger logger,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_VERSION) int ldapVersion,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_HOSTNAME) String ldapHostName,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_HOSTPORT) int ldapPort,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_AUTHDN) String ldapAuthDN,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_AUTHPWD) String ldapPwd,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_SIZELIMIT) String sizeLimit,
      @Inject @Symbol(ChenilleKitLDAPConstants.LDAP_TIMELIMIT) String timeLimit) {
    this.logger = logger;
    this.ldapVersion = ldapVersion;

    if (ldapHostName == null || ldapHostName.trim().length() < 1)
      throw new RuntimeException(
          "property '" + ChenilleKitLDAPConstants.LDAP_HOSTNAME + "' cant be empty!");

    this.ldapHostName = ldapHostName;

    this.ldapPort = ldapPort;
    this.ldapAuthDN = ldapAuthDN;
    this.ldapPwd = ldapPwd;

    ldapConnection = new LDAPConnection();

    try {
      ldapConnection.setOption(LDAPv2.SIZELIMIT, new Integer(sizeLimit));
      ldapConnection.setOption(LDAPv2.TIMELIMIT, new Integer(timeLimit));
    } catch (LDAPException le) {
      logger.error(le.getMessage(), le);

      throw new RuntimeException(le);
    }
  }
Beispiel #3
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;
  }