From 959c9ded0c297d00500678a0c80d7d6d8a5265fe Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 10 Jul 2007 16:03:42 +0000
Subject: [PATCH] Fix a set of problems with the configuration interface in which there were a number of cases in which insufficient validation was performed.  In particular, if a new configuration object was added over protocol or an existing configuration object was changed from disabled to enabled, then the server would only perform generic validation for that component and would not have any way to perform more detailed validation that could detect larger numbers of problems.

---
 opends/src/server/org/opends/server/core/PasswordGeneratorConfigManager.java |   49 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/PasswordGeneratorConfigManager.java b/opends/src/server/org/opends/server/core/PasswordGeneratorConfigManager.java
index 1b7e169..734203f 100644
--- a/opends/src/server/org/opends/server/core/PasswordGeneratorConfigManager.java
+++ b/opends/src/server/org/opends/server/core/PasswordGeneratorConfigManager.java
@@ -30,6 +30,7 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -125,7 +126,8 @@
         try
         {
           PasswordGenerator<? extends PasswordGeneratorCfg>
-               generator = loadGenerator(className, generatorConfiguration);
+               generator = loadGenerator(className, generatorConfiguration,
+                                         true);
           passwordGenerators.put(generatorConfiguration.dn(), generator);
           DirectoryServer.registerPasswordGenerator(generatorConfiguration.dn(),
               generator);
@@ -155,7 +157,7 @@
       String className = configuration.getGeneratorClass();
       try
       {
-        loadGenerator(className, null);
+        loadGenerator(className, configuration, false);
       }
       catch (InitializationException ie)
       {
@@ -225,7 +227,7 @@
          passwordGenerator = null;
     try
     {
-      passwordGenerator = loadGenerator(className, configuration);
+      passwordGenerator = loadGenerator(className, configuration, true);
     }
     catch (InitializationException ie)
     {
@@ -260,7 +262,7 @@
       String className = configuration.getGeneratorClass();
       try
       {
-        loadGenerator(className, null);
+        loadGenerator(className, configuration, false);
       }
       catch (InitializationException ie)
       {
@@ -299,7 +301,7 @@
     String className = configuration.getGeneratorClass();
     try
     {
-      passwordGenerator = loadGenerator(className, configuration);
+      passwordGenerator = loadGenerator(className, configuration, true);
     }
     catch (InitializationException ie)
     {
@@ -365,6 +367,8 @@
    * @param  configuration  The configuration to use to initialize the
    *                        password generator, or {@code null} if the
    *                        password generator should not be initialized.
+   * @param  initialize     Indicates whether the password generator instance
+   *                        should be initialized.
    *
    * @return  The possibly initialized password generator.
    *
@@ -373,7 +377,8 @@
    */
   private PasswordGenerator<? extends PasswordGeneratorCfg>
                loadGenerator(String className,
-                             PasswordGeneratorCfg configuration)
+                             PasswordGeneratorCfg configuration,
+                             boolean initialize)
           throws InitializationException
   {
     try
@@ -388,13 +393,43 @@
            (PasswordGenerator<? extends PasswordGeneratorCfg>)
            generatorClass.newInstance();
 
-      if (configuration != null)
+      if (initialize)
       {
         Method method =
           generator.getClass().getMethod("initializePasswordGenerator",
                   configuration.definition().getServerConfigurationClass());
         method.invoke(generator, configuration);
       }
+      else
+      {
+        Method method =
+             generator.getClass().getMethod("isConfigurationAcceptable",
+                                            PasswordGeneratorCfg.class,
+                                            List.class);
+
+        List<String> unacceptableReasons = new ArrayList<String>();
+        Boolean acceptable = (Boolean) method.invoke(generator, configuration,
+                                                     unacceptableReasons);
+        if (! acceptable)
+        {
+          StringBuilder buffer = new StringBuilder();
+          if (! unacceptableReasons.isEmpty())
+          {
+            Iterator<String> iterator = unacceptableReasons.iterator();
+            buffer.append(iterator.next());
+            while (iterator.hasNext())
+            {
+              buffer.append(".  ");
+              buffer.append(iterator.next());
+            }
+          }
+
+          int    msgID   = MSGID_CONFIG_PWGENERATOR_CONFIG_NOT_ACCEPTABLE;
+          String message = getMessage(msgID, String.valueOf(configuration.dn()),
+                                      buffer.toString());
+          throw new InitializationException(msgID, message);
+        }
+      }
 
       return generator;
     }

--
Gitblit v1.10.0