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/AttributeSyntaxConfigManager.java |   51 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/AttributeSyntaxConfigManager.java b/opends/src/server/org/opends/server/core/AttributeSyntaxConfigManager.java
index b311fc1..19cf217 100644
--- a/opends/src/server/org/opends/server/core/AttributeSyntaxConfigManager.java
+++ b/opends/src/server/org/opends/server/core/AttributeSyntaxConfigManager.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;
 
@@ -127,7 +128,8 @@
         String className = syntaxConfiguration.getSyntaxClass();
         try
         {
-          AttributeSyntax syntax = loadSyntax(className, syntaxConfiguration);
+          AttributeSyntax syntax = loadSyntax(className, syntaxConfiguration,
+                                              true);
 
           try
           {
@@ -172,7 +174,7 @@
       String className = configuration.getSyntaxClass();
       try
       {
-        loadSyntax(className, null);
+        loadSyntax(className, configuration, false);
       }
       catch (InitializationException ie)
       {
@@ -211,7 +213,7 @@
     String className = configuration.getSyntaxClass();
     try
     {
-      syntax = loadSyntax(className, configuration);
+      syntax = loadSyntax(className, configuration, true);
 
       try
       {
@@ -316,7 +318,7 @@
       String className = configuration.getSyntaxClass();
       try
       {
-        loadSyntax(className, null);
+        loadSyntax(className, configuration, false);
       }
       catch (InitializationException ie)
       {
@@ -405,7 +407,7 @@
     AttributeSyntax syntax = null;
     try
     {
-      syntax = loadSyntax(className, configuration);
+      syntax = loadSyntax(className, configuration, true);
 
       try
       {
@@ -447,8 +449,9 @@
    * @param  className      The fully-qualified name of the attribute syntax
    *                        class to load, instantiate, and initialize.
    * @param  configuration  The configuration to use to initialize the attribute
-   *                        syntax, or {@code null} if the attribute syntax
-   *                        should not be initialized.
+   *                        syntax.  It should not be {@code null}.
+   * @param  initialize     Indicates whether the key manager provider instance
+   *                        should be initialized.
    *
    * @return  The possibly initialized attribute syntax.
    *
@@ -456,7 +459,8 @@
    *                                   initialize the attribute syntax.
    */
   private AttributeSyntax loadSyntax(String className,
-                                     AttributeSyntaxCfg configuration)
+                                     AttributeSyntaxCfg configuration,
+                                     boolean initialize)
           throws InitializationException
   {
     try
@@ -469,13 +473,42 @@
            propertyDefinition.loadClass(className, AttributeSyntax.class);
       AttributeSyntax syntax = syntaxClass.newInstance();
 
-      if (configuration != null)
+      if (initialize)
       {
         Method method =
              syntax.getClass().getMethod("initializeSyntax",
                   configuration.definition().getServerConfigurationClass());
         method.invoke(syntax, configuration);
       }
+      else
+      {
+        Method method = syntax.getClass().getMethod("isConfigurationAcceptable",
+                                                    AttributeSyntaxCfg.class,
+                                                    List.class);
+
+        List<String> unacceptableReasons = new ArrayList<String>();
+        Boolean acceptable = (Boolean) method.invoke(syntax, 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_SCHEMA_SYNTAX_CONFIG_NOT_ACCEPTABLE;
+          String message = getMessage(msgID, String.valueOf(configuration.dn()),
+                                      buffer.toString());
+          throw new InitializationException(msgID, message);
+        }
+      }
 
       return syntax;
     }

--
Gitblit v1.10.0