From d24cd9dbc64c0a85f7d4178eadadc1d5cb4f6c44 Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Mon, 12 Jan 2009 09:59:37 +0000
Subject: [PATCH] Fix for  issue #2829 (Problems configuring and unconfiguring replication servers) scenario:  1) configure and start 2 servers s1 and s2  2) enable the replication between them  3) disable replication on server s1  4) disable replication on server s2  5) re-enable the replication between them

---
 opends/src/ads/org/opends/admin/ads/ADSContextHelper.java                       |    9 ++++++---
 opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java |   33 ++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java b/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java
index cb788e9..0caafed 100644
--- a/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java
+++ b/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2007-2008 Sun Microsystems, Inc.
+ *      Copyright 2007-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.admin.ads;
@@ -268,11 +268,14 @@
         ctx.createSubcontext(keyDn, keyAttrs).close();
       }
 
-      /* associate server entry with certificate entry via key ID attribute */
-      ctx.modifyAttributes(serverEntryDn,
+      if (serverEntryDn != null)
+      {
+        /* associate server entry with certificate entry via key ID attribute */
+        ctx.modifyAttributes(serverEntryDn,
           InitialLdapContext.REPLACE_ATTRIBUTE,
           (new BasicAttributes(
               ServerProperty.INSTANCE_KEY_ID.getAttributeName(), keyID)));
+      }
     }
     catch (NamingException ne)
     {
diff --git a/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index b26e558..97e2d0b 100644
--- a/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2007-2008 Sun Microsystems, Inc.
+ *      Copyright 2007-2009 Sun Microsystems, Inc.
  */
 
 package org.opends.server.tools.dsreplication;
@@ -63,10 +63,12 @@
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapName;
 import javax.net.ssl.TrustManager;
 
 import org.opends.admin.ads.ADSContext;
 import org.opends.admin.ads.ADSContextException;
+import org.opends.admin.ads.ADSContextHelper;
 import org.opends.admin.ads.ReplicaDescriptor;
 import org.opends.admin.ads.ServerDescriptor;
 import org.opends.admin.ads.SuffixDescriptor;
@@ -75,6 +77,7 @@
 import org.opends.admin.ads.TopologyCacheFilter;
 import org.opends.admin.ads.ADSContext.ADSPropertySyntax;
 import org.opends.admin.ads.ADSContext.AdministratorProperty;
+import org.opends.admin.ads.ADSContext.ServerProperty;
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.admin.ads.util.ConnectionUtils;
 import org.opends.admin.ads.util.PreferredConnection;
@@ -4909,10 +4912,18 @@
       }
     }
 
+    boolean recreateServerKey = false ;
+    Object keyId = null ;
+    Object certValue = null ;
     if (disableAllBaseDns)
     {
       // Unregister the server from the ADS
       server.updateAdsPropertiesWithServerProperties();
+      recreateServerKey = true ;
+      keyId = server.getAdsProperties().
+          get(ADSContext.ServerProperty.INSTANCE_KEY_ID);
+      certValue = server.getAdsProperties().
+          get(ADSContext.ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE);
       try
       {
         adsCtx.unregisterServer(server.getAdsProperties());
@@ -4924,6 +4935,7 @@
         catch (Throwable t)
         {
         }
+        recreateServerKey = true ;
       }
       catch (ADSContextException adce)
       {
@@ -5034,6 +5046,25 @@
         }
       }
     }
+    if (recreateServerKey)
+    {
+      Map<ServerProperty, Object> serverProperties =
+        new HashMap<ServerProperty, Object>();
+      serverProperties.put(ServerProperty.INSTANCE_KEY_ID, keyId);
+      serverProperties.put(ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE,
+          certValue);
+      LdapName ldapName = null ;
+      ADSContextHelper helper = new ADSContextHelper();
+      try
+      {
+        helper.registerInstanceKeyCertificate(
+            adsCtx.getDirContext(),serverProperties,ldapName);
+      }
+      catch (ADSContextException e)
+      {
+      }
+
+    }
   }
 
   /**

--
Gitblit v1.10.0