mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
18.15.2007 1d5f9c9484a47d91ab2c4cf3796e5b1effca89ec
opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/ConfigFromFile.java
@@ -32,6 +32,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.opends.server.core.DirectoryServer;
import org.opends.server.util.LDIFException;
@@ -62,6 +63,11 @@
    DirectoryServer.getObjectClass("ds-cfg-backend", true);
  private final ObjectClass administrativeUserOc =
    DirectoryServer.getObjectClass("ds-cfg-root-dn", true);
  private final ObjectClass syncProviderOc =
    DirectoryServer.getObjectClass("ds-cfg-synchronization-provider", true);
  private final ObjectClass syncConfigOc =
    DirectoryServer.getObjectClass("ds-cfg-synchronization-provider-config",
    true);
  private HashSet<ListenerDescriptor> listeners =
    new HashSet<ListenerDescriptor>();
@@ -69,7 +75,8 @@
    new HashSet<DatabaseDescriptor>();
  private HashSet<String> administrativeUsers = new HashSet<String>();
  private String errorMessage;
  private boolean synchronizationConfigured = false;
  private HashSet<String> synchronizedSuffixes = new HashSet<String>();
  /**
   * Default constructor.
@@ -87,6 +94,11 @@
  public void readConfiguration()
  {
    errorMessage = null;
    listeners.clear();
    databases.clear();
    administrativeUsers.clear();
    synchronizationConfigured = false;
    synchronizedSuffixes.clear();
    try
    {
      Installation installation =
@@ -99,6 +111,7 @@
      {
        updateConfig(entry);
      }
      updateSynchronization();
    }
    catch (IOException ioe)
    {
@@ -246,6 +259,14 @@
   {
     updateConfigWithAdministrativeUser(entry);
   }
   else if (entry.hasObjectClass(syncProviderOc))
   {
     updateConfigWithSyncProviderEntry(entry);
   }
   else if (entry.hasObjectClass(syncConfigOc))
   {
     updateConfigWithSyncConfig(entry);
   }
  }
  /**
@@ -350,13 +371,26 @@
   */
  private void updateConfigWithBackend(Entry entry)
  {
    String baseDn = getFirstValue(entry, "ds-cfg-backend-base-dn");
    String id = getFirstValue(entry, "ds-cfg-backend-id");
    int nEntries = -1; // Unknown
    if (!isConfigBackend(id))
    {
      databases.add(new DatabaseDescriptor(id, baseDn, nEntries));
      Set<String> baseDns = new TreeSet<String>();
      baseDns.addAll(getValues(entry, "ds-cfg-backend-base-dn"));
      Set<BaseDNDescriptor> replicas = new LinkedHashSet<BaseDNDescriptor>();
      for (String baseDn : baseDns)
      {
        replicas.add(getBaseDNDescriptor(entry, baseDn));
      }
      DatabaseDescriptor db = new DatabaseDescriptor(id, replicas, nEntries);
      databases.add(db);
      for (BaseDNDescriptor rep: replicas)
      {
        rep.setDatabase(db);
      }
    }
  }
@@ -371,6 +405,70 @@
  }
  /**
   * Updates the synchronization configuration data we expose to the user with
   * the provided entry object.
   * @param entry the entry to analyze.
   */
  private void updateConfigWithSyncProviderEntry(Entry entry)
  {
    if ("true".equalsIgnoreCase(getFirstValue(entry,
        "ds-cfg-synchronization-provider-enabled")))
    {
      synchronizationConfigured = true;
    }
    else
    {
      synchronizationConfigured = false;
    }
  }
  /**
   * Updates the databases suffixes with the list of synchronized suffixes
   * found.
   */
  private void updateSynchronization()
  {
    if (synchronizationConfigured)
    {
      for (String suffixDn: synchronizedSuffixes)
      {
        BaseDNDescriptor replica = null;
        for (DatabaseDescriptor db: databases)
        {
          Set<BaseDNDescriptor> replicas = db.getBaseDns();
          for (BaseDNDescriptor rep: replicas)
          {
            if (Utils.areDnsEqual(rep.getDn(), suffixDn))
            {
              replica = rep;
              break;
            }
          }
          if (replica != null)
          {
            break;
          }
        }
        if (replica != null)
        {
          replica.setType(BaseDNDescriptor.Type.SYNCHRONIZED);
        }
      }
    }
  }
  /**
   * Updates the synchronization configuration data we expose to the user with
   * the provided entry object.
   * @param entry the entry to analyze.
   */
  private void updateConfigWithSyncConfig(Entry entry)
  {
    synchronizedSuffixes.addAll(getValues(entry, "ds-cfg-synchronization-dn"));
  }
  /**
   * The following three methods are just commodity methods to get localized
   * messages.
   */
@@ -417,4 +515,13 @@
    }
    return v;
  }
  /**
   * Create a non synchronized base DN descriptor.
   */
  private BaseDNDescriptor getBaseDNDescriptor(Entry entry, String baseDn)
  {
    return new BaseDNDescriptor(BaseDNDescriptor.Type.NOT_SYNCHRONIZED,
        baseDn, null, -1, -1);
  }
}