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/IdentityMapperConfigManager.java | 51 ++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/opends/src/server/org/opends/server/core/IdentityMapperConfigManager.java b/opends/src/server/org/opends/server/core/IdentityMapperConfigManager.java
index c2dc95d..7bd2b12 100644
--- a/opends/src/server/org/opends/server/core/IdentityMapperConfigManager.java
+++ b/opends/src/server/org/opends/server/core/IdentityMapperConfigManager.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;
@@ -124,7 +125,8 @@
String className = mapperConfiguration.getMapperClass();
try
{
- IdentityMapper mapper = loadMapper(className, mapperConfiguration);
+ IdentityMapper mapper = loadMapper(className, mapperConfiguration,
+ true);
identityMappers.put(mapperConfiguration.dn(), mapper);
DirectoryServer.registerIdentityMapper(mapperConfiguration.dn(),
mapper);
@@ -173,7 +175,7 @@
String className = configuration.getMapperClass();
try
{
- loadMapper(className, null);
+ loadMapper(className, configuration, false);
}
catch (InitializationException ie)
{
@@ -212,7 +214,7 @@
String className = configuration.getMapperClass();
try
{
- identityMapper = loadMapper(className, configuration);
+ identityMapper = loadMapper(className, configuration, true);
}
catch (InitializationException ie)
{
@@ -287,7 +289,7 @@
String className = configuration.getMapperClass();
try
{
- loadMapper(className, null);
+ loadMapper(className, configuration, false);
}
catch (InitializationException ie)
{
@@ -356,7 +358,7 @@
IdentityMapper identityMapper = null;
try
{
- identityMapper = loadMapper(className, configuration);
+ identityMapper = loadMapper(className, configuration, true);
}
catch (InitializationException ie)
{
@@ -387,8 +389,9 @@
* @param className The fully-qualified name of the identity mapper
* class to load, instantiate, and initialize.
* @param configuration The configuration to use to initialize the identity
- * mapper, or {@code null} if the identity mapper
- * should not be initialized.
+ * mapper. It must not be {@code null}.
+ * @param initialize Indicates whether the identity mapper instance
+ * should be initialized.
*
* @return The possibly initialized identity mapper.
*
@@ -396,7 +399,8 @@
* initialize the identity mapper.
*/
private IdentityMapper loadMapper(String className,
- IdentityMapperCfg configuration)
+ IdentityMapperCfg configuration,
+ boolean initialize)
throws InitializationException
{
try
@@ -409,13 +413,42 @@
propertyDefinition.loadClass(className, IdentityMapper.class);
IdentityMapper mapper = mapperClass.newInstance();
- if (configuration != null)
+ if (initialize)
{
Method method =
mapper.getClass().getMethod("initializeIdentityMapper",
configuration.definition().getServerConfigurationClass());
method.invoke(mapper, configuration);
}
+ else
+ {
+ Method method = mapper.getClass().getMethod("isConfigurationAcceptable",
+ IdentityMapperCfg.class,
+ List.class);
+
+ List<String> unacceptableReasons = new ArrayList<String>();
+ Boolean acceptable = (Boolean) method.invoke(mapper, 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_IDMAPPER_CONFIG_NOT_ACCEPTABLE;
+ String message = getMessage(msgID, String.valueOf(configuration.dn()),
+ buffer.toString());
+ throw new InitializationException(msgID, message);
+ }
+ }
return mapper;
}
--
Gitblit v1.10.0