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

Jean-Noël Rouvignac
28.37.2016 8ad8be4bf3a16f43d860606454ee382dd8502819
OPENDJ-2932 Example plugin is incomplete
1 files deleted
1 files added
6 files modified
222 ■■■■■ changed files
opendj-server-example-plugin/README 47 ●●●●● patch | view | raw | blame | history
opendj-server-example-plugin/README.example.plugin 38 ●●●●● patch | view | raw | blame | history
opendj-server-example-plugin/pom.xml 18 ●●●●● patch | view | raw | blame | history
opendj-server-example-plugin/src/main/assembly/config/example-plugin.ldif 2 ●●● patch | view | raw | blame | history
opendj-server-example-plugin/src/main/assembly/descriptor.xml 18 ●●●● patch | view | raw | blame | history
opendj-server-example-plugin/src/main/java/com/example/opendj/ExamplePlugin.java 83 ●●●● patch | view | raw | blame | history
opendj-server-example-plugin/src/main/java/com/example/opendj/example_plugin.properties 8 ●●●● patch | view | raw | blame | history
opendj-server-example-plugin/src/main/java/com/example/opendj/example_plugin_fr.properties 8 ●●●● patch | view | raw | blame | history
opendj-server-example-plugin/README
File was deleted
opendj-server-example-plugin/README.example.plugin
New file
@@ -0,0 +1,38 @@
This folder contains source code for an example "Hello World" style
plugin. It features a plugin which has a configurable message (the
default being "Hello World") which is displayed as a notice message
when OpenDJ directory server is started.
In order to build and use this example plugin, perform the following
steps while the server is stopped:
  1. Then unzip the example-plugin.zip (in place):
     unzip example-plugin.zip
  2. Go into the example-plugin source folder:
     cd example-plugin
  3. And build the plugin (this requires Maven version 3):
     mvn clean install
  4. This will copy the following files into the parent OpenDJ installation:
     lib/extensions/example-plugin.jar
     config/example-plugin.ldif
     config/schema/99-example-plugin.ldif
  5. Add the plugin's config to the server configuration.
     cd ../bin
     ./start-ds
     ./dsconfig -h `hostname` -p 4444 -D "cn=Directory Manager" -w password
      create-plugin --plugin-name "Example Plugin" --type example
      --set enabled:true --set plugin-type:startup -X -n
  6. Restart the server and look for the "HELLO WORLD" notice in the start
     up log:
     ./stop-ds --restart
opendj-server-example-plugin/pom.xml
@@ -30,19 +30,15 @@
  <dependencies>
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-core</artifactId>
      <artifactId>opendj-server-legacy</artifactId>
      <version>${project.version}</version>
    </dependency>
    <!-- This adds an external dependency for the plugin.
         Also update src/main/assembly/descriptor.xml file to include the dependency -->
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-config</artifactId>
    </dependency>
    <dependency>
      <groupId>org.forgerock.commons</groupId>
      <artifactId>i18n-slf4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.3.2</version>
    </dependency>
  </dependencies>
  <build>
opendj-server-example-plugin/src/main/assembly/config/example-plugin.ldif
@@ -4,7 +4,7 @@
objectClass: ds-cfg-example-plugin
cn: Example Plugin
ds-cfg-enabled: true
ds-cfg-java-class: com.example.opends.ExamplePlugin
ds-cfg-java-class: com.example.opendj.ExamplePlugin
ds-cfg-plugin-type: startup
ds-cfg-example-plugin-message: Hello World
opendj-server-example-plugin/src/main/assembly/descriptor.xml
@@ -12,7 +12,7 @@
  Header, with the fields enclosed by brackets [] replaced by your own identifying
  information: "Portions Copyright [year] [name of copyright owner]".
  Copyright 2014 ForgeRock AS.
  Copyright 2014-2016 ForgeRock AS.
 -->
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -29,7 +29,7 @@
      <directoryMode>755</directoryMode>
      <fileMode>644</fileMode>
      <includes>
        <include>README</include>
        <include>README.example.plugin</include>
        <include>LICENSE</include>
        <include>NOTICE</include>
      </includes>
@@ -62,6 +62,20 @@
      <includes>
        <include>*.jar</include>
      </includes>
      <excludes>
        <exclude>*-sources.jar</exclude>
      </excludes>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib/extensions</outputDirectory>
      <includes>
        <include>org.apache.commons:commons-lang3</include>
      </includes>
      <useStrictFiltering>true</useStrictFiltering>
      <useProjectArtifact>true</useProjectArtifact>
      <useTransitiveDependencies>true</useTransitiveDependencies>
    </dependencySet>
  </dependencySets>
</assembly>
opendj-server-example-plugin/src/main/java/com/example/opendj/ExamplePlugin.java
@@ -12,49 +12,94 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions copyright 2014-2015 ForgeRock AS.
 * Portions copyright 2014-2016 ForgeRock AS.
 */
package com.example.opendj;
import java.util.List;
import static com.example.opendj.ExamplePluginMessages.*;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.forgerock.i18n.LocalizableMessage;
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.opends.server.api.plugin.DirectoryServerPlugin;
import org.opends.server.api.plugin.PluginResult;
import org.opends.server.api.plugin.PluginType;
import org.opends.server.types.InitializationException;
import com.example.opendj.server.ExamplePluginCfg;
/**
 * The example plugin implementation class. This plugin will output the
 * configured message to the error log during server start up.
 * The example plugin implementation class. This plugin will output the configured message to the
 * error log during server start up.
 */
public class ExamplePlugin implements ConfigurationChangeListener<ExamplePluginCfg> {
    // FIXME: fill in the remainder of this class once the server plugin API is migrated.
public class ExamplePlugin extends DirectoryServerPlugin<ExamplePluginCfg>
                           implements ConfigurationChangeListener<ExamplePluginCfg> {
    private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
    /**
     * Default constructor.
     */
    /** The current configuration. */
    private ExamplePluginCfg config;
    /** Default constructor. */
    public ExamplePlugin() {
        // No implementation required.
        super();
    }
    /** {@inheritDoc} */
    @Override
    public ConfigChangeResult applyConfigurationChange(final ExamplePluginCfg config) {
    public void initializePlugin(Set<PluginType> pluginTypes, ExamplePluginCfg configuration)
            throws ConfigException, InitializationException {
        // This plugin may only be used as a server startup plugin.
        for (PluginType t : pluginTypes) {
            switch (t) {
            case STARTUP:
                // This is fine.
                break;
            default:
                throw new ConfigException(ERR_INITIALIZE_PLUGIN.get(String.valueOf(t)));
            }
        }
        // Register change listeners. These are not really necessary for this plugin
        // since it is only used during server start-up.
        configuration.addExampleChangeListener(this);
        // Save the configuration.
        this.config = configuration;
    }
    @Override
    public PluginResult.Startup doStartup() {
        // Log the provided message.
        logger.info(NOTE_DO_STARTUP, StringUtils.upperCase(config.getMessage()));
        return PluginResult.Startup.continueStartup();
    }
    @Override
    public ConfigChangeResult applyConfigurationChange(ExamplePluginCfg config) {
        // The new configuration has already been validated.
        // Log a message to say that the configuration has changed.
        // This is not necessary, but we'll do it just to show that the change
        // has taken effect.
        logger.info(NOTE_APPLY_CONFIGURATION_CHANGE, this.config.getMessage(), config.getMessage());
        // Update the configuration.
        this.config = config;
        // Update was successful, no restart required.
        return new ConfigChangeResult();
    }
    /** {@inheritDoc} */
    @Override
    public boolean isConfigurationChangeAcceptable(final ExamplePluginCfg config,
            final List<LocalizableMessage> messages) {
        /*
         * The only thing that can be validated here is the plugin's message.
         * However, it is always going to be valid, so let's always return true.
         */
    public boolean isConfigurationChangeAcceptable(ExamplePluginCfg config, List<LocalizableMessage> messages) {
        // The only thing that can be validated here is the plugin's message.
        // However, it is always going to be valid, so let's always return true.
        return true;
    }
}
opendj-server-example-plugin/src/main/java/com/example/opendj/example_plugin.properties
@@ -11,8 +11,8 @@
# information: "Portions Copyright [year] [name of copyright owner]".
#
# Copyright 2006-2008 Sun Microsystems, Inc.
# Portions copyright 2014 ForgeRock AS.
SEVERE_ERR_INITIALIZE_PLUGIN_1="Invalid plugin type %s for the example plugin.
NOTICE_DO_STARTUP_2=Example plugin message '%s'.
NOTICE_APPLY_CONFIGURATION_CHANGE_3="Example plugin message has been changed \
# Portions copyright 2014-2016 ForgeRock AS.
ERR_INITIALIZE_PLUGIN_1="Invalid plugin type %s for the example plugin.
NOTE_DO_STARTUP_2=Example plugin message '%s'.
NOTE_APPLY_CONFIGURATION_CHANGE_3="Example plugin message has been changed \
from '%s' to '%s'.
opendj-server-example-plugin/src/main/java/com/example/opendj/example_plugin_fr.properties
@@ -11,8 +11,8 @@
# information: "Portions Copyright [year] [name of copyright owner]".
#
# Copyright 2006-2008 Sun Microsystems, Inc.
# Portions copyright 2014 ForgeRock AS.
SEVERE_ERR_INITIALIZE_PLUGIN_1="Type de plugin invalide %s pour le plugin d'exemple.
NOTICE_DO_STARTUP_2=Message du plugin d'exemple '%s'.
NOTICE_APPLY_CONFIGURATION_CHANGE_3="Le message du plugin d'exemple a été modifié \
# Portions copyright 2014-2016 ForgeRock AS.
ERR_INITIALIZE_PLUGIN_1="Type de plugin invalide %s pour le plugin d'exemple.
NOTE_DO_STARTUP_2=Message du plugin d'exemple '%s'.
NOTE_APPLY_CONFIGURATION_CHANGE_3="Le message du plugin d'exemple a été modifié \
de '%s' en '%s'.