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

Jean-Noël Rouvignac
07.03.2016 3d4c0acccda6e62b23f248d75c1cc6721fc20bdf
opendj-server-legacy/src/main/java/org/opends/server/plugins/LastModPlugin.java
@@ -16,6 +16,11 @@
 */
package org.opends.server.plugins;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.messages.PluginMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.TimeThread.*;
import java.util.List;
import java.util.Set;
@@ -23,18 +28,16 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.server.config.meta.PluginCfgDefn;
import org.forgerock.opendj.server.config.server.LastModPluginCfg;
import org.forgerock.opendj.server.config.server.PluginCfg;
import org.opends.server.api.plugin.DirectoryServerPlugin;
import org.opends.server.api.plugin.PluginResult;
import org.opends.server.api.plugin.PluginType;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Attributes;
@@ -45,10 +48,6 @@
import org.opends.server.types.operation.PreOperationModifyDNOperation;
import org.opends.server.types.operation.PreOperationModifyOperation;
import static org.opends.messages.PluginMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.TimeThread.*;
/**
 * This class implements a Directory Server plugin that will add the
 * creatorsName and createTimestamp attributes to an entry whenever it is added
@@ -61,14 +60,6 @@
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** The attribute type for the "createTimestamp" attribute. */
  private final AttributeType createTimestampType;
  /** The attribute type for the "creatorsName" attribute. */
  private final AttributeType creatorsNameType;
  /** The attribute type for the "modifiersName" attribute. */
  private final AttributeType modifiersNameType;
  /** The attribute type for the "modifyTimestamp" attribute. */
  private final AttributeType modifyTimestampType;
  /** The current configuration for this plugin. */
  private LastModPluginCfg currentConfig;
@@ -82,14 +73,6 @@
  public LastModPlugin()
  {
    super();
    // Get the attribute types for the attributes that we will use.  This needs
    // to be done in the constructor in order to make the associated variables "final".
    createTimestampType = DirectoryServer.getAttributeType(OP_ATTR_CREATE_TIMESTAMP_LC);
    creatorsNameType = DirectoryServer.getAttributeType(OP_ATTR_CREATORS_NAME_LC);
    modifiersNameType = DirectoryServer.getAttributeType(OP_ATTR_MODIFIERS_NAME_LC);
    modifyTimestampType = DirectoryServer.getAttributeType(OP_ATTR_MODIFY_TIMESTAMP_LC);
  }
@@ -134,7 +117,7 @@
               doPreOperation(PreOperationAddOperation addOperation)
  {
    // Create the attribute list for the creatorsName attribute, if appropriate.
    AttributeBuilder builder = new AttributeBuilder(creatorsNameType);
    AttributeBuilder builder = new AttributeBuilder(getCreatorsNameAttributeType());
    DN creatorDN = addOperation.getAuthorizationDN();
    if (creatorDN == null)
    {
@@ -146,13 +129,13 @@
    {
      builder.add(creatorDN.toString());
    }
    addOperation.setAttribute(creatorsNameType, builder.toAttributeList());
    addOperation.setAttribute(getCreatorsNameAttributeType(), builder.toAttributeList());
    //  Create the attribute list for the createTimestamp attribute.
    List<Attribute> timeList = Attributes.createAsList(
        createTimestampType, OP_ATTR_CREATE_TIMESTAMP, getGMTTime());
    addOperation.setAttribute(createTimestampType, timeList);
        getCreateTimestampAttributeType(), OP_ATTR_CREATE_TIMESTAMP, getGMTTime());
    addOperation.setAttribute(getCreateTimestampAttributeType(), timeList);
    // We shouldn't ever need to return a non-success result.
    return PluginResult.PreOperation.continueOperationProcessing();
@@ -165,7 +148,7 @@
       doPreOperation(PreOperationModifyOperation modifyOperation)
  {
    // Create the modifiersName attribute.
    AttributeBuilder builder = new AttributeBuilder(modifiersNameType);
    AttributeBuilder builder = new AttributeBuilder(getModifiersNameAttributeType());
    DN modifierDN = modifyOperation.getAuthorizationDN();
    if (modifierDN == null)
    {
@@ -194,7 +177,7 @@
    //  Create the modifyTimestamp attribute.
    Attribute timeAttr = Attributes.create(modifyTimestampType,
    Attribute timeAttr = Attributes.create(getModifyTimestampAttributeType(),
        OP_ATTR_MODIFY_TIMESTAMP, getGMTTime());
    try
    {
@@ -222,7 +205,7 @@
       doPreOperation(PreOperationModifyDNOperation modifyDNOperation)
  {
    // Create the modifiersName attribute.
    AttributeBuilder builder = new AttributeBuilder(modifiersNameType);
    AttributeBuilder builder = new AttributeBuilder(getModifiersNameAttributeType());
    DN modifierDN = modifyDNOperation.getAuthorizationDN();
    if (modifierDN == null)
    {
@@ -240,7 +223,7 @@
    // Create the modifyTimestamp attribute.
    Attribute timeAttr = Attributes.create(modifyTimestampType,
    Attribute timeAttr = Attributes.create(getModifyTimestampAttributeType(),
        OP_ATTR_MODIFY_TIMESTAMP, getGMTTime());
    modifyDNOperation.addModification(new Modification(
        ModificationType.REPLACE, timeAttr, true));