From 8140b0a19865e2754ad927906a607a86533f426c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 13 Jul 2009 09:20:24 +0000
Subject: [PATCH] Fix for issue 4106 (dsreplication should allow to merge disjoint replication topologies) dsreplication allows to merge disjoint topologies.  The limitations on the topologies that can be merged are described in the issue report.

---
 opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index 468e4d5..c4e0596 100644
--- a/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -60,6 +60,8 @@
     new HashMap<ServerProperty, Object>();
   private TopologyCacheException lastException;
 
+  private static final String TRUSTSTORE_DN = "cn=ads-truststore";
+
   private static final Logger LOG =
     Logger.getLogger(ServerDescriptor.class.getName());
 
@@ -1337,7 +1339,6 @@
   {
     /* TODO: this DN is declared in some core constants file. Create a
        constants file for the installer and import it into the core. */
-    final String truststoreDnStr = "cn=ads-truststore";
     final Attribute oc = new BasicAttribute("objectclass");
     oc.add("top");
     oc.add("ds-cfg-instance-key");
@@ -1353,7 +1354,7 @@
                       getAttributeName() + ";binary", keyEntry.getValue()));
       final LdapName keyDn = new LdapName((new StringBuilder(rdnAttr.getID()))
               .append("=").append(Rdn.escapeValue(rdnAttr.get())).append(",")
-              .append(truststoreDnStr).toString());
+              .append(TRUSTSTORE_DN).toString());
       try {
         ctx.createSubcontext(keyDn, keyAttrs).close();
       }
@@ -1365,6 +1366,42 @@
   }
 
   /**
+   * Cleans up the contents of the ads truststore.
+   *
+   * @param ctx the bound instance.
+   * @throws NamingException in case an error occurs while updating the
+   * instance's ads-truststore via LDAP.
+   */
+  public static void cleanAdsTrustStore(InitialLdapContext ctx)
+  throws NamingException
+  {
+    try
+    {
+      SearchControls sc = new SearchControls();
+      sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+      String[] attList = {"dn"};
+      sc.setReturningAttributes(attList);
+      NamingEnumeration<SearchResult> ne = ctx.search(TRUSTSTORE_DN,
+          "(objectclass=ds-cfg-instance-key)", sc);
+      ArrayList<String> dnsToDelete = new ArrayList<String>();
+      while (ne.hasMore())
+      {
+        SearchResult sr = ne.next();
+        dnsToDelete.add(sr.getName()+","+TRUSTSTORE_DN);
+      }
+      for (String dn : dnsToDelete)
+      {
+        ctx.destroySubcontext(dn);
+      }
+    }
+    catch (NameNotFoundException nnfe)
+    {
+      // Ignore
+      LOG.log(Level.WARNING, "Error cleaning truststore: "+nnfe, nnfe);
+    }
+  }
+
+  /**
    * Returns the values of the ds-base-dn-entry count attributes for the given
    * backend monitor entry using the provided InitialLdapContext.
    * @param ctx the InitialLdapContext to use to update the configuration.

--
Gitblit v1.10.0