mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
19.51.2016 7fade20a7d9c1bf7ced6f802e354663a308f5940
OPENDJ-3089 Move code to create server's specific syntaxes and matching rules to SchemaHandler class
2 files modified
111 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/RemoteSchemaLoader.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java 102 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/RemoteSchemaLoader.java
@@ -38,9 +38,7 @@
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.server.replication.plugin.HistoricalCsnOrderingMatchingRuleImpl;
import org.opends.server.schema.AciSyntax;
import org.opends.server.schema.SubtreeSpecificationSyntax;
import org.opends.server.schema.SchemaHandler;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
@@ -84,10 +82,7 @@
    // Add missing matching rules and attribute syntaxes to base schema to allow read of remote server schema
    // (see OPENDJ-1122 for more details)
    AciSyntax.addAciSyntax(schemaBuilder);
    SubtreeSpecificationSyntax.addSubtreeSpecificationSyntax(schemaBuilder);
    addMatchingRuleIfMissing(schemaBuilder, baseSchema, "1.3.6.1.4.1.26027.1.4.4", "historicalCsnOrderingMatch",
        "1.3.6.1.4.1.1466.115.121.1.40", new HistoricalCsnOrderingMatchingRuleImpl());
    SchemaHandler.addServerSyntaxesAndMatchingRules(schemaBuilder);
    // Add remote schema entry
    final SearchRequest request = newSearchRequest(
opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java
@@ -16,14 +16,11 @@
package org.opends.server.schema;
import static java.util.Collections.emptyList;
import static org.opends.messages.ConfigMessages.ERR_CONFIG_SCHEMA_DIR_NOT_DIRECTORY;
import static org.opends.messages.ConfigMessages.ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR;
import static org.opends.messages.SchemaMessages.NOTE_SCHEMA_IMPORT_FAILED;
import static org.opends.server.util.SchemaUtils.getElementSchemaFile;
import static org.forgerock.util.Utils.closeSilently;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.SchemaMessages.ERR_SCHEMA_HAS_WARNINGS;
import static org.opends.messages.SchemaMessages.*;
import static org.opends.server.util.SchemaUtils.getElementSchemaFile;
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.util.ServerConstants.SCHEMA_PROPERTY_FILENAME;
import static org.opends.server.util.StaticUtils.getExceptionMessage;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
@@ -220,24 +217,9 @@
      loadSchemaFromProviders(serverContext.getRootConfig(), schemaBuilder);
      try
      {
        // Add server specific syntaxes not provided by the SDK
        AciSyntax.addAciSyntax(schemaBuilder);
        SubtreeSpecificationSyntax.addSubtreeSpecificationSyntax(schemaBuilder);
      addServerSyntaxesAndMatchingRules(schemaBuilder);
        // Add server specific matching rules not provided by the SDK
        HistoricalCsnOrderingMatchingRuleImpl.addHistoricalCsnOrderingMatchingRule(schemaBuilder);
        AuthPasswordEqualityMatchingRule.addAuthPasswordEqualityMatchingRule(schemaBuilder);
        UserPasswordEqualityMatchingRule.addUserPasswordEqualityMatchingRule(schemaBuilder);
      }
      catch (ConflictingSchemaElementException e)
      {
        throw new ConfigException(e.getMessageObject(), e);
      }
      completeSchemaFromFiles(schemaBuilder);
      loadSchemaFromFiles(schemaBuilder);
      try
      {
@@ -256,6 +238,78 @@
  }
  /**
   * Adds server's specific syntaxes and matching rules not provided by the SDK to the provided schema
   * builder.
   *
   * @param schemaBuilder
   *            The schema builder
   * @throws ConfigException
   *            If there is a schema conflict for the added elements
   */
  public static void addServerSyntaxesAndMatchingRules(final SchemaBuilder schemaBuilder) throws ConfigException
  {
    try
    {
      addAciSyntax(schemaBuilder);
      addSubtreeSpecificationSyntax(schemaBuilder);
      addHistoricalCsnOrderingMatchingRule(schemaBuilder);
      addAuthPasswordEqualityMatchingRule(schemaBuilder);
      addUserPasswordEqualityMatchingRule(schemaBuilder);
    }
    catch (ConflictingSchemaElementException e)
    {
      throw new ConfigException(e.getMessageObject(), e);
    }
  }
  private static void addAciSyntax(SchemaBuilder builder)
  {
    builder
      .buildSyntax(SYNTAX_ACI_OID)
      .description(SYNTAX_ACI_DESCRIPTION)
      .implementation(new AciSyntaxImpl())
      .addToSchema();
  }
  private static void addSubtreeSpecificationSyntax(SchemaBuilder builder)
  {
    builder
      .buildSyntax(SYNTAX_SUBTREE_SPECIFICATION_OID)
      .description(SYNTAX_SUBTREE_SPECIFICATION_DESCRIPTION)
      .implementation(new SubtreeSpecificationSyntaxImpl())
      .addToSchema();
  }
  private static void addHistoricalCsnOrderingMatchingRule(SchemaBuilder builder)
  {
    builder
      .buildMatchingRule("1.3.6.1.4.1.26027.1.4.4")
      .names("historicalCsnOrderingMatch")
      .syntaxOID("1.3.6.1.4.1.1466.115.121.1.40")
      .implementation(new HistoricalCsnOrderingMatchingRuleImpl())
      .addToSchema();
  }
  private static void addAuthPasswordEqualityMatchingRule(SchemaBuilder builder)
  {
    builder.buildMatchingRule(EMR_AUTH_PASSWORD_OID)
      .names(EMR_AUTH_PASSWORD_NAME)
      .syntaxOID(SYNTAX_AUTH_PASSWORD_OID).description(EMR_AUTH_PASSWORD_DESCRIPTION)
      .implementation(new AuthPasswordEqualityMatchingRule())
      .addToSchema();
  }
  private static void addUserPasswordEqualityMatchingRule(SchemaBuilder builder)
  {
    builder.buildMatchingRule(EMR_USER_PASSWORD_OID)
      .names(EMR_USER_PASSWORD_NAME)
      .syntaxOID(SYNTAX_OCTET_STRING_OID).description(EMR_USER_PASSWORD_DESCRIPTION)
      .implementation(new UserPasswordEqualityMatchingRule())
      .addToSchema();
  }
  /**
   * Detects offline schema changes by comparing schema files and concatenated schema.
   * <p>
   * Updates the concatenated schema if changes are detected.
@@ -751,7 +805,7 @@
   *           If a problem occurs while initializing the schema elements that
   *           is not related to the server configuration.
   */
  private void completeSchemaFromFiles(final SchemaBuilder schemaBuilder)
  private void loadSchemaFromFiles(final SchemaBuilder schemaBuilder)
      throws ConfigException, InitializationException
  {
    final File schemaDirectory = getSchemaDirectoryPath();