/**
   * @param sKey anthentication key
   * @param removeKey remove after
   * @return
   * @throws Exception
   */
  public Map<String, String> authenticate(String sKey, boolean removeKey) throws Exception {
    Map<String, String> loginDomainId = new HashMap<String, String>();
    try {
      startTransaction(false);

      // Get the domain information
      KeyStoreRow ksr = getOrganization().keyStore.getRecordByKey(idAsInt(sKey));
      if (ksr == null) {
        throw new AdminException(
            "DomainDriverManager.authenticate",
            SilverpeasException.ERROR,
            "admin.EX_ERR_KEY_NOT_FOUND",
            "key: '" + sKey + "'");
      }

      loginDomainId.put("login", ksr.login);
      loginDomainId.put("domainId", idAsString(ksr.domainId));

      // Remove key from keytore in database
      if (removeKey) {
        getOrganization().keyStore.removeKeyStoreRecord(idAsInt(sKey));
      }

      // Commit transaction
      commit();
      return loginDomainId;
    } catch (AdminPersistenceException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.authenticate", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.authenticate",
          SilverpeasException.ERROR,
          "admin.EX_ERR_AUTHENTICATE",
          "key: '" + sKey + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
  /**
   * @param domainId
   * @return DomainDriver
   */
  public DomainDriver getDomainDriver(int domainId) throws Exception {
    DomainDriver domainDriver = null;
    boolean osAllocated = false;
    try {
      domainDriver = domainDriverInstances.get(idAsString(domainId));
      if (domainDriver == null) {
        // Set the OrganizationSchema (if not already done)
        getOrganizationSchema();
        osAllocated = true;

        // Get the domain information
        DomainRow dr = getOrganization().domain.getDomain(domainId);
        if (dr == null) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "admin.EX_ERR_DOMAIN_NOT_FOUND",
              "domain Id: '" + domainId + "'");
        }

        // Get the driver class name
        try {
          domainDriver = DomainDriverFactory.getDriver(dr.className);
          domainDriver.init(domainId, dr.propFileName, dr.authenticationServer);
        } catch (ClassNotFoundException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_CLASS_NOT_FOUND",
              e);
        } catch (IllegalAccessException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_ILLEGAL_ACCESS",
              e);
        } catch (InstantiationException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_INSTANTIATION",
              e);
        }

        // Save DomainDriver instance
        domainDriverInstances.put(idAsString(domainId), domainDriver);
      }
    } catch (AdminPersistenceException e) {
      throw new AdminException(
          "DomainDriverManager.getDomainDriver",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_DOMAIN_DRIVER",
          "domain id: '" + domainId + "'",
          e);
    } finally {
      if (osAllocated) {
        releaseOrganizationSchema();
      }
    }
    return domainDriver;
  }