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

Nicolas Capponi
16.32.2016 afe88363f70903f207a25edab27e7adcb9fc66e0
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -493,7 +493,7 @@
      }
      final String oid = ocToDelete.getOID();
      final Schema schema = getInfo().getServerDescriptor().getSchema();
      return new SchemaBuilder(schema.getSchemaNG()).buildObjectClass(oid)
      return new SchemaBuilder(schema).buildObjectClass(oid)
          .names(ocToDelete.getNames())
          .description(ocToDelete.getDescription())
          .superiorObjectClasses(getNameOrOIDsForOCs(newSuperiors))
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java
@@ -183,7 +183,7 @@
      Schema schema = getInfo().getServerDescriptor().getSchema();
      String oid = ocToDelete.getOID();
      return new SchemaBuilder(schema.getSchemaNG()).buildObjectClass(oid)
      return new SchemaBuilder(schema).buildObjectClass(oid)
          .names(ocToDelete.getNames())
          .description(ocToDelete.getDescription())
          .superiorObjectClasses(getNameOrOIDsForOCs(ocToDelete.getSuperiorClasses()))
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyObjectClassTask.java
@@ -163,7 +163,7 @@
      }
      final String oid = ocToDelete.getOID();
      final Schema schema = getInfo().getServerDescriptor().getSchema();
      return new SchemaBuilder(schema.getSchemaNG()).buildObjectClass(oid)
      return new SchemaBuilder(schema).buildObjectClass(oid)
          .names(ocToDelete.getNames())
          .description(ocToDelete.getDescription())
          .superiorObjectClasses(getNameOrOIDsForOCs(newSups))
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomObjectClassPanel.java
@@ -964,7 +964,7 @@
  private ObjectClass getNewObjectClass()
  {
    return new SchemaBuilder(schema.getSchemaNG()).buildObjectClass(getOID())
    return new SchemaBuilder(schema).buildObjectClass(getOID())
        .names(getAllNames())
        .description(getDescription())
        .superiorObjectClasses(getNameOrOIDsForOCs(getObjectClassSuperiors()))
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewAttributePanel.java
@@ -683,7 +683,7 @@
  {
    AttributeType superior = getSuperior();
    Syntax selectedSyntax = (Syntax) syntax.getSelectedItem();
    return new SchemaBuilder(schema.getSchemaNG()).buildAttributeType(getOID())
    return new SchemaBuilder(schema).buildAttributeType(getOID())
      .names(getAllNames())
      .description(getDescription())
      .superiorType(superior != null ? superior.getNameOrOID() : null)
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewObjectClassPanel.java
@@ -680,7 +680,7 @@
  private ObjectClass getObjectClass()
  {
    return new SchemaBuilder(schema.getSchemaNG()).buildObjectClass(getOID())
    return new SchemaBuilder(schema).buildObjectClass(getOID())
        .names(getAllNames())
        .description(getDescription())
        .superiorObjectClasses(getNameOrOIDsForOCs(getObjectClassSuperiors()))
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
@@ -1428,7 +1428,7 @@
                Object o = comps.iterator().next().getValue();
                if (o instanceof String)
                {
                  AttributeDescription attrDesc = AttributeDescription.valueOf(attrName, schema.getSchemaNG());
                  AttributeDescription attrDesc = AttributeDescription.valueOf(attrName, schema);
                  AttributeType attrType = attrDesc.getAttributeType();
                  if (!attrType.isPlaceHolder())
                  {
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
@@ -311,7 +311,7 @@
              Object o = table.getValueAt(i, 1);
              if (o instanceof String)
              {
                AttributeDescription attrDesc = AttributeDescription.valueOf(attrName, schema.getSchemaNG());
                AttributeDescription attrDesc = AttributeDescription.valueOf(attrName, schema);
                AttributeType attrType = attrDesc.getAttributeType();
                if (!attrType.isPlaceHolder())
                {
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -2030,7 +2030,7 @@
    // Check all the attributes that we consider binaries.
    if (schema != null)
    {
      AttributeType attrType = AttributeDescription.valueOf(attrName, schema.getSchemaNG()).getAttributeType();
      AttributeType attrType = AttributeDescription.valueOf(attrName, schema).getAttributeType();
      if (!attrType.isPlaceHolder())
      {
        String syntaxOID = attrType.getSyntax().getOID();
@@ -2064,7 +2064,7 @@
  {
    if (schema != null)
    {
      AttributeType attrType = AttributeDescription.valueOf(attrName, schema.getSchemaNG()).getAttributeType();
      AttributeType attrType = AttributeDescription.valueOf(attrName, schema).getAttributeType();
      if (!attrType.isPlaceHolder())
      {
        PasswordType passwordType = SchemaUtils.checkPasswordType(attrType);
@@ -2078,7 +2078,7 @@
  {
    if (schema != null)
    {
      AttributeType attrType = AttributeDescription.valueOf(attrName, schema.getSchemaNG()).getAttributeType();
      AttributeType attrType = AttributeDescription.valueOf(attrName, schema).getAttributeType();
      if (!attrType.isPlaceHolder())
      {
        return oids.contains(attrType.getSyntax().getOID());
opendj-server-legacy/src/main/java/org/opends/server/backends/NullBackend.java
@@ -18,7 +18,6 @@
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.messages.BackendMessages.*;
import static org.opends.server.util.SchemaUtils.getElementSchemaFile;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -36,6 +35,7 @@
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.server.config.server.BackendCfg;
import org.opends.server.api.Backend;
import org.opends.server.controls.PagedResultsControl;
@@ -44,6 +44,7 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.core.SearchOperation;
import org.opends.server.core.ServerContext;
import org.opends.server.types.BackupConfig;
@@ -103,6 +104,9 @@
  /** The map of null entry object classes. */
  private Map<ObjectClass,String> objectClasses;
  /** The server context. */
  private ServerContext serverContext;
  /**
   * Creates a new backend with the provided information.  All backend
   * implementations must implement a default constructor that use
@@ -118,6 +122,7 @@
  @Override
  public void configureBackend(BackendCfg config, ServerContext serverContext) throws ConfigException
  {
    this.serverContext = serverContext;
    if (config != null)
    {
      this.baseDNs = config.getBaseDN();
@@ -148,9 +153,16 @@
    objectClasses.put(getExtensibleObjectObjectClass(), "extensibleobject");
    String nulOCName = "nullbackendobject";
    ObjectClass nulOC = DirectoryServer.getSchema().getObjectClass(nulOCName);
    final ObjectClass nulOC = serverContext.getSchema().getObjectClass(nulOCName);
    try {
      DirectoryServer.getSchema().registerObjectClass(nulOC, getElementSchemaFile(nulOC), false);
      serverContext.getSchemaHandler().updateSchema(new SchemaUpdater()
      {
        @Override
        public void update(SchemaBuilder builder) throws DirectoryException
        {
          builder.buildObjectClass(nulOC);
        }
      });
    } catch (DirectoryException de) {
      logger.traceException(de);
      throw new InitializationException(de.getMessageObject());
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -16,6 +16,8 @@
 */
package org.opends.server.backends;
import static org.forgerock.opendj.ldap.schema.SchemaOptions.STRIP_UPPER_BOUND_FOR_ATTRIBUTE_TYPE;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.forgerock.util.Reject.*;
import static org.opends.messages.BackendMessages.*;
@@ -33,7 +35,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -80,7 +81,6 @@
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.SearchOperation;
import org.opends.server.core.ServerContext;
import org.opends.server.schema.AttributeTypeSyntax;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Attributes;
@@ -375,7 +375,7 @@
    Schema schema = schemaHandler.getSchema();
    buildSchemaAttribute(schema.getAttributeTypes(), userAttrs,
        operationalAttrs, attributeTypesType, includeSchemaFile,
        AttributeTypeSyntax.isStripSyntaxMinimumUpperBound(),
        schema.getOption(STRIP_UPPER_BOUND_FOR_ATTRIBUTE_TYPE),
        ignoreShowAllOption);
    buildSchemaAttribute(schema.getObjectClasses(), userAttrs,
        operationalAttrs, objectClassesType, includeSchemaFile, false,
opendj-server-legacy/src/main/java/org/opends/server/core/CoreConfigManager.java
@@ -146,7 +146,7 @@
    try
    {
      final boolean allowMalformedNames = globalConfig.isAllowAttributeNameExceptions();
      serverContext.getSchema().updateSchemaOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS, allowMalformedNames);
      serverContext.getSchemaHandler().updateSchemaOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS, allowMalformedNames);
    }
    catch (DirectoryException e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/GoverningStructureRuleVirtualAttributeProvider.java
@@ -179,7 +179,7 @@
      return null;
    }
    Schema schema = DirectoryServer.getSchema();
    Collection<NameForm> listForms = schema.getNameForm(oc);
    Collection<NameForm> listForms = schema.getNameForms(oc);
    NameForm nameForm = null;
    DITStructureRule ditRule = null;
    //We iterate over all the nameforms while creating the entry and
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -1641,7 +1641,7 @@
         * DITStructureRules corresponding to other non-acceptable
         * nameforms are not applied.
         */
        Collection<NameForm> forms = DirectoryServer.getSchema().getNameForm(structuralClass);
        Collection<NameForm> forms = DirectoryServer.getSchema().getNameForms(structuralClass);
        if (forms != null)
        {
          List<NameForm> listForms = new ArrayList<>(forms);
@@ -2186,7 +2186,7 @@
        }
        else
        {
          Collection<NameForm> allNFs = DirectoryServer.getSchema().getNameForm(parentStructuralClass);
          Collection<NameForm> allNFs = DirectoryServer.getSchema().getNameForms(parentStructuralClass);
          if(allNFs != null)
          {
            for(NameForm parentNF : allNFs)
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
@@ -238,7 +238,7 @@
  public static void startFakeServer() throws Exception
  {
    schemaBeforeStartingFakeServer = DirectoryServer.getSchema();
    DirectoryServer.setSchema(new Schema(org.forgerock.opendj.ldap.schema.Schema.getDefaultSchema()));
    DirectoryServer.setSchema(Schema.getDefaultSchema());
  }
  /**
@@ -747,9 +747,11 @@
  /**
   * Undo all the setup done by #startFakeServer().
   *
   * @throws DirectoryException
   *            If the initial schema contains warning
   * @see #startFakeServer() Matching method that starts the fake server
   */
  public static void shutdownFakeServer()
  public static void shutdownFakeServer() throws DirectoryException
  {
    DirectoryServer.setSchema(schemaBeforeStartingFakeServer);
  }
opendj-server-legacy/src/test/java/org/opends/server/api/MonitorDataTestCase.java
@@ -33,6 +33,7 @@
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.TestCaseUtils;
import org.opends.server.types.Attribute;
import org.opends.server.types.DirectoryException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -48,7 +49,7 @@
  }
  @AfterClass
  public void tearDown()
  public void tearDown() throws DirectoryException
  {
    TestCaseUtils.shutdownFakeServer();
  }
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciBodyTest.java
@@ -17,6 +17,7 @@
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.TestCaseUtils;
import org.opends.server.types.DirectoryException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@@ -35,7 +36,7 @@
  }
  @AfterClass
  public void tearDown()
  public void tearDown() throws DirectoryException
  {
    TestCaseUtils.shutdownFakeServer();
  }
opendj-server-legacy/src/test/java/org/opends/server/plugins/EntryUUIDPluginTestCase.java
@@ -27,11 +27,15 @@
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.CoreSchema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.server.config.meta.EntryUUIDPluginCfgDefn;
import org.opends.server.TestCaseUtils;
import org.opends.server.api.plugin.PluginType;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.extensions.InitializationUtils;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDIFImportConfig;
@@ -58,7 +62,10 @@
    TestCaseUtils.startServer();
  }
  private SchemaHandler getSchemaHandler()
  {
    return DirectoryServer.getInstance().getServerContext().getSchemaHandler();
  }
  /**
   * Retrieves a set of valid configuration entries that may be used to
@@ -139,17 +146,39 @@
  public void testInitializeWithValidConfigsWithoutSchema(Entry e)
         throws Exception
  {
    AttributeType entryUUIDType = CoreSchema.getEntryUUIDAttributeType();
    DirectoryServer.getSchema().deregisterAttributeType(entryUUIDType);
    final AttributeType entryUUIDType = CoreSchema.getEntryUUIDAttributeType();
    removeAttributeType(entryUUIDType);
    EntryUUIDPlugin plugin = initializePlugin(e);
    plugin.finalizePlugin();
    DirectoryServer.getSchema().registerAttributeType(entryUUIDType, null, false);
    addAttributeType(entryUUIDType);
  }
  private void addAttributeType(final AttributeType at) throws DirectoryException
  {
    getSchemaHandler().updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        builder.buildAttributeType(at).addToSchema();
      }
    });
  }
  private void removeAttributeType(final AttributeType at) throws DirectoryException
  {
    getSchemaHandler().updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        builder.removeAttributeType(at.getOID());
      }
    });
  }
  /**
   * Retrieves a set of invalid configuration entries.
opendj-server-legacy/src/test/java/org/opends/server/plugins/LastModPluginTestCase.java
@@ -30,16 +30,20 @@
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.server.config.meta.LastModPluginCfgDefn;
import org.opends.server.TestCaseUtils;
import org.opends.server.api.plugin.PluginType;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.extensions.InitializationUtils;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryConfig;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
@@ -66,7 +70,40 @@
    TestCaseUtils.startServer();
  }
  private SchemaHandler getSchemaHandler()
  {
    return DirectoryServer.getInstance().getServerContext().getSchemaHandler();
  }
  private void registerAttributeTypes(final AttributeType...types) throws Exception
  {
    getSchemaHandler().updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        for (AttributeType at : types)
        {
          builder.buildAttributeType(at).addToSchema();
        }
      }
    });
  }
  private void deregisterAttributeTypes(final AttributeType...types) throws Exception
  {
    getSchemaHandler().updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        for (AttributeType at : types)
        {
          builder.removeAttributeType(at.getOID());
        }
      }
    });
  }
  /**
   * Retrieves a set of valid configuration entries that may be used to
@@ -164,24 +201,14 @@
    AttributeType mtType = getModifyTimestampAttributeType();
    AttributeType mnType = getModifiersNameAttributeType();
    DirectoryServer.getSchema().deregisterAttributeType(ctType);
    DirectoryServer.getSchema().deregisterAttributeType(cnType);
    DirectoryServer.getSchema().deregisterAttributeType(mtType);
    DirectoryServer.getSchema().deregisterAttributeType(mnType);
    deregisterAttributeTypes(ctType, cnType, mtType, mnType);
    LastModPlugin plugin = initializePlugin(e);
    plugin.finalizePlugin();
    DirectoryServer.getSchema().registerAttributeType(ctType, null, false);
    DirectoryServer.getSchema().registerAttributeType(cnType, null, false);
    DirectoryServer.getSchema().registerAttributeType(mtType, null, false);
    DirectoryServer.getSchema().registerAttributeType(mnType, null, false);
    registerAttributeTypes(ctType, cnType, mtType, mnType);
  }
  /**
   * Retrieves a set of invalid configuration entries.
   *
opendj-server-legacy/src/test/java/org/opends/server/schema/GenericSchemaTestCase.java
@@ -29,8 +29,6 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.MatchingRule;
import org.forgerock.opendj.ldap.schema.NameForm;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
@@ -39,6 +37,7 @@
import org.opends.server.types.LDIFImportConfig;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.SchemaUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -111,10 +110,10 @@
      {
        for (ByteString v : a)
        {
          AttributeType at = DirectoryServer.getSchema().parseAttributeType(v.toString());
          if (! isNumericOID(at.getOID()))
          String oid = SchemaUtils.parseAttributeTypeOID(v.toString());
          if (! isNumericOID(oid))
          {
            invalidOIDs.add(at.getNameOrOID());
            invalidOIDs.add(oid);
          }
        }
      }
@@ -141,10 +140,10 @@
      {
        for (ByteString v : a)
        {
          ObjectClass oc = DirectoryServer.getSchema().parseObjectClass(v.toString());
          if (! isNumericOID(oc.getOID()))
          String oid = SchemaUtils.parseObjectClassOID(v.toString());
          if (! isNumericOID(oid))
          {
            invalidOIDs.add(oc.getNameOrOID());
            invalidOIDs.add(oid);
          }
        }
      }
@@ -170,10 +169,10 @@
      {
        for (ByteString v : a)
        {
          NameForm nf = DirectoryServer.getSchema().parseNameForm(v.toString());
          if (! isNumericOID(nf.getOID()))
          String oid = SchemaUtils.parseNameFormOID(v.toString());
          if (! isNumericOID(oid))
          {
            invalidOIDs.add(nf.getNameOrOID());
            invalidOIDs.add(oid);
          }
        }
      }
opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java
@@ -38,8 +38,10 @@
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.CoreSchema;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SchemaHandler;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -208,7 +210,9 @@
    String string = "( 2.5.18.6 NAME 'subtreeSpecification' "
        + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.45 )";
    AttributeType type = DirectoryServer.getSchema().parseAttributeType(string);
    SchemaHandler schemaHandler = DirectoryServer.getInstance().getServerContext().getSchemaHandler();
    SchemaBuilder builder = new SchemaBuilder(schemaHandler.getSchema());
    AttributeType type = builder.addAttributeType(string, false).toSchema().getAttributeType("2.5.18.6");
    // Test values.
    String[] values = new String[] { "{ }",