From 6f14605908036dd6c2cfc64f31f1d5d8d17f86a8 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Mon, 04 Apr 2016 13:38:34 +0000
Subject: [PATCH] Remove ConfigurationBootstrapper

---
 /dev/null                                                                      |   83 -----------------------------------------
 opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java |   19 +++++++--
 opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java |    3 -
 3 files changed, 15 insertions(+), 90 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationBootstrapper.java b/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationBootstrapper.java
deleted file mode 100644
index 4a1b06e..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationBootstrapper.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.core;
-
-import java.lang.reflect.Constructor;
-
-import static org.opends.messages.CoreMessages.ERR_CANNOT_INSTANTIATE_CONFIG_HANDLER;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.config.ConfigurationFramework;
-import org.forgerock.opendj.config.server.ConfigException;
-import org.opends.server.types.InitializationException;
-
-/**
- * Bootstrap the server configuration.
- */
-public class ConfigurationBootstrapper
-{
-
-  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
-  /**
-   * Bootstrap the server configuration.
-   * <p>
-   * The returned server management context is fully initialized with
-   * all configuration objects valued from configuration file.
-   *
-   * @param serverContext
-   *            The server context.
-   * @param configClass
-   *            The actual configuration class to use.
-   * @return the configuration handler
-   * @throws InitializationException
-   *            If an error occurs during bootstrapping.
-   */
-  public static ConfigurationHandler bootstrap(ServerContext serverContext, Class<ConfigurationHandler> configClass)
-      throws InitializationException {
-    final ConfigurationFramework configFramework = ConfigurationFramework.getInstance();
-    try
-    {
-      if (!configFramework.isInitialized())
-      {
-        configFramework.initialize();
-      }
-    }
-    catch (ConfigException e)
-    {
-      // TODO : fix the message
-      throw new InitializationException(LocalizableMessage.raw("Cannot initialize configuration framework"), e);
-    }
-
-    // Load and instantiate the configuration handler class.
-    Class<ConfigurationHandler> handlerClass = configClass;
-    final ConfigurationHandler configurationHandler;
-    try
-    {
-      Constructor<ConfigurationHandler> cons = handlerClass.getConstructor(ServerContext.class);
-      configurationHandler = cons.newInstance(serverContext);
-    }
-    catch (Exception e)
-    {
-      logger.traceException(e);
-      LocalizableMessage message = ERR_CANNOT_INSTANTIATE_CONFIG_HANDLER.get(configClass, e.getLocalizedMessage());
-      throw new InitializationException(message, e);
-    }
-    configurationHandler.initialize();
-    return configurationHandler;
-  }
-}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
index 9ce2a03..880d25c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -880,8 +880,8 @@
       // Set default values for variables that may be needed during schema processing.
       directoryServer.syntaxEnforcementPolicy = AcceptRejectWarn.REJECT;
 
-      // Create and initialize the server schema,
-      // and register a minimal set of matching rules and attribute syntaxes.
+      // Create the server schema and initialize and register a minimal set of
+      // matching rules and attribute syntaxes.
       try
       {
         directoryServer.setSchema(new Schema(org.forgerock.opendj.ldap.schema.Schema.getCoreSchema()));
@@ -1099,8 +1099,9 @@
    */
   public void initializeConfiguration() throws InitializationException
   {
+    configFile = environmentConfig.getConfigFile();
     configClass = environmentConfig.getConfigClass();
-    configurationHandler = ConfigurationBootstrapper.bootstrap(serverContext, configClass);
+    configurationHandler = ConfigurationHandler.bootstrapConfiguration(serverContext, configClass);
     serverManagementContext = new ServerManagementContext(configurationHandler);
 
     final ConfigurationBackend configBackend = new ConfigurationBackend(serverContext, configurationHandler);
@@ -1210,6 +1211,13 @@
 
       initializeSchema();
 
+      // At this point, it is necessary to reload the configuration because it was
+      // loaded with an incomplete schema (meaning some attributes types and objectclasses
+      // were defined by default, using a non-strict schema).
+      // Configuration add/delete/change listeners are preserved by calling this method,
+      // so schema elements listeners already registered are not lost.
+      configurationHandler.reinitializeWithFullSchema(schema.getSchemaNG());
+
       commonAudit = new CommonAudit(serverContext);
 
       // Allow internal plugins to be registered.
@@ -1277,7 +1285,6 @@
       groupManager.performBackendPreInitializationProcessing(configBackend);
 
       AccessControlConfigManager.getInstance().initializeAccessControl(serverContext);
-      initializeAuthenticationPolicyComponents();
 
       // Initialize all the backends and their associated suffixes
       // and initialize the workflows when workflow configuration mode is auto.
@@ -1302,6 +1309,7 @@
       monitorConfigManager = new MonitorConfigManager(serverContext);
       monitorConfigManager.initializeMonitorProviders();
 
+      initializeAuthenticationPolicyComponents();
 
       pluginConfigManager.initializeUserPlugins(null);
 
@@ -1993,7 +2001,8 @@
   @Deprecated
   public static Entry getConfigEntry(DN entryDN) throws ConfigException
   {
-    return Converters.to(directoryServer.configurationHandler.getEntry(entryDN));
+    org.forgerock.opendj.ldap.Entry entry = directoryServer.configurationHandler.getEntry(entryDN);
+    return entry != null ? Converters.to(entry) : null;
   }
 
   /**
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java b/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
index bde41ab..f0d67f0 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
@@ -20,7 +20,6 @@
 import java.io.File;
 
 import org.forgerock.opendj.config.server.ServerManagementContext;
-import org.opends.server.core.ConfigurationBootstrapper;
 import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.ServerContext;
 import org.opends.server.types.DirectoryEnvironmentConfig;
@@ -82,7 +81,7 @@
       throws InitializationException
   {
     final ConfigurationHandler configHandler =
-        ConfigurationBootstrapper.bootstrap(serverContext, ConfigurationHandler.class);
+        ConfigurationHandler.bootstrapConfiguration(serverContext, ConfigurationHandler.class);
     final ServerManagementContext serverManagementContext = new ServerManagementContext(configHandler);
     when(serverContext.getServerManagementContext()).thenReturn(serverManagementContext);
     return this;

--
Gitblit v1.10.0