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/SASLConfigManager.java |   54 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/SASLConfigManager.java b/opends/src/server/org/opends/server/core/SASLConfigManager.java
index 3cbd037..4a061e4 100644
--- a/opends/src/server/org/opends/server/core/SASLConfigManager.java
+++ b/opends/src/server/org/opends/server/core/SASLConfigManager.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;
 
@@ -129,7 +130,8 @@
         try
         {
           SASLMechanismHandler handler = loadHandler(className,
-                                                     handlerConfiguration);
+                                                     handlerConfiguration,
+                                                     true);
           handlers.put(handlerConfiguration.dn(), handler);
         }
         catch (InitializationException ie)
@@ -159,7 +161,7 @@
       String className = configuration.getHandlerClass();
       try
       {
-        loadHandler(className, null);
+        loadHandler(className, configuration, false);
       }
       catch (InitializationException ie)
       {
@@ -198,7 +200,7 @@
     String className = configuration.getHandlerClass();
     try
     {
-      handler = loadHandler(className, configuration);
+      handler = loadHandler(className, configuration, true);
     }
     catch (InitializationException ie)
     {
@@ -269,7 +271,7 @@
       String className = configuration.getHandlerClass();
       try
       {
-        loadHandler(className, null);
+        loadHandler(className, configuration, false);
       }
       catch (InitializationException ie)
       {
@@ -335,7 +337,7 @@
     SASLMechanismHandler handler = null;
     try
     {
-      handler = loadHandler(className, configuration);
+      handler = loadHandler(className, configuration, true);
     }
     catch (InitializationException ie)
     {
@@ -363,9 +365,10 @@
    *
    * @param  className      The fully-qualified name of the SASL mechanism
    *                        handler class to load, instantiate, and initialize.
-   * @param  configuration  The configuration to use to initialize the handler,
-   *                        or {@code null} if the SASL mechanism handler should
-   *                        not be initialized.
+   * @param  configuration  The configuration to use to initialize the handler.
+   *                        It must not be {@code null}.
+   * @param  initialize     Indicates whether the SASL mechanism handler
+   *                        instance should be initialized.
    *
    * @return  The possibly initialized SASL mechanism handler.
    *
@@ -374,7 +377,8 @@
    */
   private SASLMechanismHandler loadHandler(String className,
                                            SASLMechanismHandlerCfg
-                                                configuration)
+                                                configuration,
+                                           boolean initialize)
           throws InitializationException
   {
     try
@@ -387,13 +391,43 @@
            propertyDefinition.loadClass(className, SASLMechanismHandler.class);
       SASLMechanismHandler handler = handlerClass.newInstance();
 
-      if (configuration != null)
+      if (initialize)
       {
         Method method =
              handler.getClass().getMethod("initializeSASLMechanismHandler",
                   configuration.definition().getServerConfigurationClass());
         method.invoke(handler, configuration);
       }
+      else
+      {
+        Method method =
+             handler.getClass().getMethod("isConfigurationAcceptable",
+                                          SASLMechanismHandlerCfg.class,
+                                          List.class);
+
+        List<String> unacceptableReasons = new ArrayList<String>();
+        Boolean acceptable = (Boolean) method.invoke(handler, 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_SASL_CONFIG_NOT_ACCEPTABLE;
+          String message = getMessage(msgID, String.valueOf(configuration.dn()),
+                                      buffer.toString());
+          throw new InitializationException(msgID, message);
+        }
+      }
 
       return handler;
     }

--
Gitblit v1.10.0