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

Matthew Swift
13.17.2013 2f3c74dbc436b2e2c8f2c29159d29df44149aa02
Fix OPENDJ-1223: Copy DataProvider PoC from branch to OpenDJ 3 trunk
22 files added
2149 ■■■■■ changed files
opendj-server3/pom.xml 137 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/AbstractDataProvider.java 138 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/ArchivableDataProvider.java 100 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/Attachment.java 109 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/AttachmentHolder.java 80 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/BackupConfig.java 33 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/BindRequestContext.java 55 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProvider.java 250 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderCfg.java 33 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderConnection.java 159 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderEvent.java 129 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderEventListener.java 62 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderFactory.java 91 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderID.java 154 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderStatus.java 79 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/ExportableDataProvider.java 61 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/ImportableDataProvider.java 69 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/Operation.java 202 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/Privilege.java 33 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/RestoreConfig.java 33 ●●●●● patch | view | raw | blame | history
opendj-server3/src/main/java/org/forgerock/opendj/server/core/package-info.java 34 ●●●●● patch | view | raw | blame | history
opendj-server3/src/site/xdoc/index.xml.vm 108 ●●●●● patch | view | raw | blame | history
opendj-server3/pom.xml
New file
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ! CDDL HEADER START
  !
  ! The contents of this file are subject to the terms of the
  ! Common Development and Distribution License, Version 1.0 only
  ! (the "License").  You may not use this file except in compliance
  ! with the License.
  !
  ! You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
  ! or http://forgerock.org/license/CDDLv1.0.html.
  ! See the License for the specific language governing permissions
  ! and limitations under the License.
  !
  ! When distributing Covered Code, include this CDDL HEADER in each
  ! file and include the License file at legal-notices/CDDLv1_0.txt.
  ! If applicable, add the following below this CDDL HEADER, with the
  ! fields enclosed by brackets "[]" replaced with your own identifying
  ! information:
  !      Portions Copyright [yyyy] [name of copyright owner]
  !
  ! CDDL HEADER END
  !
  !      Copyright 2013 ForgeRock AS
  !
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>opendj-project</artifactId>
    <groupId>org.forgerock.opendj</groupId>
    <version>3.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>opendj-server3</artifactId>
  <name>OpenDJ LDAP Directory Server</name>
  <description>
    This module includes the core functionality of the OpenDJ LDAP Directory Server.
  </description>
  <packaging>jar</packaging>
  <dependencies>
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-grizzly</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-admin</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.forgerock.commons</groupId>
      <artifactId>forgerock-util</artifactId>
      <version>1.2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.forgerock.commons</groupId>
      <artifactId>i18n-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-core</artifactId>
      <type>test-jar</type>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.forgerock</groupId>
      <artifactId>forgerock-build-tools</artifactId>
      <version>${forgerockBuildToolsVersion}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.forgerock.commons</groupId>
        <artifactId>i18n-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-messages</goal>
            </goals>
            <configuration>
              <messageFiles>
                <!-- <messageFile>com/forgerock/opendj/grizzly/grizzly.properties</messageFile> -->
              </messageFiles>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <reportSets>
          <reportSet>
            <reports>
              <report>dependencies</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <links>
            <link>http://commons.forgerock.org/i18n-framework/i18n-core/apidocs</link>
          </links>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>
opendj-server3/src/main/java/org/forgerock/opendj/server/core/AbstractDataProvider.java
New file
@@ -0,0 +1,138 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * This class provides a skeletal implementation of the {@link DataProvider}
 * interface, to minimize the effort required to implement this interface.
 */
public abstract class AbstractDataProvider implements DataProvider {
    private static final Logger debugLogger = LoggerFactory.getLogger(AbstractDataProvider.class);
    // The list of event listeners associated with this data provider.
    private final List<DataProviderEventListener> eventListeners =
            new CopyOnWriteArrayList<DataProviderEventListener>();
    /**
     * Creates a new abstract data provider.
     */
    protected AbstractDataProvider() {
        // No implementation required.
    }
    /**
     * {@inheritDoc}
     * <p>
     * The default implementation is to invoke {@code getEntry(dn)} and return
     * {@code true} if the entry was successfully retrieved.
     */
    @Override
    public boolean containsEntry(final DN dn) throws DirectoryException {
        return getEntry(dn) != null;
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public final void deregisterEventListener(final DataProviderEventListener listener) {
        eventListeners.remove(listener);
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public final void registerEventListener(final DataProviderEventListener listener) {
        eventListeners.add(listener);
    }
    /**
     * {@inheritDoc}
     * <p>
     * The default implementation is to return false for all base DNs indicating
     * that change notification is not supported.
     */
    @Override
    public boolean supportsChangeNotification(final DN baseDN) throws DirectoryException {
        return false;
    }
    /**
     * Notify all event listeners that this data provider has changed state due
     * to an operational error, configuration change, or an administrative
     * action.
     * <p>
     * This method can be used to forward events to parent data providers.
     *
     * @param event
     *            The data provider event.
     */
    protected final void notifyDataProviderEventOccurred(final DataProviderEvent event) {
        for (final DataProviderEventListener listener : eventListeners) {
            try {
                listener.handleDataProviderEvent(event);
            } catch (final Exception e) {
                debugLogger.trace("Unexpected error occurred while invoking listener", e);
            }
        }
    }
    /**
     * Notify all event listeners that this data provider has changed state due
     * to an operational error, configuration change, or an administrative
     * action.
     * <p>
     * This method is equivalent to the following code:
     *
     * <pre>
     * DataProviderEvent event = new DataProviderEvent(reason, types);
     * notifyDataProviderStateChanged(event);
     * </pre>
     *
     * @param reason
     *            A message describing this event.
     * @param types
     *            The types of event that have occurred in the data provider.
     */
    protected final void notifyDataProviderEventOccurred(final LocalizableMessage reason,
            final Set<DataProviderEvent.Type> types) {
        final DataProviderEvent event = new DataProviderEvent(reason, types);
        notifyDataProviderEventOccurred(event);
    }
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/ArchivableDataProvider.java
New file
@@ -0,0 +1,100 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2008 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import org.forgerock.opendj.ldap.FutureResult;
import org.forgerock.opendj.ldap.ResultHandler;
/**
 * A data provider which supports backup and restore functionality.
 * <p>
 * TODO: do we need supportsRestore?
 * <p>
 * TODO: do we need removeBackup?
 * <p>
 * TODO: is there any boiler plate code that abstracted in order to make
 * implementation simpler? E.g. initialization, crypto.
 * <p>
 * FIXME: the async APIs used below are a bad fit. We do not want to return an
 * ErrorResultException. We really need a more generic promises API.
 */
public interface ArchivableDataProvider {
    /**
     * Creates a backup of the contents of this data provider in a form that may
     * be restored at a later date if necessary. This method should only be
     * called if {@code supportsBackup} returns {@code true}.
     * <p>
     * Note that the server will not explicitly initialize this data provider
     * before calling this method.
     *
     * @param backupConfig
     *            The configuration to use when performing the backup.
     * @param handler
     *            A handler which will be notified when the backup completes.
     * @return A future representing the completion of the backup.
     */
    FutureResult<Void> createBackup(BackupConfig backupConfig, ResultHandler<Void> handler);
    /**
     * Returns the ID of this data provider.
     *
     * @return The ID of this data provider.
     */
    DataProviderID getDataProviderID();
    /**
     * Restores a backup of the contents of this data provider.
     * <p>
     * Note that the server will not explicitly initialize this data provider
     * before calling this method.
     *
     * @param restoreConfig
     *            The configuration to use when performing the restore.
     * @param handler
     *            A handler which will be notified when the restore completes.
     * @return A future representing the completion of the restore.
     */
    FutureResult<Void> restoreBackup(RestoreConfig restoreConfig, ResultHandler<Void> handler);
    /**
     * Indicates whether this data provider provides a mechanism to perform a
     * backup of its contents in a form that can be restored later, based on the
     * provided configuration.
     *
     * @param backupConfig
     *            The configuration of the backup for which to make the
     *            determination.
     * @param unsupportedReason
     *            A buffer to which a message can be appended explaining why the
     *            requested backup is not supported.
     * @return {@code true} if this data provider provides a mechanism for
     *         performing backups with the provided configuration, or
     *         {@code false} if not.
     */
    boolean supportsBackup(BackupConfig backupConfig, StringBuilder unsupportedReason);
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/Attachment.java
New file
@@ -0,0 +1,109 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2010 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * Class used to define dynamic typed attachments on {@link AttachmentHolder}
 * instances. Storing attachment values in {@link AttachmentHolder} has the
 * advantage of the <tt>Attachment</tt> value being typed when compared to Map
 * storage:
 *
 * @param <T>
 *            The type of attachment.
 */
public final class Attachment<T> {
    private final T defaultValue;
    private final String name;
    /**
     * Construct a new attachment with the specified name and default value.
     *
     * @param name
     *            Attachment name.
     * @param defaultValue
     *            Attachment default value, which will be used, if it is not
     *            set.
     */
    public Attachment(final String name, final T defaultValue) {
        this.name = name;
        this.defaultValue = defaultValue;
    }
    /**
     * Retrieves the attachment value, stored on the {@link AttachmentHolder}.
     *
     * @param attachmentHolder
     *            {@link AttachmentHolder}.
     * @return attachment value.
     */
    public T get(final AttachmentHolder attachmentHolder) {
        T value = get0(attachmentHolder);
        if (value == null) {
            value = defaultValue;
        }
        return value;
    }
    /**
     * Remove attachment value, stored on the {@link AttachmentHolder}.
     *
     * @param attachmentHolder
     *            {@link AttachmentHolder}.
     * @return The former value or {@code null} if there was previously no
     *         value.
     */
    public T remove(final AttachmentHolder attachmentHolder) {
        final T value = get0(attachmentHolder);
        if (value != null) {
            set(attachmentHolder, null);
        }
        return value;
    }
    /**
     * Set attachment value, stored on the {@link AttachmentHolder}. If a value
     * already exists, it will be replaced.
     *
     * @param attachmentHolder
     *            {@link AttachmentHolder}.
     * @param value
     *            attachment value to set.
     * @return The former value or {@code null} if there was previously no
     *         value.
     */
    public T set(final AttachmentHolder attachmentHolder, final T value) {
        final T oldValue = get0(attachmentHolder);
        attachmentHolder.setAttachment(name, value);
        return oldValue;
    }
    @SuppressWarnings("unchecked")
    private T get0(final AttachmentHolder attachmentHolder) {
        return (T) attachmentHolder.getAttachment(name);
    }
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/AttachmentHolder.java
New file
@@ -0,0 +1,80 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2010 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.Set;
/**
 * Interface declares common functionality for objects, which can store
 * {@link Attachment}s.
 */
public interface AttachmentHolder {
    /**
     * Retrieves the attachment with the specified name.
     *
     * @param name
     *            The name for the attachment to retrieve. It will be treated in
     *            a case-sensitive manner.
     * @return The requested attachment object, or {@code null} if it does not
     *         exist.
     */
    Object getAttachment(String name);
    /**
     * Retrieves the set of attachment names defined for this holder, as a
     * mapping between the attachment name and the associated object.
     *
     * @return The set of attachments defined for this operation.
     */
    Set<String> getAttachmentNames();
    /**
     * Removes the attachment with the specified name.
     *
     * @param name
     *            The name for the attachment to remove. It will be treated in a
     *            case-sensitive manner.
     * @return The attachment that was removed, or {@code null} if it does not
     *         exist.
     */
    Object removeAttachment(String name);
    /**
     * Sets the value of the specified attachment. If an attachment already
     * exists with the same name, it will be replaced. Otherwise, a new
     * attachment will be added.
     *
     * @param name
     *            The name to use for the attachment.
     * @param value
     *            The value to use for the attachment.
     * @return The former value held by the attachment with the given name, or
     *         {@code null} if there was previously no such attachment.
     */
    Object setAttachment(String name, Object value);
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/BackupConfig.java
New file
@@ -0,0 +1,33 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * Configuration options for performing backups.
 */
public interface BackupConfig {
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/BindRequestContext.java
New file
@@ -0,0 +1,55 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2010 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.requests.BindRequest;
/**
 * The bind request context allows for updating the authentication state of the
 * connection.
 */
public interface BindRequestContext extends Operation {
    /**
     * Specifies information about the authentication that has been performed
     * for this connection.
     *
     * @param bindRequest
     *            The bind request the client used for authentication.
     * @param authenticationEntry
     *            The entry for the user as whom the client is authenticated, or
     *            {@code null} if the client is unauthenticated.
     * @param authorizationEntry
     *            The entry for the user that should be considered the
     *            authorization identity for this client, or {@code null} if it
     *            should be the unauthenticated user.
     */
    void setAuthenticationInfo(BindRequest bindRequest, Entry authenticationEntry,
            Entry authorizationEntry);
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProvider.java
New file
@@ -0,0 +1,250 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.Set;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.RequestHandler;
import org.opends.server.types.DirectoryException;
/**
 * An entry container which provides the content of one or more sub-trees.
 * <p>
 * A data provider can be:
 * <ul>
 * <li>a simple data source such as a local back-end, a remote LDAP server or a
 * local LDIF file.
 * <li>used to route operations. This is the case for load balancing and
 * distribution.
 * <li>combine and transform data from underlying data providers. For example,
 * DN mapping, attribute renaming, attribute value transformations, etc.
 * </ul>
 * Data providers operate in two states:
 * <ul>
 * <li>initialized
 * <li>accepting requests
 * </ul>
 * Data providers are created in the <i>initialized</i> state. In this state a
 * data provider has validated its configuration and registered support for
 * off-line services such as export, import, backup, and restore if available.
 * <p>
 * A data provider transitions to the <i>accepting requests</i> state when the
 * {@link #startDataProvider()} method is invoked. In this state a data provider
 * has acquired any remaining resources that it needs in order to be fully
 * operational. This may include connections to underlying data providers. See
 * the documentation for {@link #startDataProvider()} for more information.
 * <p>
 * A data provider transitions back to the <i>initialized</i> state using the
 * {@link #stopDataProvider()} method. This occurs when the data provider is no
 * longer needed in order process client requests, but may still be needed in
 * order to perform off-line services such as import, export, backup, and
 * restore.
 * <p>
 * If data provider is disabled or deleted from the server configuration or if
 * the server is shutdown, then the {@link #finalizeDataProvider()} method is
 * invoked. This method should ensure that the data provider is stopped and no
 * longer available for off-line services such as import, export, backup, and
 * restore.
 */
public interface DataProvider extends RequestHandler<Operation> {
    /**
     * Indicates whether this data provider contains the specified entry.
     *
     * @param dn
     *            The DN of the entry.
     * @return {@code true} if this data provider contains the specified entry,
     *         or {@code false} if it does not.
     * @throws DirectoryException
     *             If a problem occurs while trying to make the determination,
     *             or if {@code dn} is not a DN equal to or subordinate to one
     *             of the base DNs managed by this data provider.
     */
    boolean containsEntry(DN dn) throws DirectoryException;
    /**
     * Deregisters an event listener from this data provider.
     *
     * @param listener
     *            The event listener.
     */
    void deregisterEventListener(DataProviderEventListener listener);
    /**
     * Performs any necessary work to finalize this data provider. This may
     * include closing any connections to underlying data providers, databases,
     * and deregistering any listeners, etc.
     * <p>
     * This method may be called during the Directory Server shutdown process or
     * if a data provider is disabled with the server online. It must not return
     * until this data provider is finalized.
     * <p>
     * Implementations should assume that this data provider has already been
     * stopped using {@link #stopDataProvider()}.
     * <p>
     * Implementations must deregister any listeners such as those required for
     * performing import, export, backup, and restore.
     * <p>
     * Implementations must not throw any exceptions. If any problems are
     * encountered, then they may be logged but the closure should progress as
     * completely as possible.
     */
    void finalizeDataProvider();
    /**
     * Returns an unmodifiable set containing the base DNs of the sub-trees
     * which this data provider contains.
     *
     * @return An unmodifiable set containing the base DNs of the sub-trees
     *         which this data provider contains.
     */
    Set<DN> getBaseDNs();
    /**
     * Retrieves the specified entry from this data provider.
     *
     * @param dn
     *            The DN of the entry.
     * @return The requested entry, or {@code null} if this data provider does
     *         not contain the specified entry.
     * @throws DirectoryException
     *             If a problem occurs while trying to retrieve the entry, or if
     *             {@code dn} is not a DN equal to or subordinate to one of the
     *             base DNs managed by this data provider.
     */
    Entry getEntry(DN dn) throws DirectoryException;
    /**
     * Returns the current status of the provided base DN in this data provider.
     *
     * @param baseDN
     *            The base DN in this data provider.
     * @return The current status of the provided base DN in this data provider.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by this
     *             data provider.
     */
    DataProviderStatus getStatus(DN baseDN) throws DirectoryException;
    /**
     * Returns an unmodifiable set containing the OIDs of the controls that may
     * be supported by the provided base DN in this data provider.
     *
     * @param baseDN
     *            The base DN in this data provider.
     * @return An unmodifiable set containing the OIDs of the controls that may
     *         be supported by the provided base DN in this data provider.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by this
     *             data provider.
     */
    Set<String> getSupportedControls(DN baseDN) throws DirectoryException;
    /**
     * Returns an unmodifiable set containing the OIDs of the features that may
     * be supported by the provided base DN in this data provider.
     *
     * @param baseDN
     *            The base DN in this data provider.
     * @return An unmodifiable set containing the OIDs of the features that may
     *         be supported by the provided base DN in this data provider.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by this
     *             data provider.
     */
    Set<String> getSupportedFeatures(DN baseDN) throws DirectoryException;
    /**
     * Registers an event listener with this data provider.
     *
     * @param listener
     *            The event listener.
     */
    void registerEventListener(DataProviderEventListener listener);
    /**
     * Starts this data provider so that it is ready to process client requests.
     * This method is called immediately before the first data provider
     * connection is opened.
     * <p>
     * Implementations must acquire any remaining resources in order to make
     * this data provider fully operational. This may include any of the
     * following:
     * <ul>
     * <li>connections to other data providers
     * <li>connections to remote databases
     * <li>connections to remote servers
     * <li>opening local databases and files
     * <li>pre-loading databases.
     * </ul>
     * Implementations must perform all required work synchronously such that,
     * on return, this data provider is fully operational.
     */
    void startDataProvider();
    /**
     * Performs any necessary work to stop this data provider. This includes
     * closing any connections to underlying data providers, databases, etc.
     * <p>
     * This method is called immediately after the last data provider connection
     * is closed. It must not return until this data provider is stopped.
     * <p>
     * Implementations must release all resources acquired when this data
     * provider was started. This includes:
     * <ul>
     * <li>connections to other data providers
     * <li>connections to remote databases
     * <li>connections to remote servers
     * <li>closing local databases and files.
     * </ul>
     * Implementations must not deregister this data provider or any associated
     * listeners such as those required for performing import, export, backup,
     * and restore.
     * <p>
     * Implementations must not throw any exceptions. If any problems are
     * encountered, then they may be logged but the shutdown should progress as
     * completely as possible.
     */
    void stopDataProvider();
    /**
     * Indicates whether or not the provided base DN in this data provider
     * supports change notification.
     *
     * @param baseDN
     *            The base DN in this data provider.
     * @return {@code true} if the provided base DN in this data provider
     *         supports change notification.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by this
     *             data provider.
     */
    boolean supportsChangeNotification(DN baseDN) throws DirectoryException;
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderCfg.java
New file
@@ -0,0 +1,33 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * This will be generated by the config framework.
 */
public interface DataProviderCfg {
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderConnection.java
New file
@@ -0,0 +1,159 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.Set;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.RequestHandler;
import org.opends.server.types.DirectoryException;
/**
 * A connection to a data provider. When a connection is no longer needed it
 * must be closed.
 */
public interface DataProviderConnection extends RequestHandler<Operation> {
    /**
     * Closes this data provider connection. When this method returns the
     * connection can no longer be used.
     */
    void close();
    /**
     * Indicates whether the underlying data provider contains the specified
     * entry.
     *
     * @param dn
     *            The DN of the entry.
     * @return {@code true} if the underlying data provider contains the
     *         specified entry, or {@code false} if it does not.
     * @throws DirectoryException
     *             If a problem occurs while trying to make the determination,
     *             or if {@code dn} is not a DN equal to or subordinate to one
     *             of the base DNs managed by the underlying data provider.
     */
    boolean containsEntry(DN dn) throws DirectoryException;
    /**
     * Deregisters an event listener from the underlying data provider.
     *
     * @param listener
     *            The event listener.
     */
    void deregisterEventListener(DataProviderEventListener listener);
    /**
     * Returns an unmodifiable set containing the base DNs of the sub-trees
     * which the underlying data provider contains.
     *
     * @return An unmodifiable set containing the base DNs of the sub-trees
     *         which the underlying data provider contains.
     */
    Set<DN> getBaseDNs();
    /**
     * Retrieves the specified entry from the underlying data provider.
     *
     * @param dn
     *            The DN of the entry.
     * @return The requested entry, or {@code null} if the underlying data
     *         provider does not contain the specified entry.
     * @throws DirectoryException
     *             If a problem occurs while trying to retrieve the entry, or if
     *             {@code dn} is not a DN equal to or subordinate to one of the
     *             base DNs managed by the underlying data provider.
     */
    Entry getEntry(DN dn) throws DirectoryException;
    /**
     * Returns the current status of the provided base DN in the underlying data
     * provider.
     *
     * @param baseDN
     *            The base DN in the underlying data provider.
     * @return The current status of the provided base DN in the underlying data
     *         provider.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by the
     *             underlying data provider.
     */
    DataProviderStatus getStatus(DN baseDN) throws DirectoryException;
    /**
     * Returns an unmodifiable set containing the OIDs of the controls that may
     * be supported by the provided base DN in the underlying data provider.
     *
     * @param baseDN
     *            The base DN in the underlying data provider.
     * @return An unmodifiable set containing the OIDs of the controls that may
     *         be supported by the provided base DN in the underlying data
     *         provider.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by the
     *             underlying data provider.
     */
    Set<String> getSupportedControls(DN baseDN) throws DirectoryException;
    /**
     * Returns an unmodifiable set containing the OIDs of the features that may
     * be supported by the provided base DN in the underlying data provider.
     *
     * @param baseDN
     *            The base DN in the underlying data provider.
     * @return An unmodifiable set containing the OIDs of the features that may
     *         be supported by the provided base DN in the underlying data
     *         provider.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by the
     *             underlying data provider.
     */
    Set<String> getSupportedFeatures(DN baseDN) throws DirectoryException;
    /**
     * Registers an event listener with the underlying data provider.
     *
     * @param listener
     *            The event listener.
     */
    void registerEventListener(DataProviderEventListener listener);
    /**
     * Indicates whether or not the provided base DN in the underlying data
     * provider supports change notification.
     *
     * @param baseDN
     *            The base DN in the underlying data provider.
     * @return {@code true} if the provided base DN in the underlying data
     *         provider supports change notification.
     * @throws DirectoryException
     *             If {@code baseDN} is not one of the base DNs managed by the
     *             underlying data provider.
     */
    boolean supportsChangeNotification(DN baseDN) throws DirectoryException;
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderEvent.java
New file
@@ -0,0 +1,129 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2008 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.util.Reject;
/**
 * An object that provides information about the source of a data provider
 * related event. {@code DataProviderEvent} objects are generated when a data
 * provider experiences an operational error or a state change resulting from
 * configuration updates or administrative actions.
 * <p>
 * TODO: what else should this contain?
 */
public final class DataProviderEvent {
    /**
     * Indicates the type of event that has occurred in the data provider.
     */
    public static enum Type {
        /**
         * The data provider's access mode has changed.
         */
        ACCESS_MODE,
        /**
         * The data provider's set of base DNs has changed.
         */
        BASE_DNS,
        /**
         * The data provider's set of supported controls has changed.
         */
        SUPPORTED_CONTROLS,
        /**
         * The data provider's set of supported features has changed.
         */
        SUPPORTED_FEATURES;
    }
    // A message describing this event.
    private final LocalizableMessage reason;
    // the types of event that have occurred in the data provider.
    private final Set<Type> types;
    /**
     * Creates a new data provider event.
     *
     * @param reason
     *            A message describing this event.
     * @param types
     *            The types of event that have occurred in the data provider.
     */
    public DataProviderEvent(final LocalizableMessage reason, final Set<Type> types) {
        Reject.ifNull(reason);
        Reject.ifNull(types);
        Reject.ifTrue(types.isEmpty());
        this.reason = reason;
        final EnumSet<Type> tmp = EnumSet.noneOf(Type.class);
        for (final Type type : types) {
            tmp.add(type);
        }
        this.types = Collections.unmodifiableSet(tmp);
    }
    /**
     * Returns an unmodifiable set containing the types of event that have
     * occurred in the data provider.
     *
     * @return The unmodifiable set containing the types of event that have
     *         occurred in the data provider.
     */
    public Set<Type> getEventTypes() {
        return types;
    }
    /**
     * Returns a message describing this event.
     *
     * @return A message describing this event.
     */
    public LocalizableMessage getReason() {
        return reason;
    }
    /**
     * Returns a string describing this event.
     *
     * @return A string describing this event.
     */
    @Override
    public String toString() {
        return reason.toString();
    }
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderEventListener.java
New file
@@ -0,0 +1,62 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * An object that registers to be notified of events generated by a
 * {@link DataProviderConnection} object. Data provider events may be triggered
 * as a result of:
 * <ul>
 * <li>The data provider connection being closed.
 * <li>An operational error. For example, a proxy data provider might lose
 * connectivity with the remote server.
 * <li>A configuration change. For example, a data provider may be disabled, or
 * have a new base DN added.
 * <li>An administrative action. For example, a data provider may be temporarily
 * disabled during an import or restore from backup.
 * </ul>
 * In the case of configuration changes, the data provider will only notify its
 * listeners once the configuration change has been applied. If a listener
 * wishes to validate configuration changes before they are applied to a data
 * provider then the listener should use the registration methods provided by
 * {@code DataProviderCfg}.
 */
public interface DataProviderEventListener {
    /**
     * The data provider has changed state due to an operational error,
     * configuration change, or an administrative action.
     * <p>
     * Implementations should examine the provided {@link DataProviderEvent} in
     * order to determine how the data provider has changed.
     *
     * @param event
     *            The data provider event.
     */
    void handleDataProviderEvent(DataProviderEvent event);
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderFactory.java
New file
@@ -0,0 +1,91 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.config.ConfigException;
import org.opends.server.types.InitializationException;
/**
 * A factory for creating data provider instances.
 *
 * @param <T>
 *            The type of configuration handled by this data provider.
 * @see DataProvider
 */
public interface DataProviderFactory<T extends DataProviderCfg> {
    /**
     * Creates and initializes a new data provider based on the information in
     * the provided configuration.
     * <p>
     * Implementations must not start any services nor attempt to connect to
     * other data providers. However, they may register with the backup/restore
     * and import/export managers.
     *
     * @param id
     *            The ID which should be used to uniquely identify this data
     *            provider.
     * @param configuration
     *            The configuration that contains the information to use to
     *            create and initialize the new data provider.
     * @return The new data provider instance.
     * @throws ConfigException
     *             If an unrecoverable problem arises during initialization of
     *             the data provider as a result of the server configuration.
     * @throws InitializationException
     *             If a problem occurs during initialization of the data
     *             provider that is not related to the server configuration.
     * @see DataProvider#startDataProvider()
     */
    DataProvider createDataProvider(DataProviderID id, T configuration) throws ConfigException,
            InitializationException;
    /**
     * Indicates whether the provided configuration is acceptable for creating
     * and initializing a new data provider using this data provider factory.
     * <p>
     * This method will be called before
     * {@link #createDataProvider(DataProviderID, DataProviderCfg)} in order
     * validate the configuration.
     * <p>
     * Implementations should perform basic validation of the configuration but
     * should not attempt to start any resource or connect to other data
     * providers.
     *
     * @param configuration
     *            The configuration for which to make the determination.
     * @param unacceptableReasons
     *            A list that may be used to hold the reasons that the provided
     *            configuration is not acceptable.
     * @return {@code true} if the provided configuration is acceptable for this
     *         data provider factory, or {@code false} if not.
     */
    boolean isConfigurationAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons);
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderID.java
New file
@@ -0,0 +1,154 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2008 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.util.Locale;
/**
 * A unique ID which can be used for identifying data providers.
 * <p>
 * There are two types of data provider:
 * <ul>
 * <li><b>User configured</b>: these are data providers which have been defined
 * using the server's configuration.
 * <li><b>Internal</b>: these are data providers which have been created
 * internally.
 * </ul>
 */
public final class DataProviderID implements Comparable<DataProviderID> {
    /**
     * Creates a new ID for an internal data provider.
     *
     * @param name
     *            The name of the internal data provider.
     * @return The new data provider ID.
     */
    public static DataProviderID newInternalID(final String name) {
        return new DataProviderID(name, true /* internal */);
    }
    /**
     * Creates a new ID for a user configured data provider.
     *
     * @param name
     *            The name of the user configured data provider.
     * @return The new data provider ID.
     */
    public static DataProviderID newUserID(final String name) {
        return new DataProviderID(name, false /* user */);
    }
    // Flag indicating whether or not this ID represents an internal
    // data provider.
    private final boolean isInternal;
    // The data provider name.
    private final String name;
    // The normalized name.
    private final String normalizedName;
    // Prevent direct instantiation.
    private DataProviderID(final String name, final boolean isInternal) {
        this.name = name;
        this.normalizedName = name.trim().toLowerCase(Locale.ENGLISH);
        this.isInternal = isInternal;
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public int compareTo(final DataProviderID o) {
        if (isInternal != o.isInternal) {
            // Internal data providers sort last.
            return isInternal ? 1 : -1;
        } else {
            return normalizedName.compareTo(o.normalizedName);
        }
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        } else if (obj instanceof DataProviderID) {
            final DataProviderID other = (DataProviderID) obj;
            if (isInternal != other.isInternal) {
                return false;
            } else {
                return normalizedName.equals(other.normalizedName);
            }
        } else {
            return false;
        }
    }
    /**
     * Returns the data provider name associated with this data provider ID.
     *
     * @return The data provider name associated with this data provider ID.
     */
    public String getName() {
        return name;
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return normalizedName.hashCode();
    }
    /**
     * Indicating whether or not this ID represents an internal data provider.
     *
     * @return <code>true</code> if this ID represents an internal data
     *         provider.
     */
    public boolean isInternal() {
        return isInternal;
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        if (isInternal) {
            return "__" + name;
        } else {
            return name;
        }
    }
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/DataProviderStatus.java
New file
@@ -0,0 +1,79 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2008 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * The status of a data provider. A data provider may be enabled, disabled, or
 * providing a restricted service.
 */
public enum DataProviderStatus {
    /**
     * The data provider is disabled and rejecting all operations.
     */
    DISABLED("disabled"),
    /**
     * The data provider is enabled and accepting all operations.
     */
    ENABLED("enabled"),
    /**
     * The data provider is only accepting read operations; all write operations
     * will be rejected.
     */
    READ_ONLY("read-only"),
    /**
     * The data provider is accepting read operations, internal write
     * operations, and updates through synchronization; all other write
     * operations will be rejected.
     */
    WRITE_INTERNAL_ONLY("write-internal-only");
    // The human-readable name for this status.
    private String name;
    /**
     * Creates a new data provider status with the provided name.
     *
     * @param name
     *            The human-readable name for this status.
     */
    private DataProviderStatus(final String name) {
        this.name = name;
    }
    /**
     * Retrieves a string representation of this status.
     *
     * @return A string representation of this status.
     */
    @Override
    public String toString() {
        return name;
    }
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/ExportableDataProvider.java
New file
@@ -0,0 +1,61 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2008 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import org.forgerock.opendj.ldap.FutureResult;
import org.forgerock.opendj.ldap.ResultHandler;
import org.forgerock.opendj.ldif.EntryWriter;
/**
 * A data provider which supports LDIF export functionality.
 * <p>
 * FIXME: the async APIs used below are a bad fit. We do not want to return an
 * ErrorResultException. We really need a more generic promises API.
 */
public interface ExportableDataProvider {
    /**
     * Exports the contents of this data provider to the provided entry writer.
     * <p>
     * Note that the server will not explicitly initialize this data provider
     * before calling this method.
     *
     * @param writer
     *            The entry writer.
     * @param handler
     *            A handler which will be notified when the export completes.
     * @return A future representing the completion of the export.
     */
    FutureResult<Void> exportEntries(EntryWriter writer, ResultHandler<Void> handler);
    /**
     * Returns the ID of this data provider.
     *
     * @return The ID of this data provider.
     */
    DataProviderID getDataProviderID();
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/ImportableDataProvider.java
New file
@@ -0,0 +1,69 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *       Copyright 2008 Sun Microsystems, Inc.
 *       Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import org.forgerock.opendj.ldap.FutureResult;
import org.forgerock.opendj.ldap.ResultHandler;
import org.forgerock.opendj.ldif.EntryReader;
/**
 * A data provider which supports LDIF import functionality.
 * <p>
 * FIXME: the async APIs used below are a bad fit. We do not want to return an
 * ErrorResultException. We really need a more generic promises API.
 * <p>
 * FIXME: it would be nice if we can use EntryReader, however we may need to
 * provide an optimized implementation for use in multi-threaded imports. E.g.
 * performing DN checking as early as possible before doing schema validation.
 * <p>
 * FIXME: import allows you to append, merge, replace entries. Do we need to
 * expose that here?
 */
public interface ImportableDataProvider {
    /**
     * Returns the ID of this data provider.
     *
     * @return The ID of this data provider.
     */
    DataProviderID getDataProviderID();
    /**
     * Imports the contents of this data provider from the provided entry
     * reader.
     * <p>
     * Note that the server will not explicitly initialize this data provider
     * before calling this method.
     *
     * @param reader
     *            The entry reader.
     * @param handler
     *            A handler which will be notified when the import completes.
     * @return A future representing the completion of the import.
     */
    FutureResult<Void> importEntries(EntryReader reader, ResultHandler<Void> handler);
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/Operation.java
New file
@@ -0,0 +1,202 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import java.net.InetSocketAddress;
import java.util.Collection;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.RequestContext;
import org.forgerock.opendj.ldap.requests.BindRequest;
/**
 * The context in which a request is to be processed.
 * <p>
 * Implementations may query the context in order to:
 * <ul>
 * <li>query the schema associated with the request (attribute types, decode
 * DNs, etc)
 * <li>perform internal operations
 * <li>query information regarding client performing the request
 * </ul>
 * Context implementations take care of correctly routing internal requests.
 * <p>
 * In addition, the context acts as a transaction manager, coordinating any
 * resources accessed during the processing of a request and any subsequent
 * requests forming part of the same logical transaction.
 * <p>
 * FiXME: this interface should be split up into sub-components, such as network
 * information (protocol, addresses), client information (auth ID, SSF,
 * privileges).
 */
public interface Operation extends RequestContext, AttachmentHolder {
    /**
     * Retrieves the entry for the user that should be considered the
     * authorization identity for this operation. In many cases, it will be the
     * same as the authorization entry for the underlying client connection, or
     * {@code null} if no authentication has been performed on that connection.
     * However, it may be some other value if special processing has been
     * requested (e.g., the operation included a proxied authorization control).
     *
     * @return The entry for the user that should be considered the
     *         authorization identity for this operation, or {@code null} if the
     *         authorization identity should be the unauthenticated user.
     */
    public Entry getAuthorizationEntry();
    /**
     * Returns a connection for performing internal operations.
     *
     * @return A connection for performing internal operations.
     */
    public Connection getConnection();
    /**
     * Retrieves the operation ID for this operation.
     *
     * @return The operation ID for this operation.
     */
    public long getOperationID();
    /**
     * Indicates whether the authenticate client has all of the specified
     * privileges.
     *
     * @param privileges
     *            The array of privileges for which to make the determination.
     * @return {@code true} if the authenticated client has all of the specified
     *         privileges, or {@code false} if not.
     */
    public boolean hasAllPrivileges(Collection<Privilege> privileges);
    /**
     * Indicates whether the authenticated client has the specified privilege.
     *
     * @param privilege
     *            The privilege for which to make the determination.
     * @return {@code true} if the authenticated client has the specified
     *         privilege, or {@code false} if not.
     */
    public boolean hasPrivilege(Privilege privilege);
    /**
     * Sets the entry for the user that should be considered the authorization
     * identity for this operation.
     *
     * @param authorizationEntry
     *            The entry for the user that should be considered the
     *            authorization identity for this operation, or {@code null} if
     *            it should be the unauthenticated user.
     */
    public void setAuthorizationEntry(Entry authorizationEntry);
    /**
     * Retrieves the entry for the user as whom the client is authenticated.
     *
     * @return The entry for the user as whom the client is authenticated, or
     *         {@code null} if the client is unauthenticated.
     */
    Entry getAuthenticationEntry();
    /**
     * Retrieves the last successful bind request from the client.
     *
     * @return The last successful bind request or {@code null} if the client
     *         have not yet successfully bind.
     */
    BindRequest getBindRequest();
    /**
     * Retrieves the unique identifier that is assigned to the client connection
     * that submitted this operation.
     *
     * @return The unique identifier that is assigned to the client connection
     *         that submitted this operation.
     */
    long getConnectionID();
    /**
     * Returns the {@code InetSocketAddress} associated with the local system.
     *
     * @return The {@code InetSocketAddress} associated with the local system.
     */
    InetSocketAddress getLocalAddress();
    /**
     * Retrieves the default maximum number of entries that should checked for
     * matches during a search.
     *
     * @return The default maximum number of entries that should checked for
     *         matches during a search.
     */
    int getLookthroughLimit();
    /**
     * Returns the {@code InetSocketAddress} associated with the remote system.
     *
     * @return The {@code InetSocketAddress} associated with the remote system.
     */
    InetSocketAddress getPeerAddress();
    /**
     * Retrieves the protocol that the client is using to communicate with the
     * Directory Server.
     *
     * @return The protocol that the client is using to communicate with the
     *         Directory Server.
     */
    String getProtocol();
    /**
     * Returns the strongest cipher strength currently in use by the underlying
     * connection.
     *
     * @return The strongest cipher strength currently in use by the underlying
     *         connection.
     */
    int getSecurityStrengthFactor();
    /**
     * Retrieves the size limit that will be enforced for searches performed
     * using this client connection.
     *
     * @return The size limit that will be enforced for searches performed using
     *         this client connection.
     */
    int getSizeLimit();
    /**
     * Retrieves the time limit that will be enforced for searches performed
     * using this client connection.
     *
     * @return The time limit that will be enforced for searches performed using
     *         this client connection.
     */
    int getTimeLimit();
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/Privilege.java
New file
@@ -0,0 +1,33 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * TODO: User privilege.
 */
public interface Privilege {
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/RestoreConfig.java
New file
@@ -0,0 +1,33 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
/**
 * Configuration options for restoring backups.
 */
public interface RestoreConfig {
}
opendj-server3/src/main/java/org/forgerock/opendj/server/core/package-info.java
New file
@@ -0,0 +1,34 @@
/*
* CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
/**
 * Contains APIs for new DataProvider design. This is work in
 * progress. On completion, this package will be removed and
 * classes put in their appropriate locations.
 */
package org.forgerock.opendj.server.core;
opendj-server3/src/site/xdoc/index.xml.vm
New file
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ! CCPL HEADER START
  !
  ! This work is licensed under the Creative Commons
  ! Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  ! To view a copy of this license, visit
  ! http://creativecommons.org/licenses/by-nc-nd/3.0/
  ! or send a letter to Creative Commons, 444 Castro Street,
  ! Suite 900, Mountain View, California, 94041, USA.
  !
  ! You can also obtain a copy of the license at
  ! trunk/opendj3/legal-notices/CC-BY-NC-ND.txt.
  ! See the License for the specific language governing permissions
  ! and limitations under the License.
  !
  ! If applicable, add the following below this CCPL HEADER, with the fields
  ! enclosed by brackets "[]" replaced with your own identifying information:
  !      Portions Copyright [yyyy] [name of copyright owner]
  !
  ! CCPL HEADER END
  !
  !      Copyright 2013 ForgeRock AS
  !
-->
<document xmlns="http://maven.apache.org/XDOC/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
  <properties>
    <title>About ${project.name}</title>
    <author email="opendj-dev@forgerock.org">${project.organization.name}</author>
  </properties>
  <body>
    <section name="About ${project.name}">
      <p>
        ${project.description}
      </p>
    </section>
    <section name="Documentation for ${project.name}">
      <p>
        Javadoc for this module can be found <a href="apidocs/index.html">here</a>.
      </p>
    </section>
    <section name="Get ${project.name}">
      <p>
        Start developing your applications by obtaining ${project.name}
        using any of the following methods:
    </p>
      <subsection name="Maven">
        <p>
          By far the simplest method is to develop your application using Maven
          and add the following settings to your <b>pom.xml</b>:
        </p>
        <source>&lt;repositories>
  &lt;repository>
    &lt;id>forgerock-staging-repository&lt;/id>
    &lt;name>ForgeRock Release Repository&lt;/name>
    &lt;url>${mavenRepoReleases}&lt;/url>
    &lt;snapshots>
      &lt;enabled>false&lt;/enabled>
    &lt;/snapshots>
  &lt;/repository>
  &lt;repository>
    &lt;id>forgerock-snapshots-repository&lt;/id>
    &lt;name>ForgeRock Snapshot Repository&lt;/name>
    &lt;url>${mavenRepoSnapshots}&lt;/url>
    &lt;releases>
      &lt;enabled>false&lt;/enabled>
    &lt;/releases>
  &lt;/repository>
&lt;/repositories>
...
&lt;dependencies>
  &lt;dependency>
    &lt;groupId>${project.groupId}&lt;/groupId>
    &lt;artifactId>${project.artifactId}&lt;/artifactId>
    &lt;version>${project.version}&lt;/version>
  &lt;/dependency>
&lt;/dependencies></source>
      </subsection>
      <subsection name="Download">
        <p>
          If you are not using Maven then you will need to download a pre-built
          binary from the ForgeRock Maven repository, along with any compile
          time <a href="dependencies.html">dependencies</a>:
        </p>
        <ul>
          <li><a href="${mavenRepoReleases}/org/forgerock/opendj/${project.artifactId}">Stable releases</a></li>
          <li><a href="${mavenRepoSnapshots}/org/forgerock/opendj/${project.artifactId}/${project.version}">Latest development snapshot</a></li>
        </ul>
      </subsection>
      <subsection name="Build">
        <p>
          For the DIY enthusiasts you can build it yourself by checking out the
          latest code using <a href="source-repository.html">Subversion</a>
          and building it with Maven 3.
        </p>
      </subsection>
    </section>
    <section name="Getting started">
      <p>
        The following example shows how ${project.name} may be used:
      </p>
      <source>TODO</source>
    </section>
  </body>
</document>