UCDetector and AutoRefactor code cleanup
| | |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.guitools.controlpanel.task; |
| | | |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | |
| | | import java.util.Set; |
| | | import java.util.TreeSet; |
| | | |
| | | import javax.swing.JProgressBar; |
| | | import javax.swing.SwingUtilities; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.guitools.controlpanel.datamodel.BackendDescriptor; |
| | | import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; |
| | | import org.opends.guitools.controlpanel.ui.ProgressDialog; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.tools.ManageTasks; |
| | | import org.opends.server.tools.tasks.TaskEntry; |
| | | |
| | |
| | | |
| | | arguments.toArray(args); |
| | | |
| | | returnCode = ManageTasks.mainTaskInfo(args, System.in, |
| | | outPrintStream, errorPrintStream, false); |
| | | returnCode = ManageTasks.mainTaskInfo(args, outPrintStream, errorPrintStream, false); |
| | | if (returnCode != 0) |
| | | { |
| | | break; |
| | | } |
| | | else |
| | | |
| | | numberCanceled++; |
| | | final int fNumberCanceled = numberCanceled; |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | numberCanceled ++; |
| | | final int fNumberCanceled = numberCanceled; |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | @Override |
| | | public void run() |
| | | { |
| | | @Override |
| | | public void run() |
| | | JProgressBar progressBar = getProgressDialog().getProgressBar(); |
| | | if (fNumberCanceled == 1) |
| | | { |
| | | if (fNumberCanceled == 1) |
| | | { |
| | | getProgressDialog().getProgressBar().setIndeterminate(false); |
| | | } |
| | | getProgressDialog().getProgressBar().setValue( |
| | | (fNumberCanceled * 100) / totalNumber); |
| | | progressBar.setIndeterminate(false); |
| | | } |
| | | }); |
| | | } |
| | | progressBar.setValue((fNumberCanceled * 100) / totalNumber); |
| | | } |
| | | }); |
| | | } |
| | | if (returnCode != 0) |
| | | { |
| | |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup; |
| | | |
| | | import java.io.BufferedReader; |
| | |
| | | { |
| | | // Reads the inputstream content. |
| | | try (InputStream input = new FileInputStream(getFile()); |
| | | BufferedReader br = new BufferedReader(new InputStreamReader(input));) |
| | | BufferedReader br = new BufferedReader(new InputStreamReader(input))) |
| | | { |
| | | final StringBuilder sb = new StringBuilder(); |
| | | String read; |
| | |
| | | /** |
| | | * Sets the license approval status. |
| | | * |
| | | * @param p_approved |
| | | * @param approved |
| | | * the license approval status |
| | | */ |
| | | public static void setApproval(boolean p_approved) |
| | | public static void setApproval(boolean approved) |
| | | { |
| | | approved = p_approved; |
| | | LicenseFile.approved = approved; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return new File(getInstanceLegalDirectory(), ACCEPTED_LICENSE_FILE_NAME).exists(); |
| | | } |
| | | |
| | | } |
| | |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | putBoolean(userAttrs, ATTR_BACKUP_ENCRYPTED, backupInfo.isEncrypted()); |
| | | putBoolean(userAttrs, ATTR_BACKUP_INCREMENTAL, backupInfo.isIncremental()); |
| | | |
| | | HashSet<String> dependencies = backupInfo.getDependencies(); |
| | | Set<String> dependencies = backupInfo.getDependencies(); |
| | | if (dependencies != null && !dependencies.isEmpty()) { |
| | | t = DirectoryServer.getAttributeType(ATTR_BACKUP_DEPENDENCY); |
| | | AttributeBuilder builder = new AttributeBuilder(t); |
| | |
| | | putByteString(userAttrs, ATTR_BACKUP_UNSIGNED_HASH, unsignedHash); |
| | | } |
| | | |
| | | HashMap<String, String> properties = backupInfo.getBackupProperties(); |
| | | Map<String, String> properties = backupInfo.getBackupProperties(); |
| | | if (properties != null && !properties.isEmpty()) { |
| | | for (Map.Entry<String, String> e : properties.entrySet()) { |
| | | t = DirectoryServer.getAttributeType(toLowerCase(e.getKey())); |
| | |
| | | /** Loads the compressed schema information from disk. */ |
| | | private void load() |
| | | { |
| | | FileInputStream inputStream = null; |
| | | |
| | | try |
| | | // Determine the location of the compressed schema data file. It should |
| | | // be in the config directory with a name of "schematokens.dat". If that |
| | | // file doesn't exist, then don't do anything. |
| | | final String path = DirectoryServer.getInstanceRoot() + File.separator |
| | | + CONFIG_DIR_NAME + File.separator + COMPRESSED_SCHEMA_FILE_NAME; |
| | | if (!new File(path).exists()) |
| | | { |
| | | // Determine the location of the compressed schema data file. It should |
| | | // be in the config directory with a name of "schematokens.dat". If that |
| | | // file doesn't exist, then don't do anything. |
| | | final String path = DirectoryServer.getInstanceRoot() + File.separator |
| | | + CONFIG_DIR_NAME + File.separator + COMPRESSED_SCHEMA_FILE_NAME; |
| | | if (!new File(path).exists()) |
| | | { |
| | | return; |
| | | } |
| | | inputStream = new FileInputStream(path); |
| | | return; |
| | | } |
| | | |
| | | try (FileInputStream inputStream = new FileInputStream(path)) |
| | | { |
| | | final ASN1Reader reader = ASN1.getReader(inputStream); |
| | | |
| | | // The first element in the file should be a sequence of object class |
| | |
| | | // FIXME -- Should we do something else here? |
| | | throw new RuntimeException(e); |
| | | } |
| | | finally |
| | | { |
| | | close(inputStream); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | synchronized (saveLock) |
| | | { |
| | | FileOutputStream outputStream = null; |
| | | try |
| | | // Determine the location of the "live" compressed schema data file, and |
| | | // then append ".tmp" to get the name of the temporary file that we will use. |
| | | final String path = DirectoryServer.getInstanceRoot() + File.separator |
| | | + CONFIG_DIR_NAME + File.separator + COMPRESSED_SCHEMA_FILE_NAME; |
| | | final String tempPath = path + ".tmp"; |
| | | try (FileOutputStream outputStream = new FileOutputStream(tempPath)) |
| | | { |
| | | // Determine the location of the "live" compressed schema data file, and |
| | | // then append ".tmp" to get the name of the temporary file that we will |
| | | // use. |
| | | final String path = DirectoryServer.getInstanceRoot() + File.separator |
| | | + CONFIG_DIR_NAME + File.separator + COMPRESSED_SCHEMA_FILE_NAME; |
| | | final String tempPath = path + ".tmp"; |
| | | |
| | | outputStream = new FileOutputStream(tempPath); |
| | | final ASN1Writer writer = ASN1.getWriter(outputStream); |
| | | |
| | | // The first element in the file should be a sequence of object class |
| | |
| | | throw new DirectoryException( |
| | | DirectoryServer.getServerErrorResultCode(), message, e); |
| | | } |
| | | finally |
| | | { |
| | | close(outputStream); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** Stores mapping between configuration attribute name and its label. */ |
| | | private static Map<String,LocalizableMessage> argDisplayMap = new HashMap<>(); |
| | | private static final Map<String, LocalizableMessage> argDisplayMap = new HashMap<>(); |
| | | static { |
| | | argDisplayMap.put(ATTR_TASK_EXPORT_LDIF_FILE, INFO_EXPORT_ARG_LDIF_FILE.get()); |
| | | argDisplayMap.put(ATTR_TASK_EXPORT_BACKEND_ID, INFO_EXPORT_ARG_BACKEND_ID.get()); |
| | |
| | | /** |
| | | * Processes the command-line arguments and invokes the backup process. |
| | | * |
| | | * @param args The command-line arguments provided to this program. |
| | | * |
| | | * @return The error code. |
| | | */ |
| | | public static int mainBackUpDB(String[] args) |
| | | { |
| | | return mainBackUpDB(args, true, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | | * Processes the command-line arguments and invokes the backup process. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @param initializeServer Indicates whether to initialize the server. |
| | |
| | | /** Describes an attribute index which should be created during installation. */ |
| | | public static final class DefaultIndex |
| | | { |
| | | static DefaultIndex withEqualityAndSubstring(final String name) |
| | | private static DefaultIndex withEqualityAndSubstring(final String name) |
| | | { |
| | | return new DefaultIndex(name, true); |
| | | } |
| | | |
| | | static DefaultIndex withEquality(final String name) |
| | | private static DefaultIndex withEquality(final String name) |
| | | { |
| | | return new DefaultIndex(name, false); |
| | | } |
| | |
| | | * @throws Exception |
| | | * If any problems occurred |
| | | */ |
| | | public static void createBackend(RootCfgClient rootConfiguration, String backendName, Collection<DN> baseDNs, |
| | | private static void createBackend(RootCfgClient rootConfiguration, String backendName, Collection<DN> baseDNs, |
| | | ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType) throws Exception |
| | | { |
| | | final BackendCfgClient backendCfgClient = rootConfiguration.createBackend(backendType, backendName, null); |
| | |
| | | */ |
| | | public class BackendTypeHelper |
| | | { |
| | | |
| | | /** |
| | | * Filter the provided backend name by removing the backend suffix. |
| | | * |
| | |
| | | { |
| | | return backend; |
| | | } |
| | | |
| | | } |
| | | |
| | | private final List<ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg>> backends; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> retrieveBackendTypeFromName( |
| | | final String backendTypeStr) |
| | | { |
| | |
| | | * the backend type to adapt. |
| | | * @return a BackendTypeUIAdapter which adapts the provided backend. |
| | | */ |
| | | public static BackendTypeUIAdapter getBackendTypeAdapter( |
| | | private static BackendTypeUIAdapter getBackendTypeAdapter( |
| | | ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backend) |
| | | { |
| | | return new BackendTypeUIAdapter(backend); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_FILE_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_JMXPORT_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_PORT_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.adapter.server3x.Converters; |
| | | import org.forgerock.opendj.config.DefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.ManagedObjectDefinition; |
| | | import org.forgerock.opendj.config.StringPropertyDefinition; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.Syntax; |
| | | import org.forgerock.opendj.server.config.client.BackendCfgClient; |
| | | import org.forgerock.opendj.server.config.meta.CryptoManagerCfgDefn; |
| | | import org.forgerock.opendj.server.config.server.BackendCfg; |
| | | import org.opends.quicksetup.installer.Installer; |
| | | import org.forgerock.opendj.config.DefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.StringPropertyDefinition; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.server.config.meta.CryptoManagerCfgDefn; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.core.ConfigurationHandler; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.LockFileManager; |
| | |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.types.DirectoryEnvironmentConfig; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.NullOutputStream; |
| | |
| | | + "ds-cfg-trust-store-type: JCEKS" + NEW_LINE |
| | | + "ds-cfg-trust-store-file: config/truststore" + NEW_LINE; |
| | | |
| | | /** The fully-qualified name of this class. */ |
| | | private static final String CLASS_NAME = "org.opends.server.tools.ConfigureDS"; |
| | | |
| | | /** The DN of the configuration entry defining the LDAP connection handler. */ |
| | | public static final String DN_LDAP_CONNECTION_HANDLER = "cn=LDAP Connection Handler," + DN_CONNHANDLER_BASE; |
| | | |
| | | private static final String DN_LDAP_CONNECTION_HANDLER = "cn=LDAP Connection Handler," + DN_CONNHANDLER_BASE; |
| | | /** The DN of the configuration entry defining the Administration connector. */ |
| | | public static final String DN_ADMIN_CONNECTOR = "cn=Administration Connector," + DN_CONFIG_ROOT; |
| | | |
| | | private static final String DN_ADMIN_CONNECTOR = "cn=Administration Connector," + DN_CONFIG_ROOT; |
| | | /** The DN of the configuration entry defining the LDAPS connection handler. */ |
| | | private static final String DN_LDAPS_CONNECTION_HANDLER = "cn=LDAPS Connection Handler," + DN_CONNHANDLER_BASE; |
| | | |
| | | /** The DN of the configuration entry defining the HTTP connection handler. */ |
| | | private static final String DN_HTTP_CONNECTION_HANDLER = |
| | | "cn=HTTP Connection Handler,cn=Connection Handlers,cn=config"; |
| | | |
| | | /** The DN of the configuration entry defining the JMX connection handler. */ |
| | | private static final String DN_JMX_CONNECTION_HANDLER = "cn=JMX Connection Handler," + DN_CONNHANDLER_BASE; |
| | | |
| | | /** The DN of the configuration entry defining the initial root user. */ |
| | | public static final String DN_ROOT_USER = "cn=Directory Manager," + DN_ROOT_DN_CONFIG_BASE; |
| | | |
| | | private static final String DN_ROOT_USER = "cn=Directory Manager," + DN_ROOT_DN_CONFIG_BASE; |
| | | /** The DN of the Crypto Manager. */ |
| | | public static final String DN_CRYPTO_MANAGER = "cn=Crypto Manager,cn=config"; |
| | | |
| | | private static final String DN_CRYPTO_MANAGER = "cn=Crypto Manager,cn=config"; |
| | | /** The DN of the DIGEST-MD5 SASL mechanism handler. */ |
| | | public static final String DN_DIGEST_MD5_SASL_MECHANISM = "cn=DIGEST-MD5,cn=SASL Mechanisms,cn=config"; |
| | | private static final String DN_DIGEST_MD5_SASL_MECHANISM = "cn=DIGEST-MD5,cn=SASL Mechanisms,cn=config"; |
| | | |
| | | private static int SUCCESS = 0; |
| | | private static int ERROR = 1; |
| | | private static final int SUCCESS = 0; |
| | | private static final int ERROR = 1; |
| | | |
| | | /** |
| | | * Provides the command-line arguments to the <CODE>configMain</CODE> method |
| | |
| | | arguments = args; |
| | | out = NullOutputStream.wrapOrNullStream(outStream); |
| | | err = NullOutputStream.wrapOrNullStream(errStream); |
| | | argParser = new ArgumentParser(CLASS_NAME, INFO_CONFIGDS_TOOL_DESCRIPTION.get(), false); |
| | | argParser = new ArgumentParser(ConfigureDS.class.getName(), INFO_CONFIGDS_TOOL_DESCRIPTION.get(), false); |
| | | } |
| | | |
| | | private int run() |
| | |
| | | * Returns <CODE>null</CODE> if no alternative cipher could be found. |
| | | * @return a cipher that is supported by the JVM we are running at. |
| | | */ |
| | | public static String getAlternativeCipher() |
| | | private static String getAlternativeCipher() |
| | | { |
| | | final String[] preferredAlternativeCiphers = |
| | | { |
| | | "RSA/ECB/OAEPWITHSHA1ANDMGF1PADDING", |
| | | "RSA/ECB/PKCS1Padding" |
| | | }; |
| | | String alternativeCipher = null; |
| | | for (final String cipher : preferredAlternativeCiphers) |
| | | { |
| | | try |
| | | { |
| | | Cipher.getInstance(cipher); |
| | | alternativeCipher = cipher; |
| | | break; |
| | | return cipher; |
| | | } |
| | | catch (final Throwable t) |
| | | catch (final Throwable ignored) |
| | | { |
| | | // ignored |
| | | } |
| | | } |
| | | return alternativeCipher; |
| | | return null; |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | |
| | | /** The service was already enabled. */ |
| | | public static final int SERVICE_ALREADY_ENABLED = 1; |
| | | /** The service name was already in use. */ |
| | | public static final int SERVICE_NAME_ALREADY_IN_USE = 2; |
| | | private static final int SERVICE_NAME_ALREADY_IN_USE = 2; |
| | | /** An error occurred enabling the service. */ |
| | | public static final int SERVICE_ENABLE_ERROR = 3; |
| | | private static final int SERVICE_ENABLE_ERROR = 3; |
| | | |
| | | /** Return codes for the method disableService. */ |
| | | /** The service was successfully disabled. */ |
| | |
| | | /** The service was already disabled. */ |
| | | public static final int SERVICE_ALREADY_DISABLED = 1; |
| | | /** The service is marked for deletion. */ |
| | | public static final int SERVICE_MARKED_FOR_DELETION = 2; |
| | | private static final int SERVICE_MARKED_FOR_DELETION = 2; |
| | | /** An error occurred disabling the service. */ |
| | | public static final int SERVICE_DISABLE_ERROR = 3; |
| | | |
| | |
| | | /** The service is enabled. */ |
| | | public static final int SERVICE_STATE_ENABLED = 0; |
| | | /** The service is disabled. */ |
| | | public static final int SERVICE_STATE_DISABLED = 1; |
| | | private static final int SERVICE_STATE_DISABLED = 1; |
| | | /** An error occurred checking the service state. */ |
| | | public static final int SERVICE_STATE_ERROR = 2; |
| | | private static final int SERVICE_STATE_ERROR = 2; |
| | | |
| | | /** Return codes for the method cleanupService. */ |
| | | /** The service cleanup worked. */ |
| | | public static final int SERVICE_CLEANUP_SUCCESS = 0; |
| | | private static final int SERVICE_CLEANUP_SUCCESS = 0; |
| | | /** The service could not be found. */ |
| | | public static final int SERVICE_NOT_FOUND = 1; |
| | | private static final int SERVICE_NOT_FOUND = 1; |
| | | /** An error occurred cleaning up the service. */ |
| | | public static final int SERVICE_CLEANUP_ERROR = 2; |
| | | private static final int SERVICE_CLEANUP_ERROR = 2; |
| | | /** The service is marked for deletion. */ |
| | | public static final int SERVICE_CLEANUP_MARKED_FOR_DELETION = 3; |
| | | private static final int SERVICE_CLEANUP_MARKED_FOR_DELETION = 3; |
| | | |
| | | /** |
| | | * Configures the Windows service for this instance on this machine. This tool |
| | |
| | | * @return the integer code describing if the operation could be completed or |
| | | * not. |
| | | */ |
| | | public static int configureWindowsService(String[] args, OutputStream outStream, OutputStream errStream) |
| | | private static int configureWindowsService(String[] args, OutputStream outStream, OutputStream errStream) |
| | | { |
| | | PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | |
| | | * <CODE>SERVICE_ALREADY_ENABLED</CODE> depending on whether the |
| | | * service could be enabled or not. |
| | | */ |
| | | public static int enableService(PrintStream out, PrintStream err, String serviceName, String serviceDescription) |
| | | private static int enableService(PrintStream out, PrintStream err, String serviceName, String serviceDescription) |
| | | { |
| | | String serverRoot = getServerRoot(); |
| | | String[] cmd; |
| | |
| | | * <CODE>SERVICE_CLEANUP_ERROR</CODE> depending on whether the service |
| | | * could be found or not. |
| | | */ |
| | | public static int cleanupService(String serviceName, PrintStream out, |
| | | PrintStream err) |
| | | private static int cleanupService(String serviceName, PrintStream out, PrintStream err) |
| | | { |
| | | String[] cmd; |
| | | if (hasUAC()) |
| | |
| | | * <CODE>SERVICE_STATE_ERROR</CODE> depending on the state of the |
| | | * service. |
| | | */ |
| | | public static int serviceState(PrintStream out, PrintStream err) |
| | | private static int serviceState(PrintStream out, PrintStream err) |
| | | { |
| | | String serviceName = null; |
| | | |
| | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainExportLDIF(args, true, System.out, System.err); |
| | | |
| | | if(retCode != 0) |
| | | { |
| | | System.exit(filterExitCode(retCode)); |
| | |
| | | /** |
| | | * Processes the command-line arguments and invokes the export process. |
| | | * |
| | | * @param args The command-line arguments provided to this program. |
| | | * |
| | | * @return The error code. |
| | | */ |
| | | public static int mainExportLDIF(String[] args) |
| | | { |
| | | return mainExportLDIF(args, true, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | | * Processes the command-line arguments and invokes the export process. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @param initializeServer Indicates whether to initialize the server. |
| | |
| | | BooleanArgument.builder("encryptLDIF") |
| | | .shortIdentifier('y') |
| | | .description(INFO_LDIFEXPORT_DESCRIPTION_ENCRYPT_LDIF.get()) |
| | | .hidden() // See issue #27 |
| | | .hidden() // See issue OPENDJ-448 |
| | | .buildAndAddToParser(argParser); |
| | | signHash = |
| | | BooleanArgument.builder("signHash") |
| | | .shortIdentifier('s') |
| | | .description(INFO_LDIFEXPORT_DESCRIPTION_SIGN_HASH.get()) |
| | | .hidden() // See issue #28 |
| | | .hidden() // See issue OPENDJ-448 |
| | | .buildAndAddToParser(argParser); |
| | | |
| | | displayUsage = showUsageArgument(); |
| | |
| | | return process(argParser, initializeServer, out, err); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void addTaskAttributes(List<RawAttribute> attributes) |
| | | { |
| | |
| | | return results; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getTaskId() { |
| | | // NYI. |
| | |
| | | * server process (e.g., via the tasks interface). |
| | | */ |
| | | public class ImportLDIF extends TaskTool { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** |
| | | * The buffer size that should be used when reading data from LDIF. |
| | | */ |
| | | public static final int LDIF_BUFFER_SIZE = 1048576; |
| | | |
| | | /** The buffer size that should be used when reading data from LDIF. */ |
| | | private static final int LDIF_BUFFER_SIZE = 1048576; |
| | | |
| | | /** |
| | | * The main method for ImportLDIF tool. |
| | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainImportLDIF(args, true, System.out, System.err); |
| | | |
| | | if(retCode != 0) |
| | | { |
| | | System.exit(filterExitCode(retCode)); |
| | |
| | | /** |
| | | * Processes the command-line arguments and invokes the import process. |
| | | * |
| | | * @param args The command-line arguments provided to this program. |
| | | * @return The error code. |
| | | */ |
| | | public static int mainImportLDIF(String[] args) |
| | | { |
| | | return mainImportLDIF(args, true, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | | * Processes the command-line arguments and invokes the import process. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @param initializeServer Indicates whether to initialize the server. |
| | |
| | | |
| | | private int process(String[] args, boolean initializeServer, |
| | | OutputStream outStream, OutputStream errStream) { |
| | | |
| | | PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | | JDKLogging.disableLogging(); |
| | | |
| | | // FIXME -- Need to add a mechanism for verifying the file signature. |
| | | |
| | | |
| | | // Create the command-line argument parser for use with this program. |
| | | LDAPConnectionArgumentParser argParser = |
| | | createArgParser("org.opends.server.tools.ImportLDIF", INFO_LDIFIMPORT_TOOL_DESCRIPTION.get()); |
| | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | if (argParser.usageOrVersionDisplayed()) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | // Make sure that either the "ldifFile" argument or the "templateFile" |
| | | // argument was provided, but not both. |
| | | if (ldifFiles.isPresent()) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get information about the backends defined in the server. Iterate |
| | | // through them, finding the one backend into which the LDIF should be |
| | | // imported and finding backends with subordinate base DNs that should be |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // See if the data should be read from LDIF files or generated via MakeLDIF. |
| | | LDIFImportConfig importConfig; |
| | | if (ldifFiles.isPresent()) |
| | |
| | | importConfig = new LDIFImportConfig(tf); |
| | | } |
| | | |
| | | |
| | | // Create the LDIF import configuration to use when reading the LDIF. |
| | | importConfig.setCompressed(isCompressed.isPresent()); |
| | | importConfig.setClearBackend(clearBackend.isPresent()); |
| | |
| | | DN[] baseDNs = new DN[defaultIncludeBranches.size()]; |
| | | defaultIncludeBranches.toArray(baseDNs); |
| | | |
| | | |
| | | // Acquire an exclusive lock for the backend. |
| | | try |
| | | { |
| | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | // Launch the import. |
| | | int retCode = 0; |
| | | try |
| | |
| | | retCode = 1; |
| | | } |
| | | |
| | | |
| | | // Release the exclusive lock on the backend. |
| | | try |
| | | { |
| | |
| | | retCode = 1; |
| | | } |
| | | |
| | | |
| | | // Clean up after the import by closing the import config. |
| | | importConfig.close(); |
| | | return retCode; |
| | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import javax.naming.ldap.LdapName; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg0; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.ManagedObjectDefinition; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.server.config.client.BackendCfgClient; |
| | | import org.forgerock.opendj.server.config.server.BackendCfg; |
| | | import org.opends.messages.QuickSetupMessages; |
| | |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | |
| | | /** |
| | | * Constructor for the InstallDS object. |
| | | * |
| | |
| | | * the print stream to use for standard output. |
| | | * @param err |
| | | * the print stream to use for standard error. |
| | | * @param in |
| | | * the input stream to use for standard input. |
| | | * @param tempLogFile |
| | | * the temporary log file where messages will be logged. |
| | | */ |
| | | public InstallDS(PrintStream out, PrintStream err, InputStream in, TempLogFile tempLogFile) |
| | | private InstallDS(PrintStream out, PrintStream err, TempLogFile tempLogFile) |
| | | { |
| | | super(out, err); |
| | | this.tempLogFile = tempLogFile; |
| | |
| | | */ |
| | | public static int mainCLI(String[] args, final TempLogFile tempLogFile) |
| | | { |
| | | return mainCLI(args, System.out, System.err, System.in, tempLogFile); |
| | | return mainCLI(args, System.out, System.err, tempLogFile); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param errStream |
| | | * The output stream to use for standard error, or <CODE>null</CODE> |
| | | * if standard error is not needed. |
| | | * @param inStream |
| | | * The input stream to use for standard input. |
| | | * @param tempLogFile |
| | | * the temporary log file where messages will be logged. |
| | | * @return The error code. |
| | | */ |
| | | public static int mainCLI( |
| | | String[] args, OutputStream outStream, OutputStream errStream, InputStream inStream, TempLogFile tempLogFile) |
| | | private static int mainCLI( |
| | | String[] args, OutputStream outStream, OutputStream errStream, TempLogFile tempLogFile) |
| | | { |
| | | final PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | |
| | | System.setProperty(Constants.CLI_JAVA_PROPERTY, "true"); |
| | | |
| | | final PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | | final InstallDS install = new InstallDS(out, err, inStream, tempLogFile); |
| | | final InstallDS install = new InstallDS(out, err, tempLogFile); |
| | | |
| | | return install.execute(args); |
| | | } |
| | |
| | | * the command-line arguments provided to this program. |
| | | * @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG). |
| | | */ |
| | | public int execute(String[] args) |
| | | private int execute(String[] args) |
| | | { |
| | | argParser = new InstallDSArgumentParser(InstallDS.class.getName()); |
| | | try |
| | |
| | | return printAndReturnErrorCode(e.getMessageObject()).getReturnCode(); |
| | | } |
| | | |
| | | |
| | | System.setProperty(Constants.CLI_JAVA_PROPERTY, "true"); |
| | | final Installer installer = new Installer(); |
| | | installer.setTempLogFile(tempLogFile); |
| | |
| | | println(); |
| | | } |
| | | |
| | | |
| | | private InstallReturnCode printAndReturnErrorCode(LocalizableMessage message) |
| | | { |
| | | println(message); |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isQuiet() |
| | | { |
| | | return argParser.quietArg.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() |
| | | { |
| | | return !argParser.noPromptArg.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isMenuDrivenMode() { |
| | | return true; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isAdvancedMode() { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return argParser.verboseArg.isPresent(); |
| | |
| | | { |
| | | try |
| | | { |
| | | new LdapName(baseDN); |
| | | DN.valueOf(baseDN); |
| | | } |
| | | catch (final Exception e) |
| | | catch (final LocalizedIllegalArgumentException | NullPointerException e) |
| | | { |
| | | errorMessages.add(ERR_INSTALLDS_CANNOT_PARSE_DN.get(baseDN, e.getMessage())); |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | new LdapName(dn); |
| | | DN.valueOf(dn); |
| | | if (dn.trim().length() == 0) |
| | | { |
| | | toRemove.add(dn); |
| | |
| | | final List<String> baseDNs = promptIfRequiredForDNs( |
| | | argParser.baseDNArg, lastResetBaseDN, INFO_INSTALLDS_PROMPT_BASEDN.get(), true); |
| | | return promptIfRequiredForDataOptions(baseDNs); |
| | | |
| | | } |
| | | |
| | | private ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> getOrPromptForBackendType() |
| | |
| | | INFO_INSTALLDS_CERT_OPTION_PKCS11.get() |
| | | }; |
| | | |
| | | |
| | | final MenuBuilder<Integer> builder = new MenuBuilder<>(this); |
| | | builder.setPrompt(INFO_INSTALLDS_HEADER_CERT_TYPE.get()); |
| | | |
| | |
| | | { |
| | | return argParser.getConnectTimeout(); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_JMXPORT_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_KEYSTORE_PWD_FILE_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_NUM_ENTRIES_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_PORT_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_ROOT_USER_PWD_FILE_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.Utils.addErrorMessageIfArgumentsConflict; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.addErrorMessageIfArgumentsConflict; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | BooleanArgument cliArg; |
| | | private BooleanArgument cliArg; |
| | | BooleanArgument addBaseEntryArg; |
| | | BooleanArgument showUsageArg; |
| | | private BooleanArgument showUsageArg; |
| | | BooleanArgument quietArg; |
| | | BooleanArgument noPromptArg; |
| | | BooleanArgument verboseArg; |
| | | StringArgument propertiesFileArgument; |
| | | BooleanArgument noPropertiesFileArgument; |
| | | private StringArgument propertiesFileArgument; |
| | | private BooleanArgument noPropertiesFileArgument; |
| | | BooleanArgument skipPortCheckArg; |
| | | BooleanArgument enableWindowsServiceArg; |
| | | BooleanArgument doNotStartArg; |
| | |
| | | BooleanArgument generateSelfSignedCertificateArg; |
| | | StringArgument hostNameArg; |
| | | BooleanArgument usePkcs11Arg; |
| | | FileBasedArgument directoryManagerPwdFileArg; |
| | | FileBasedArgument keyStorePasswordFileArg; |
| | | private FileBasedArgument directoryManagerPwdFileArg; |
| | | private FileBasedArgument keyStorePasswordFileArg; |
| | | IntegerArgument ldapPortArg; |
| | | IntegerArgument adminConnectorPortArg; |
| | | IntegerArgument ldapsPortArg; |
| | |
| | | StringArgument rejectedImportFileArg; |
| | | StringArgument skippedImportFileArg; |
| | | StringArgument directoryManagerDNArg; |
| | | StringArgument directoryManagerPwdStringArg; |
| | | private StringArgument directoryManagerPwdStringArg; |
| | | StringArgument useJavaKeyStoreArg; |
| | | StringArgument useJCEKSArg; |
| | | StringArgument usePkcs12Arg; |
| | | StringArgument keyStorePasswordArg; |
| | | private StringArgument keyStorePasswordArg; |
| | | StringArgument certNicknameArg; |
| | | StringArgument progNameArg; |
| | | IntegerArgument connectTimeoutArg; |
| | | private StringArgument progNameArg; |
| | | private IntegerArgument connectTimeoutArg; |
| | | BooleanArgument acceptLicense; |
| | | StringArgument backendTypeArg; |
| | | |
| | |
| | | return cliArg.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void parseArguments(String[] args) throws ArgumentException |
| | | { |
| | |
| | | private void checkPortAlreadyUsed(Set<Integer> ports, int port, Collection<LocalizableMessage> errorMessages, |
| | | Arg1<Object> errorMsg) |
| | | { |
| | | if (ports.contains(port)) |
| | | if (!ports.add(port)) |
| | | { |
| | | errorMessages.add(errorMsg.get(port)); |
| | | } |
| | | else |
| | | { |
| | | ports.add(port); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ConsoleApplication; |
| | | |
| | | |
| | | /** |
| | | * This class is used to update the scripts that are used to launch the command |
| | | * lines. We read the contents of a given properties file and we update the |
| | | * scripts setting the arguments and JVM to be used by the different scripts. |
| | | * |
| | | */ |
| | | public class JavaPropertiesTool extends ConsoleApplication |
| | | { |
| | | /** The argument parser. */ |
| | | private JavaPropertiesToolArgumentParser argParser; |
| | | |
| | | /** |
| | | * The enumeration containing the different return codes that the command-line |
| | | * can have. |
| | | * |
| | | */ |
| | | /** The enumeration containing the different return codes that the command-line can have. */ |
| | | public enum ErrorReturnCode |
| | | { |
| | | /** |
| | | * Successful setup. |
| | | */ |
| | | /** Successful setup. */ |
| | | SUCCESSFUL(0), |
| | | /** |
| | | * We did no have an error but the setup was not executed (displayed version |
| | | * or usage). |
| | | */ |
| | | /** We did no have an error but the setup was not executed (displayed version or usage). */ |
| | | SUCCESSFUL_NOP(0), |
| | | /** |
| | | * Unexpected error (potential bug). |
| | | */ |
| | | /** Unexpected error (potential bug). */ |
| | | ERROR_UNEXPECTED(1), |
| | | /** |
| | | * Cannot parse arguments or data provided by user is not valid. |
| | | */ |
| | | /** Cannot parse arguments or data provided by user is not valid. */ |
| | | ERROR_USER_DATA(2), |
| | | /** |
| | | * Error writing to destination file. |
| | | */ |
| | | /** Error writing to destination file. */ |
| | | ERROR_WRITING_FILE(3), |
| | | /** |
| | | * Conflicting command line arguments. |
| | | */ |
| | | /** Conflicting command line arguments. */ |
| | | CONFLICTING_ARGS(18); |
| | | |
| | | private int returnCode; |
| | | private final int returnCode; |
| | | |
| | | private ErrorReturnCode(int returnCode) |
| | | { |
| | | this.returnCode = returnCode; |
| | |
| | | * @param err the print stream to use for standard error. |
| | | * @param in the input stream to use for standard input. |
| | | */ |
| | | public JavaPropertiesTool(PrintStream out, PrintStream err, InputStream in) |
| | | private JavaPropertiesTool(PrintStream out, PrintStream err, InputStream in) |
| | | { |
| | | super(out, err); |
| | | } |
| | |
| | | } |
| | | println(); |
| | | |
| | | |
| | | return ErrorReturnCode.SUCCESSFUL.getReturnCode(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isQuiet() |
| | | { |
| | | return argParser.quietArg.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isMenuDrivenMode() { |
| | | return true; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isAdvancedMode() { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return true; |
| | |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | |
| | | public class JavaPropertiesToolArgumentParser extends ArgumentParser |
| | | { |
| | | /** Usage argument. */ |
| | | BooleanArgument showUsageArg; |
| | | private BooleanArgument showUsageArg; |
| | | /** Quiet argument. */ |
| | | BooleanArgument quietArg; |
| | | /** The file containing the properties. */ |
| | |
| | | */ |
| | | public class LDAPPasswordModify |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class. |
| | | */ |
| | | /** The fully-qualified name of this class. */ |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.tools.LDAPPasswordModify"; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the command-line arguments, establishes a connection to the |
| | | * Directory Server, sends the password modify request, and reads the |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the command-line arguments, establishes a connection to the |
| | | * Directory Server, sends the password modify request, and reads the |
| | | * response. |
| | | * |
| | | * @param args The command-line arguments provided to this program. |
| | | * |
| | | * @return An integer value of zero if everything completed successfully, or |
| | | * a nonzero value if an error occurred. |
| | | */ |
| | | public static int mainPasswordModify(String[] args) |
| | | { |
| | | return mainPasswordModify(args, true, System.out, System.err); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the command-line arguments, establishes a connection to the |
| | | * Directory Server, sends the password modify request, and reads the |
| | |
| | | PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | | |
| | | |
| | | // Create the arguments that will be used by this program. |
| | | BooleanArgument provideDNForAuthzID; |
| | | BooleanArgument showUsage; |
| | |
| | | StringArgument propertiesFileArgument; |
| | | BooleanArgument noPropertiesFileArgument; |
| | | |
| | | |
| | | // Initialize the argument parser. |
| | | LocalizableMessage toolDescription = INFO_LDAPPWMOD_TOOL_DESCRIPTION.get(); |
| | | ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription, |
| | |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | | |
| | | // Parse the command-line arguments provided to this program. |
| | | try |
| | | { |
| | |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | | |
| | | // If the usage or version argument was provided, |
| | | // then we don't need to do anything else. |
| | | if (argParser.usageOrVersionDisplayed()) |
| | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | // Make sure that the user didn't specify any conflicting arguments. |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the host and port. |
| | | String host = ldapHost.getValue(); |
| | | int port; |
| | |
| | | return CLIENT_SIDE_PARAM_ERROR; |
| | | } |
| | | |
| | | |
| | | // If a control string was provided, then decode the requested controls. |
| | | ArrayList<Control> controls = new ArrayList<>(); |
| | | if(controlStr.isPresent()) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Perform a basic Directory Server bootstrap if appropriate. |
| | | if (initializeServer) |
| | | { |
| | | EmbeddedUtils.initializeForClientUse(); |
| | | } |
| | | |
| | | |
| | | // Establish a connection to the Directory Server. |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions(); |
| | |
| | | { |
| | | dn = bindDN.getValue(); |
| | | pw = bindPW.getValue(); |
| | | if(pw != null && pw.equals("-")) |
| | | if ("-".equals(pw)) |
| | | { |
| | | // read the password from the stdin. |
| | | try |
| | |
| | | LDAPReader reader = connection.getLDAPReader(); |
| | | LDAPWriter writer = connection.getLDAPWriter(); |
| | | |
| | | |
| | | // Construct the password modify request. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer asn1Writer = ASN1.getWriter(builder); |
| | |
| | | new LDAPMessage(nextMessageID.getAndIncrement(), extendedRequest, |
| | | controls); |
| | | |
| | | |
| | | // Send the request to the server and read the response. |
| | | try |
| | | { |
| | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | // Read the response from the server. |
| | | LDAPMessage responseMessage = null; |
| | | try |
| | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | // Make sure that the response was acceptable. |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | responseMessage.getExtendedResponseProtocolOp(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // See if the response included any controls that we recognize, and if so |
| | | // then handle them. |
| | | List<Control> responseControls = responseMessage.getControls(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // See if the response included a generated password. |
| | | ByteString responseValue = extendedResponse.getValue(); |
| | | if (responseValue != null) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Unbind from the server and close the connection. |
| | | unbind(nextMessageID, writer); |
| | | close(reader, writer); |
| | |
| | | catch (Exception e) {} |
| | | } |
| | | } |
| | | |
| | |
| | | import com.forgerock.opendj.cli.TextTablePrinter; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.io.StringWriter; |
| | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | /** Tool for getting information and managing tasks in the Directory Server. */ |
| | | public class ManageTasks extends ConsoleApplication { |
| | |
| | | * @param args The command-line arguments provided to this program. |
| | | */ |
| | | public static void main(String[] args) { |
| | | int retCode = mainTaskInfo(args, System.in, System.out, System.err); |
| | | |
| | | int retCode = mainTaskInfo(args, System.out, System.err); |
| | | if (retCode != 0) { |
| | | System.exit(filterExitCode(retCode)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Processes the command-line arguments and invokes the process for |
| | | * displaying task information. |
| | | * |
| | | * @param args The command-line arguments provided to this program. |
| | | * @return int return code |
| | | */ |
| | | public static int mainTaskInfo(String[] args) { |
| | | return mainTaskInfo(args, System.in, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | | * Processes the command-line arguments and invokes the export process. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * @param in Input stream from which to solicit user input. |
| | | * @param out The output stream to use for standard output, or |
| | | * {@code null} if standard output is not needed. |
| | | * @param err The output stream to use for standard error, or |
| | |
| | | * @return int return code |
| | | */ |
| | | public static int mainTaskInfo(String[] args, |
| | | InputStream in, |
| | | OutputStream out, |
| | | OutputStream err, |
| | | boolean initializeServer) { |
| | | ManageTasks tool = new ManageTasks(in, out, err); |
| | | ManageTasks tool = new ManageTasks(out, err); |
| | | return tool.process(args, initializeServer); |
| | | } |
| | | |
| | |
| | | * Processes the command-line arguments and invokes the export process. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * @param in Input stream from which to solicit user input. |
| | | * @param out The output stream to use for standard output, or |
| | | * {@code null} if standard output is not needed. |
| | | * @param err The output stream to use for standard error, or |
| | | * {@code null} if standard error is not needed. |
| | | * @return int return code |
| | | */ |
| | | public static int mainTaskInfo(String[] args, |
| | | InputStream in, |
| | | private static int mainTaskInfo(String[] args, |
| | | OutputStream out, |
| | | OutputStream err) { |
| | | return mainTaskInfo(args, in, out, err, true); |
| | | return mainTaskInfo(args, out, err, true); |
| | | } |
| | | |
| | | private static final int INDENT = 2; |
| | |
| | | |
| | | /** |
| | | * Constructs a parameterized instance. |
| | | * |
| | | * @param in Input stream from which to solicit user input. |
| | | * @param out The output stream to use for standard output, or |
| | | * {@code null} if standard output is not needed. |
| | | * @param err The output stream to use for standard error, or |
| | | * {@code null} if standard error is not needed. |
| | | */ |
| | | public ManageTasks(InputStream in, OutputStream out, OutputStream err) |
| | | private ManageTasks(OutputStream out, OutputStream err) |
| | | { |
| | | super(new PrintStream(out), new PrintStream(err)); |
| | | } |
| | |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @return The error code. |
| | | */ |
| | | public int process(String[] args) |
| | | { |
| | | return process(args, true); |
| | | } |
| | | |
| | | /** |
| | | * Processes the command-line arguments and invokes the export process. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @param initializeServer Indicates whether to initialize the server. |
| | | * @return The error code. |
| | | */ |
| | | public int process(String[] args, boolean initializeServer) |
| | | private int process(String[] args, boolean initializeServer) |
| | | { |
| | | if (initializeServer) |
| | | { |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | |
| | |
| | | public class StopWindowsService |
| | | { |
| | | /** The service was successfully stopped. */ |
| | | public static final int SERVICE_STOP_SUCCESSFUL = 0; |
| | | private static final int SERVICE_STOP_SUCCESSFUL = 0; |
| | | /** The service could not be found. */ |
| | | public static final int SERVICE_NOT_FOUND = 1; |
| | | private static final int SERVICE_NOT_FOUND = 1; |
| | | /** The service could not be stopped. */ |
| | | public static final int SERVICE_STOP_ERROR = 3; |
| | | private static final int SERVICE_STOP_ERROR = 3; |
| | | |
| | | /** |
| | | * Invokes the net stop on the service corresponding to this server. |
| | |
| | | * @param errStream |
| | | * The stream to write error messages. |
| | | */ |
| | | public static int stopWindowsService(OutputStream outStream, OutputStream errStream) |
| | | private static int stopWindowsService(OutputStream outStream, OutputStream errStream) |
| | | { |
| | | NullOutputStream.wrapOrNullStream(outStream); |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | abstract class MonoServerReplicationUserData extends ReplicationUserData |
| | | { |
| | | private HostPort hostPort = new HostPort(null, 0); |
| | | private boolean useStartTLS; |
| | | private boolean useSSL; |
| | | |
| | | /** |
| | | * Returns the host name and port of the server. |
| | |
| | | { |
| | | this.hostPort = hostPort; |
| | | } |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if we must use SSL to connect to the server and |
| | | * <CODE>false</CODE> otherwise. |
| | | * @return <CODE>true</CODE> if we must use SSL to connect to the server and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | boolean useSSL() |
| | | { |
| | | return useSSL; |
| | | } |
| | | |
| | | /** |
| | | * Sets whether we must use SSL to connect to the server or not. |
| | | * @param useSSL whether we must use SSL to connect to the server or not. |
| | | */ |
| | | void setUseSSL(boolean useSSL) |
| | | { |
| | | this.useSSL = useSSL; |
| | | } |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if we must use StartTLS to connect to the server |
| | | * and <CODE>false</CODE> otherwise. |
| | | * @return <CODE>true</CODE> if we must use StartTLS to connect to the server |
| | | * and <CODE>false</CODE> otherwise. |
| | | */ |
| | | boolean useStartTLS() |
| | | { |
| | | return useStartTLS; |
| | | } |
| | | |
| | | /** |
| | | * Sets whether we must use StartTLS to connect to the server or not. |
| | | * @param useStartTLS whether we must use SSL to connect to the server or not. |
| | | */ |
| | | void setUseStartTLS(boolean useStartTLS) |
| | | { |
| | | this.useStartTLS = useStartTLS; |
| | | } |
| | | } |
| | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_BINDPWD_FILE_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.CliMessages.INFO_PORT_PLACEHOLDER; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | |
| | | /** The 'secureReplication' argument for the first server. */ |
| | | BooleanArgument secureReplicationArg; |
| | | |
| | | |
| | | /** |
| | | * Get the password which has to be used for the command to connect to this server without |
| | | * prompting the user in the enable replication subcommand. If no password was specified return |
| | |
| | | private IntegerArgument portDestinationArg; |
| | | /** The 'suffixes' global argument. */ |
| | | StringArgument baseDNsArg; |
| | | /**The 'quiet' argument. */ |
| | | /** The 'quiet' argument. */ |
| | | private BooleanArgument quietArg; |
| | | /**The 'scriptFriendly' argument. */ |
| | | /** The 'scriptFriendly' argument. */ |
| | | BooleanArgument scriptFriendlyArg; |
| | | /**Properties file argument. */ |
| | | /** Properties file argument. */ |
| | | StringArgument propertiesFileArgument; |
| | | /**No-properties file argument. */ |
| | | /** No-properties file argument. */ |
| | | BooleanArgument noPropertiesFileArgument; |
| | | /** |
| | | * The argument that the user must set to display the equivalent |
| | | * non-interactive mode argument. |
| | | */ |
| | | /** The argument that the user must set to display the equivalent non-interactive mode argument. */ |
| | | BooleanArgument displayEquivalentArgument; |
| | | /** |
| | | * The argument that allows the user to dump the equivalent non-interactive |
| | | * command to a file. |
| | | */ |
| | | /** The argument that allows the user to dump the equivalent non-interactive command to a file. */ |
| | | StringArgument equivalentCommandFileArgument; |
| | | /** The argument that the user must set to have advanced options in interactive mode. */ |
| | | BooleanArgument advancedArg; |
| | |
| | | /** The 'maximumDuration' argument for the purge of historical. */ |
| | | IntegerArgument maximumDurationArg; |
| | | |
| | | /** the 'change-number' argument for task reset-changenumber. */ |
| | | /** The 'change-number' argument for task reset-changenumber. */ |
| | | IntegerArgument resetChangeNumber; |
| | | |
| | | /** The text of the enable replication subcommand. */ |
| | |
| | | validateSubcommandOptions(buf); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int validateGlobalOptions(LocalizableMessageBuilder buf) |
| | | { |
| | |
| | | { |
| | | errors.add(ERR_REPLICATION_NOT_A_VALID_BASEDN.get(dn)); |
| | | } |
| | | if (dn.equalsIgnoreCase(Constants.REPLICATION_CHANGES_DN)) |
| | | if (Constants.REPLICATION_CHANGES_DN.equalsIgnoreCase(dn)) |
| | | { |
| | | errors.add(ERR_REPLICATION_NOT_A_USER_SUFFIX.get(Constants.REPLICATION_CHANGES_DN)); |
| | | } |
| | |
| | | ArgumentGroup argGroup) |
| | | throws ArgumentException |
| | | { |
| | | |
| | | for (Argument arg : args) |
| | | { |
| | | if (arg == advancedArg) |
| | |
| | | setFilePropertiesArgument(propertiesFileArg); |
| | | } |
| | | |
| | | /** |
| | | * Creates the enable replication subcommand and all the specific options |
| | | * for the subcommand. |
| | | */ |
| | | /** Creates the enable replication subcommand and all the specific options for the subcommand. */ |
| | | private void createEnableReplicationSubCommand() throws ArgumentException |
| | | { |
| | | createServerArgs1(); |
| | |
| | | hostNameSourceArg, portSourceArg, hostNameDestinationArg, portDestinationArg, resetChangeNumber); |
| | | } |
| | | |
| | | IntegerArgument newChangeNumberArgument() throws ArgumentException |
| | | private IntegerArgument newChangeNumberArgument() throws ArgumentException |
| | | { |
| | | return IntegerArgument.builder("change-number") |
| | | .description(INFO_DESCRIPTION_START_CHANGE_NUMBER.get()) |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.Entry; |
| | | |
| | | /** |
| | |
| | | public class Branch |
| | | { |
| | | /** The DN for this branch entry. */ |
| | | private DN branchDN; |
| | | |
| | | private final DN branchDN; |
| | | /** |
| | | * The number of entries that should be created below this branch for each |
| | | * subordinate template. |
| | | */ |
| | | private int[] numEntriesPerTemplate; |
| | | |
| | | /** The names of the subordinate templates for this branch. */ |
| | | private String[] subordinateTemplateNames; |
| | | |
| | | /** The set of subordinate templates for this branch. */ |
| | | private Template[] subordinateTemplates; |
| | | |
| | | /** The set of template lines that correspond to the RDN components. */ |
| | | private TemplateLine[] rdnLines; |
| | | |
| | | private final TemplateLine[] rdnLines; |
| | | /** The set of extra lines that should be included in this branch entry. */ |
| | | private TemplateLine[] extraLines; |
| | | |
| | |
| | | * @param extraLines The set of extra lines that should be |
| | | * included in this branch entry. |
| | | */ |
| | | public Branch(TemplateFile templateFile, DN branchDN, |
| | | private Branch(TemplateFile templateFile, DN branchDN, |
| | | String[] subordinateTemplateNames, int[] numEntriesPerTemplate, |
| | | TemplateLine[] extraLines) |
| | | { |
| | |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class defines a tag that may be used to generate random values. It has |
| | | * a number of subtypes based on the type of information that should be |
| | |
| | | * The value that indicates that the value is to be generated from a fixed |
| | | * number of characters from a given character set. |
| | | */ |
| | | public static final int RANDOM_TYPE_CHARS_FIXED = 1; |
| | | |
| | | |
| | | |
| | | private static final int RANDOM_TYPE_CHARS_FIXED = 1; |
| | | /** |
| | | * The value that indicates that the value is to be generated from a variable |
| | | * number of characters from a given character set. |
| | | */ |
| | | public static final int RANDOM_TYPE_CHARS_VARIABLE = 2; |
| | | |
| | | |
| | | |
| | | private static final int RANDOM_TYPE_CHARS_VARIABLE = 2; |
| | | /** The value that indicates that the value should be a random number. */ |
| | | public static final int RANDOM_TYPE_NUMERIC = 3; |
| | | |
| | | |
| | | |
| | | private static final int RANDOM_TYPE_NUMERIC = 3; |
| | | /** The value that indicates that the value should be a random month. */ |
| | | public static final int RANDOM_TYPE_MONTH = 4; |
| | | |
| | | |
| | | |
| | | private static final int RANDOM_TYPE_MONTH = 4; |
| | | /** The value that indicates that the value should be a telephone number. */ |
| | | public static final int RANDOM_TYPE_TELEPHONE = 5; |
| | | |
| | | |
| | | private static final int RANDOM_TYPE_TELEPHONE = 5; |
| | | |
| | | /** The character set that will be used for alphabetic characters. */ |
| | | public static final char[] ALPHA_CHARS = |
| | | private static final char[] ALPHA_CHARS = |
| | | "abcdefghijklmnopqrstuvwxyz".toCharArray(); |
| | | |
| | | |
| | | |
| | | /** The character set that will be used for numeric characters. */ |
| | | public static final char[] NUMERIC_CHARS = "01234567890".toCharArray(); |
| | | |
| | | |
| | | |
| | | private static final char[] NUMERIC_CHARS = "01234567890".toCharArray(); |
| | | /** The character set that will be used for alphanumeric characters. */ |
| | | public static final char[] ALPHANUMERIC_CHARS = |
| | | private static final char[] ALPHANUMERIC_CHARS = |
| | | "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); |
| | | |
| | | |
| | | |
| | | /** The character set that will be used for hexadecimal characters. */ |
| | | public static final char[] HEX_CHARS = "01234567890abcdef".toCharArray(); |
| | | |
| | | |
| | | |
| | | private static final char[] HEX_CHARS = "01234567890abcdef".toCharArray(); |
| | | /** The character set that will be used for base64 characters. */ |
| | | public static final char[] BASE64_CHARS = |
| | | private static final char[] BASE64_CHARS = |
| | | ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + |
| | | "01234567890+/").toCharArray(); |
| | | |
| | | |
| | | |
| | | /** The set of month names that will be used. */ |
| | | public static final String[] MONTHS = |
| | | private static final String[] MONTHS = |
| | | { |
| | | "January", |
| | | "February", |
| | |
| | | |
| | | /** The number of characters between the minimum and maximum length (inclusive). */ |
| | | private int lengthRange; |
| | | |
| | | /** The maximum number of characters to include in the value. */ |
| | | private int maxLength; |
| | | |
| | | /** The minimum number of characters to include in the value. */ |
| | | private int minLength; |
| | | |
| | | /** The type of random value that should be generated. */ |
| | | private int randomType; |
| | | |
| | | /** The maximum numeric value that should be generated. */ |
| | | private long maxValue; |
| | | |
| | | /** The minimum numeric value that should be generated. */ |
| | | private long minValue; |
| | | |
| | | /** The number of values between the minimum and maximum value (inclusive). */ |
| | | private long valueRange; |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | * Portions Copyright 2015-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class defines a data structure that provides information about the |
| | | * result of tag processing. |
| | | */ |
| | | public class TagResult |
| | | { |
| | | /** |
| | | * A tag result in which all components have a value of <CODE>true</CODE>. |
| | | */ |
| | | public static final TagResult SUCCESS_RESULT = |
| | | new TagResult(true, true, true, true); |
| | | |
| | | |
| | | |
| | | /** A tag result in which all components have a value of <CODE>true</CODE>. */ |
| | | public static final TagResult SUCCESS_RESULT = new TagResult(true, true, true, true); |
| | | /** |
| | | * A tag result that indicates the value should not be included in the entry, |
| | | * but all other processing should continue. |
| | | */ |
| | | public static final TagResult OMIT_FROM_ENTRY = |
| | | new TagResult(false, true, true, true); |
| | | |
| | | |
| | | |
| | | /** |
| | | * A tag result in whihc all components have a value of <CODE>false</CODE>. |
| | | */ |
| | | public static final TagResult STOP_PROCESSING = |
| | | new TagResult(false, false, false, false); |
| | | |
| | | |
| | | public static final TagResult OMIT_FROM_ENTRY = new TagResult(false, true, true, true); |
| | | /** A tag result in which all components have a value of <CODE>false</CODE>. */ |
| | | public static final TagResult STOP_PROCESSING = new TagResult(false, false, false, false); |
| | | |
| | | /** Indicates whether to keep processing the associated line. */ |
| | | private boolean keepProcessingLine; |
| | | |
| | | private final boolean keepProcessingLine; |
| | | /** Indicates whether to keep processing the associated entry. */ |
| | | private boolean keepProcessingEntry; |
| | | |
| | | private final boolean keepProcessingEntry; |
| | | /** Indicates whether to keep processing entries below the associated parent. */ |
| | | private boolean keepProcessingParent; |
| | | |
| | | private final boolean keepProcessingParent; |
| | | /** Indicates whether to keep processing entries for the template file. */ |
| | | private boolean keepProcessingTemplateFile; |
| | | |
| | | |
| | | private final boolean keepProcessingTemplateFile; |
| | | |
| | | /** |
| | | * Creates a new tag result object with the provided information. |
| | |
| | | * processing entries for the template |
| | | * file. |
| | | */ |
| | | public TagResult(boolean keepProcessingLine, boolean keepProcessingEntry, |
| | | private TagResult(boolean keepProcessingLine, boolean keepProcessingEntry, |
| | | boolean keepProcessingParent, |
| | | boolean keepProcessingTemplateFile) |
| | | { |
| | |
| | | this.keepProcessingTemplateFile = keepProcessingTemplateFile; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether to continue processing for the current line. If this is |
| | | * <CODE>false</CODE>, then the current line will not be included in the |
| | | * entry. It will have no impact on whehter the entry itself is included in |
| | | * entry. It will have no impact on whether the entry itself is included in |
| | | * the generated LDIF. |
| | | * |
| | | * @return <CODE>true</CODE> if the line should be included in the entry, or |
| | |
| | | return keepProcessingLine; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether to continue processing for the current entry. If this is |
| | | * <CODE>false</CODE>, then the current entry will not be included in the |
| | |
| | | return keepProcessingEntry; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether to continue processing entries below the current parent. |
| | | * If this is <CODE>false</CODE>, then the current entry will not be included, |
| | |
| | | return keepProcessingParent; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether to keep processing entries for the template file. If |
| | | * this is <CODE>false</CODE>, then LDIF processing will end immediately (and |
| | |
| | | return keepProcessingTemplateFile; |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.Map; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | /** |
| | | * This class defines a template, which is a pattern that may be used to |
| | |
| | | * The attribute types that are used in the RDN for entries generated using |
| | | * this template. |
| | | */ |
| | | private AttributeType[] rdnAttributes; |
| | | |
| | | private final AttributeType[] rdnAttributes; |
| | | /** The number of entries to create for each subordinate template. */ |
| | | private int[] numEntriesPerTemplate; |
| | | |
| | | private final int[] numEntriesPerTemplate; |
| | | /** The name for this template. */ |
| | | private String name; |
| | | private final String name; |
| | | |
| | | /** The names of the subordinate templates below this template. */ |
| | | private String[] subordinateTemplateNames; |
| | | |
| | | /** The subordinate templates below this template. */ |
| | | private Template[] subordinateTemplates; |
| | | |
| | | /** The template file that contains this template. */ |
| | | private TemplateFile templateFile; |
| | | |
| | | private final TemplateFile templateFile; |
| | | /** The set of template lines for this template. */ |
| | | private TemplateLine[] templateLines; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new template with the provided information. |
| | | * |
| | | * @param templateFile The template file that contains this |
| | | * template. |
| | | * @param name The name for this template. |
| | | * @param rdnAttributes The set of attribute types that are used |
| | | * in the RDN for entries generated using |
| | | * this template. |
| | | * @param subordinateTemplateNames The names of the subordinate templates |
| | | * below this template. |
| | | * @param numEntriesPerTemplate The number of entries to create below |
| | | * each subordinate template. |
| | | */ |
| | | public Template(TemplateFile templateFile, String name, |
| | | AttributeType[] rdnAttributes, |
| | | String[] subordinateTemplateNames, |
| | | int[] numEntriesPerTemplate) |
| | | { |
| | | this.templateFile = templateFile; |
| | | this.name = name; |
| | | this.rdnAttributes = rdnAttributes; |
| | | this.subordinateTemplateNames = subordinateTemplateNames; |
| | | this.numEntriesPerTemplate = numEntriesPerTemplate; |
| | | |
| | | templateLines = new TemplateLine[0]; |
| | | subordinateTemplates = null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new template with the provided information. |
| | |
| | | public class TemplateEntry |
| | | { |
| | | /** The branch used to generate this entry (if it is associated with a branch). */ |
| | | private Branch branch; |
| | | private final Branch branch; |
| | | /** The DN for this template entry, if it is known. */ |
| | | private DN dn; |
| | | /** The DN of the parent entry for this template entry, if it is available. */ |
| | | private DN parentDN; |
| | | private final DN parentDN; |
| | | |
| | | /** |
| | | * The set of attributes associated with this template entry, mapped from the |
| | |
| | | private final LinkedHashMap<AttributeType, ArrayList<TemplateValue>> attributes = new LinkedHashMap<>(); |
| | | |
| | | /** The template used to generate this entry (if it is associated with a template). */ |
| | | private Template template; |
| | | private final Template template; |
| | | |
| | | |
| | | /** |
| | |
| | | public TemplateEntry(Branch branch) |
| | | { |
| | | this.branch = branch; |
| | | |
| | | dn = branch.getBranchDN(); |
| | | template = null; |
| | | parentDN = null; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public TemplateEntry(Template template, DN parentDN) |
| | | { |
| | | this.branch = null; |
| | | dn = null; |
| | | this.template = template; |
| | | this.parentDN = parentDN; |
| | | } |
| | |
| | | return dn; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this entry contains one or more values for the specified |
| | | * attribute type. |
| | | * |
| | | * @param attributeType The attribute type for which to make the |
| | | * determination. |
| | | * |
| | | * @return <CODE>true</CODE> if this entry contains one or more values for |
| | | * the specified attribute type, or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean hasAttribute(AttributeType attributeType) |
| | | { |
| | | return attributes.containsKey(attributeType); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the value for the specified attribute, if defined. If the |
| | | * specified attribute has multiple values, then the first will be returned. |
| | |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileReader; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | |
| | | import java.util.Random; |
| | | import java.util.StringTokenizer; |
| | | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | /** |
| | | * This class defines a template file, which is a collection of constant |
| | | * definitions, branches, and templates. |
| | |
| | | public class TemplateFile |
| | | { |
| | | /** The name of the file holding the list of first names. */ |
| | | public static final String FIRST_NAME_FILE = "first.names"; |
| | | private static final String FIRST_NAME_FILE = "first.names"; |
| | | /** The name of the file holding the list of last names. */ |
| | | public static final String LAST_NAME_FILE = "last.names"; |
| | | |
| | | private static final String LAST_NAME_FILE = "last.names"; |
| | | |
| | | /** |
| | | * A map of the contents of various text files used during the parsing |
| | | * process, mapped from absolute path to the array of lines in the file. |
| | | */ |
| | | private final HashMap<String, String[]> fileLines = new HashMap<>(); |
| | | private final Map<String, String[]> fileLines = new HashMap<>(); |
| | | |
| | | /** The index of the next first name value that should be used. */ |
| | | private int firstNameIndex; |
| | |
| | | private final LinkedHashMap<String, Template> templates = new LinkedHashMap<>(); |
| | | |
| | | /** The random number generator for this template file. */ |
| | | private Random random; |
| | | private final Random random; |
| | | |
| | | /** The next first name that should be used. */ |
| | | private String firstName; |
| | | /** The next last name that should be used. */ |
| | | private String lastName; |
| | | |
| | | /** |
| | | * The resource path to use for filesystem elements that cannot be found |
| | | * anywhere else. |
| | | */ |
| | | private String resourcePath; |
| | | /** The resource path to use for filesystem elements that cannot be found anywhere else. */ |
| | | private final String resourcePath; |
| | | /** The path to the directory containing the template file, if available. */ |
| | | private String templatePath; |
| | | |
| | |
| | | /** The set of last names to use when generating the LDIF. */ |
| | | private String[] lastNames; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new, empty template file structure. |
| | | * |
| | | * @param resourcePath The path to the directory that may contain additional |
| | | * resource files needed during the LDIF generation |
| | | * process. |
| | | */ |
| | | public TemplateFile(String resourcePath) |
| | | { |
| | | this(resourcePath, new Random()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new, empty template file structure. |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of tags that have been registered. They will be in the |
| | | * form of a mapping between the name of the tag (in all lowercase characters) |
| | |
| | | return registeredTags; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the tag with the specified name. |
| | | * |
| | |
| | | * @return The requested tag, or <CODE>null</CODE> if no such tag has been |
| | | * registered. |
| | | */ |
| | | public Tag getTag(String lowerName) |
| | | private Tag getTag(String lowerName) |
| | | { |
| | | return registeredTags.get(lowerName); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the specified class as a tag that may be used in templates. |
| | | * |
| | | * @param tagClass The fully-qualified name of the class to register as a |
| | | * tag. |
| | | * |
| | | * @throws MakeLDIFException If a problem occurs while attempting to |
| | | * register the specified tag. |
| | | */ |
| | | public void registerTag(String tagClass) |
| | | throws MakeLDIFException |
| | | { |
| | | Class c; |
| | | try |
| | | { |
| | | c = Class.forName(tagClass); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_MAKELDIF_CANNOT_LOAD_TAG_CLASS.get(tagClass); |
| | | throw new MakeLDIFException(message, e); |
| | | } |
| | | |
| | | Tag t; |
| | | try |
| | | { |
| | | t = (Tag) c.newInstance(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_MAKELDIF_CANNOT_INSTANTIATE_TAG.get(tagClass); |
| | | throw new MakeLDIFException(message, e); |
| | | } |
| | | |
| | | String lowerName = toLowerCase(t.getName()); |
| | | if (registeredTags.containsKey(lowerName)) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_MAKELDIF_CONFLICTING_TAG_NAME.get(tagClass, t.getName()); |
| | | throw new MakeLDIFException(message); |
| | | } |
| | | else |
| | | { |
| | | registeredTags.put(lowerName, t); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the set of tags that will always be available for use in |
| | | * templates. |
| | | */ |
| | | /** Registers the set of tags that will always be available for use in templates. */ |
| | | private void registerDefaultTags() |
| | | { |
| | | Class[] defaultTagClasses = new Class[] |
| | | Class<?>[] defaultTagClasses = |
| | | { |
| | | AttributeValueTag.class, |
| | | DNTag.class, |
| | |
| | | UnderscoreParentDNTag.class |
| | | }; |
| | | |
| | | for (Class c : defaultTagClasses) |
| | | for (Class<?> c : defaultTagClasses) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of constants defined for this template file. |
| | | * |
| | |
| | | return constants; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the value of the constant with the specified name. |
| | | * |
| | | * @param lowerName The name of the constant to retrieve, in all lowercase |
| | | * characters. |
| | | * |
| | | * @return The value of the constant with the specified name, or |
| | | * <CODE>null</CODE> if there is no such constant. |
| | | */ |
| | | public String getConstant(String lowerName) |
| | | { |
| | | return constants.get(lowerName); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the provided constant for use in the template. |
| | | * |
| | | * @param name The name for the constant. |
| | | * @param value The value for the constant. |
| | | */ |
| | | public void registerConstant(String name, String value) |
| | | { |
| | | constants.put(toLowerCase(name), value); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of branches defined in this template file. |
| | | * |
| | |
| | | return branches; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the branch registered with the specified DN. |
| | | * |
| | | * @param branchDN The DN for which to retrieve the corresponding branch. |
| | | * |
| | | * @return The requested branch, or <CODE>null</CODE> if no such branch has |
| | | * been registered. |
| | | */ |
| | | public Branch getBranch(DN branchDN) |
| | | { |
| | | return branches.get(branchDN); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the provided branch in this template file. |
| | | * |
| | | * @param branch The branch to be registered. |
| | | */ |
| | | public void registerBranch(Branch branch) |
| | | { |
| | | branches.put(branch.getBranchDN(), branch); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of templates defined in this template file. |
| | | * |
| | |
| | | return templates; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the template with the specified name. |
| | | * |
| | | * @param lowerName The name of the template to retrieve, in all lowercase |
| | | * characters. |
| | | * |
| | | * @return The requested template, or <CODE>null</CODE> if there is no such |
| | | * template. |
| | | */ |
| | | public Template getTemplate(String lowerName) |
| | | { |
| | | return templates.get(lowerName); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the provided template for use in this template file. |
| | | * |
| | | * @param template The template to be registered. |
| | | */ |
| | | public void registerTemplate(Template template) |
| | | { |
| | | templates.put(toLowerCase(template.getName()), template); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the random number generator for this template file. |
| | | * |
| | |
| | | return random; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Reads the contents of the first and last name files into the appropriate |
| | | * arrays and sets up the associated index pointers. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the first and last name indexes to choose new values. The |
| | | * algorithm used is designed to ensure that the combination of first and last |
| | |
| | | firstName = firstNames[firstNameIndex++]; |
| | | lastName = lastNames[lastNameIndex++]; |
| | | |
| | | |
| | | // If we've already exhausted every possible combination, then append an |
| | | // integer to the last name. |
| | | if (nameUniquenessCounter > 1) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the first name value that should be used for the current entry. |
| | | * |
| | |
| | | return firstName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the last name value that should be used for the current entry. |
| | | * |
| | |
| | | return lastName; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the contents of the specified file as a MakeLDIF template file |
| | | * definition. |
| | |
| | | templatePath = f.getParentFile().getAbsolutePath(); |
| | | |
| | | List<String> fileLines = readLines(f); |
| | | String[] lines = new String[fileLines.size()]; |
| | | fileLines.toArray(lines); |
| | | String[] lines = fileLines.toArray(new String[fileLines.size()]); |
| | | parse(lines, warnings); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the data read from the provided input stream as a MakeLDIF template |
| | | * file definition. |
| | | * |
| | | * @param inputStream The input stream from which to read the template file |
| | | * data. |
| | | * @param warnings A list into which any warnings identified may be |
| | | * placed. |
| | | * |
| | | * @throws IOException If a problem occurs while attempting to read data |
| | | * from the provided input stream. |
| | | * |
| | | * @throws InitializationException If a problem occurs while initializing |
| | | * any of the MakeLDIF components. |
| | | * |
| | | * @throws MakeLDIFException If any other problem occurs while parsing the |
| | | * template file. |
| | | */ |
| | | public void parse(InputStream inputStream, List<LocalizableMessage> warnings) |
| | | throws IOException, InitializationException, MakeLDIFException |
| | | { |
| | | ArrayList<String> fileLines = new ArrayList<>(); |
| | | |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) |
| | | { |
| | | while (true) |
| | | { |
| | | String line = reader.readLine(); |
| | | if (line == null) |
| | | { |
| | | break; |
| | | } |
| | | fileLines.add(line); |
| | | } |
| | | } |
| | | |
| | | String[] lines = new String[fileLines.size()]; |
| | | fileLines.toArray(lines); |
| | | parse(lines, warnings); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the provided data as a MakeLDIF template file definition. |
| | | * |
| | |
| | | // no conflicts. |
| | | String className = line.substring(8).trim(); |
| | | |
| | | Class tagClass; |
| | | Class<?> tagClass; |
| | | try |
| | | { |
| | | tagClass = Class.forName(className); |
| | |
| | | LocalizableMessage message = ERR_MAKELDIF_CONFLICTING_BRANCH_DN.get(branchDN, startLineNumber); |
| | | throw new MakeLDIFException(message); |
| | | } |
| | | else |
| | | { |
| | | templateFileBranches.put(branchDN, b); |
| | | } |
| | | templateFileBranches.put(branchDN, b); |
| | | } |
| | | else if (lowerLine.startsWith("template: ")) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // If we've gotten here, then we're almost done. We just need to finalize |
| | | // the branch and template definitions and then update the template file |
| | | // variables. |
| | |
| | | templates.putAll(templateFileTemplates); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Parse a line and replace all constants within [ ] with their |
| | | * values. |
| | |
| | | throw new MakeLDIFException(message); |
| | | } |
| | | |
| | | |
| | | // Create a new branch that will be used for the verification process. |
| | | Branch branch = new Branch(this, branchDN); |
| | | |
| | |
| | | return branch; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the information contained in the provided set of lines as a MakeLDIF |
| | | * template definition. |
| | |
| | | // The first line must be "template: " followed by the template name. |
| | | String templateName = templateLines[0].substring(10).trim(); |
| | | |
| | | |
| | | // The next line may start with either "extends: ", "rdnAttr: ", or |
| | | // "subordinateTemplate: ". Keep reading until we find something that's |
| | | // not one of those. |
| | |
| | | // It's a comment, so we should ignore it. |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | TemplateLine templateLine = parseTemplateLine(line, lowerLine, |
| | | lineNumber, null, |
| | | template, tags, warnings); |
| | | template.addTemplateLine(templateLine); |
| | | } |
| | | template.addTemplateLine(parseTemplateLine(line, lowerLine, lineNumber, null, template, tags, warnings)); |
| | | } |
| | | |
| | | return template; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the provided line as a template line. Note that exactly one of the |
| | | * branch or template arguments must be non-null and the other must be null. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Define constants that specify what we're currently parsing. |
| | | final int PARSING_STATIC_TEXT = 0; |
| | | final int PARSING_REPLACEMENT_TAG = 1; |
| | |
| | | valueIsBase64); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the provided string as a replacement tag. Exactly one of the branch |
| | | * or template must be null, and the other must be non-null. |
| | |
| | | String[] args = new String[argList.size()]; |
| | | argList.toArray(args); |
| | | |
| | | |
| | | Tag newTag; |
| | | try |
| | | { |
| | |
| | | throw new MakeLDIFException(ERR_MAKELDIF_CANNOT_INSTANTIATE_NEW_TAG.get(tagName, lineNumber, e), e); |
| | | } |
| | | |
| | | |
| | | if (branch == null) |
| | | { |
| | | newTag.initializeForTemplate(this, template, args, lineNumber, warnings); |
| | | } |
| | | else if (newTag.allowedInBranch()) |
| | | { |
| | | newTag.initializeForBranch(this, branch, args, lineNumber, warnings); |
| | | } |
| | | else |
| | | { |
| | | if (newTag.allowedInBranch()) |
| | | { |
| | | newTag.initializeForBranch(this, branch, args, lineNumber, warnings); |
| | | } |
| | | else |
| | | { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_NOT_ALLOWED_IN_BRANCH.get( |
| | | newTag.getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | } |
| | | throw new MakeLDIFException(ERR_MAKELDIF_TAG_NOT_ALLOWED_IN_BRANCH.get(newTag.getName(), lineNumber)); |
| | | } |
| | | |
| | | return newTag; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the provided string as an attribute tag. Exactly one of the branch |
| | | * or template must be null, and the other must be non-null. |
| | |
| | | argList.toArray(args); |
| | | |
| | | AttributeValueTag tag = new AttributeValueTag(); |
| | | if (branch == null) |
| | | if (branch != null) |
| | | { |
| | | tag.initializeForTemplate(this, template, args, lineNumber, warnings); |
| | | tag.initializeForBranch(this, branch, args, lineNumber, warnings); |
| | | } |
| | | else |
| | | { |
| | | tag.initializeForBranch(this, branch, args, lineNumber, warnings); |
| | | tag.initializeForTemplate(this, template, args, lineNumber, warnings); |
| | | } |
| | | |
| | | return tag; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a File object based on the provided path. If the given path is |
| | | * absolute, then that absolute path will be used. If it is relative, then it |
| | |
| | | return f; |
| | | } |
| | | |
| | | |
| | | // If the provided path was absolute, then use it anyway, even though we |
| | | // couldn't find the file. |
| | | if (f.isAbsolute()) |
| | |
| | | return f; |
| | | } |
| | | |
| | | |
| | | // Try a path relative to the resource directory. |
| | | String newPath = resourcePath + File.separator + path; |
| | | f = new File(newPath); |
| | |
| | | return f; |
| | | } |
| | | |
| | | |
| | | // Try a path relative to the template directory, if it's available. |
| | | if (templatePath != null) |
| | | { |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the lines of the specified file as a string array. If the result |
| | | * is already cached, then it will be used. If the result is not cached, then |
| | |
| | | return lines; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Generates the LDIF content and writes it to the provided LDIF writer. |
| | | * |
| | |
| | | return TagResult.SUCCESS_RESULT; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.INFO_ERROR_READING_SERVER_CONFIGURATION; |
| | | import static org.opends.messages.QuickSetupMessages.INFO_NOT_AVAILABLE_LABEL; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.net.URI; |
| | |
| | | private boolean displayMustStartLegend; |
| | | |
| | | /** Prefix for log files. */ |
| | | public static final String LOG_FILE_PREFIX = "opendj-status-"; |
| | | private static final String LOG_FILE_PREFIX = "opendj-status-"; |
| | | /** Suffix for log files. */ |
| | | public static final String LOG_FILE_SUFFIX = ".log"; |
| | | private static final String LOG_FILE_SUFFIX = ".log"; |
| | | |
| | | private ApplicationTrustManager interactiveTrustManager; |
| | | private boolean useInteractiveTrustManager; |
| | |
| | | * The print stream to use for standard output. |
| | | * @param err |
| | | * The print stream to use for standard error. |
| | | * @param in |
| | | * The input stream to use for standard input. |
| | | */ |
| | | public StatusCli(PrintStream out, PrintStream err, InputStream in) |
| | | private StatusCli(PrintStream out, PrintStream err) |
| | | { |
| | | super(out, err); |
| | | } |
| | |
| | | */ |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainCLI(args, true, System.out, System.err, System.in); |
| | | int retCode = mainCLI(args, System.out, System.err); |
| | | if(retCode != 0) |
| | | { |
| | | System.exit(retCode); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that information to |
| | | * run the status tool. |
| | | * |
| | | * @param args the command-line arguments provided to this program. |
| | | * |
| | | * @return The return code. |
| | | */ |
| | | |
| | | public static int mainCLI(String[] args) |
| | | { |
| | | return mainCLI(args, true, System.out, System.err, System.in); |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that information to run |
| | | * the status tool. |
| | | * |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | * @param initializeServer |
| | | * Indicates whether to initialize the server. |
| | | * @param outStream |
| | | * The output stream to use for standard output, or {@code null} |
| | | * if standard output is not needed. |
| | | * @param errStream |
| | | * The output stream to use for standard error, or {@code null} |
| | | * if standard error is not needed. |
| | | * @param inStream |
| | | * The input stream to use for standard input. |
| | | * @return The return code. |
| | | */ |
| | | public static int mainCLI(String[] args, boolean initializeServer, |
| | | OutputStream outStream, OutputStream errStream, InputStream inStream) |
| | | public static int mainCLI(String[] args, OutputStream outStream, OutputStream errStream) |
| | | { |
| | | PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | |
| | | t.printStackTrace(); |
| | | } |
| | | |
| | | final StatusCli statusCli = new StatusCli(out, err, inStream); |
| | | final StatusCli statusCli = new StatusCli(out, err); |
| | | int retCode = statusCli.execute(args); |
| | | if (retCode == 0) |
| | | { |
| | |
| | | * The command-line arguments provided to this program. |
| | | * @return The return code of the process. |
| | | */ |
| | | public int execute(String[] args) { |
| | | private int execute(String[] args) { |
| | | argParser = new StatusCliArgumentParser(StatusCli.class.getName()); |
| | | try { |
| | | argParser.initializeGlobalArguments(getOutputStream()); |
| | |
| | | String bindDn = null; |
| | | String bindPwd = null; |
| | | |
| | | ManagementContext mContext = null; |
| | | |
| | | // This is done because we do not need to ask the user about these |
| | | // parameters. We force their presence in the |
| | | // LDAPConnectionConsoleInteraction, this done, it will not prompt |
| | |
| | | argParser.displayMessageAndUsageReference(getErrStream(), e.getMessageObject()); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } |
| | | |
| | | boolean managementContextOpened = false; |
| | | try |
| | | { |
| | | if (argParser.isInteractive()) |
| | |
| | | } |
| | | if (bindPwd != null && !bindPwd.isEmpty()) |
| | | { |
| | | mContext = getManagementContextFromConnection(ci); |
| | | interactiveTrustManager = ci.getTrustManager(); |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | try (ManagementContext mContext = getManagementContextFromConnection(ci)) |
| | | { |
| | | managementContextOpened = true; |
| | | interactiveTrustManager = ci.getTrustManager(); |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | } catch (ClientException e) { |
| | | println(e.getMessageObject()); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } finally { |
| | | closeSilently(mContext); |
| | | } |
| | | |
| | | if (mContext != null) |
| | | if (managementContextOpened) |
| | | { |
| | | try (ConnectionWrapper conn = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd)) |
| | | { |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools.tasks; |
| | | |
| | |
| | | */ |
| | | public class TaskClient { |
| | | |
| | | /** |
| | | * Connection through which task scheduling will take place. |
| | | */ |
| | | protected LDAPConnection connection; |
| | | |
| | | /** |
| | | * Keeps track of message IDs. |
| | | */ |
| | | /** Connection through which task scheduling will take place. */ |
| | | private LDAPConnection connection; |
| | | /** Keeps track of message IDs. */ |
| | | private final AtomicInteger nextMessageID = new AtomicInteger(0); |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static String getTaskID(List<RawAttribute> taskAttributes) |
| | | { |
| | | String taskID = null; |
| | | |
| | | RawAttribute recurringIDAttr = getAttribute(ATTR_RECURRING_TASK_ID, |
| | | taskAttributes); |
| | | |
| | | RawAttribute recurringIDAttr = getAttribute(ATTR_RECURRING_TASK_ID, taskAttributes); |
| | | if (recurringIDAttr != null) { |
| | | taskID = recurringIDAttr.getValues().get(0).toString(); |
| | | } else { |
| | | RawAttribute taskIDAttr = getAttribute(ATTR_TASK_ID, |
| | | taskAttributes); |
| | | taskID = taskIDAttr.getValues().get(0).toString(); |
| | | return recurringIDAttr.getValues().get(0).toString(); |
| | | } |
| | | |
| | | return taskID; |
| | | RawAttribute taskIDAttr = getAttribute(ATTR_TASK_ID, taskAttributes); |
| | | return taskIDAttr.getValues().get(0).toString(); |
| | | } |
| | | |
| | | private static RawAttribute getAttribute(String attrName, |
| | |
| | | throw new LDAPException( |
| | | LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, |
| | | ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get()); |
| | | } else { |
| | | opType = responseMessage.getProtocolOpType(); |
| | | if (opType == LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY) { |
| | | SearchResultEntryProtocolOp searchEntryOp = |
| | | responseMessage.getSearchResultEntryProtocolOp(); |
| | | SearchResultEntry entry = searchEntryOp.toSearchResultEntry(); |
| | | entries.add(entry); |
| | | } |
| | | } |
| | | opType = responseMessage.getProtocolOpType(); |
| | | if (opType == LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY) |
| | | { |
| | | SearchResultEntryProtocolOp searchEntryOp = responseMessage.getSearchResultEntryProtocolOp(); |
| | | SearchResultEntry entry = searchEntryOp.toSearchResultEntry(); |
| | | entries.add(entry); |
| | | } |
| | | } |
| | | while (opType != LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE); |
| | | |
| | | List<TaskEntry> taskEntries = new ArrayList<>(entries.size()); |
| | | for (Entry entry : entries) { |
| | | taskEntries.add(new TaskEntry(entry)); |
| | |
| | | if (responseMessage == null) { |
| | | LocalizableMessage message = ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get(); |
| | | throw new LDAPException(UNAVAILABLE.intValue(), message); |
| | | } else { |
| | | opType = responseMessage.getProtocolOpType(); |
| | | if (opType == LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY) { |
| | | SearchResultEntryProtocolOp searchEntryOp = |
| | | responseMessage.getSearchResultEntryProtocolOp(); |
| | | entry = searchEntryOp.toSearchResultEntry(); |
| | | } |
| | | } |
| | | opType = responseMessage.getProtocolOpType(); |
| | | if (opType == LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY) |
| | | { |
| | | SearchResultEntryProtocolOp searchEntryOp = responseMessage.getSearchResultEntryProtocolOp(); |
| | | entry = searchEntryOp.toSearchResultEntry(); |
| | | } |
| | | } |
| | | while (opType != LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE); |
| | |
| | | return new TaskEntry(entry); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Changes that the state of the task in the backend to a canceled state. |
| | | * |
| | |
| | | |
| | | TaskEntry entry = getTaskEntry(id); |
| | | TaskState state = entry.getTaskState(); |
| | | if (state != null) { |
| | | if (!TaskState.isDone(state)) { |
| | | |
| | | ByteString dn = ByteString.valueOfUtf8(entry.getDN().toString()); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | |
| | | String newState; |
| | | if (TaskState.isPending(state)) { |
| | | newState = TaskState.CANCELED_BEFORE_STARTING.name(); |
| | | } else { |
| | | newState = TaskState.STOPPED_BY_ADMINISTRATOR.name(); |
| | | } |
| | | LDAPAttribute attr = new LDAPAttribute(ATTR_TASK_STATE, newState); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, attr)); |
| | | |
| | | ModifyRequestProtocolOp modRequest = |
| | | new ModifyRequestProtocolOp(dn, mods); |
| | | LDAPMessage requestMessage = |
| | | new LDAPMessage(nextMessageID.getAndIncrement(), modRequest, null); |
| | | |
| | | writer.writeMessage(requestMessage); |
| | | |
| | | LDAPMessage responseMessage = reader.readMessage(); |
| | | |
| | | if (responseMessage == null) { |
| | | LocalizableMessage message = ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get(); |
| | | throw new LDAPException(UNAVAILABLE.intValue(), message); |
| | | } |
| | | |
| | | if (responseMessage.getProtocolOpType() != |
| | | LDAPConstants.OP_TYPE_MODIFY_RESPONSE) |
| | | { |
| | | throw new LDAPException( |
| | | LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, |
| | | ERR_TASK_CLIENT_INVALID_RESPONSE_TYPE.get( |
| | | responseMessage.getProtocolOpName())); |
| | | } |
| | | |
| | | ModifyResponseProtocolOp modResponse = |
| | | responseMessage.getModifyResponseProtocolOp(); |
| | | LocalizableMessage errorMessage = modResponse.getErrorMessage(); |
| | | if (errorMessage != null) { |
| | | throw new LDAPException( |
| | | LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, |
| | | errorMessage); |
| | | } |
| | | } else if (TaskState.isRecurring(state)) { |
| | | |
| | | ByteString dn = ByteString.valueOfUtf8(entry.getDN().toString()); |
| | | DeleteRequestProtocolOp deleteRequest = |
| | | new DeleteRequestProtocolOp(dn); |
| | | |
| | | LDAPMessage requestMessage = new LDAPMessage( |
| | | nextMessageID.getAndIncrement(), deleteRequest, null); |
| | | |
| | | writer.writeMessage(requestMessage); |
| | | |
| | | LDAPMessage responseMessage = reader.readMessage(); |
| | | |
| | | if (responseMessage == null) { |
| | | LocalizableMessage message = ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get(); |
| | | throw new LDAPException(UNAVAILABLE.intValue(), message); |
| | | } |
| | | |
| | | if (responseMessage.getProtocolOpType() != |
| | | LDAPConstants.OP_TYPE_DELETE_RESPONSE) |
| | | { |
| | | throw new LDAPException( |
| | | LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, |
| | | ERR_TASK_CLIENT_INVALID_RESPONSE_TYPE.get( |
| | | responseMessage.getProtocolOpName())); |
| | | } |
| | | |
| | | DeleteResponseProtocolOp deleteResponse = |
| | | responseMessage.getDeleteResponseProtocolOp(); |
| | | LocalizableMessage errorMessage = deleteResponse.getErrorMessage(); |
| | | if (errorMessage != null) { |
| | | throw new LDAPException( |
| | | LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, |
| | | errorMessage); |
| | | } |
| | | } else { |
| | | throw new TaskClientException( |
| | | ERR_TASK_CLIENT_UNCANCELABLE_TASK.get(id)); |
| | | } |
| | | } else { |
| | | throw new TaskClientException( |
| | | ERR_TASK_CLIENT_TASK_STATE_UNKNOWN.get(id)); |
| | | if (state == null) |
| | | { |
| | | throw new TaskClientException(ERR_TASK_CLIENT_TASK_STATE_UNKNOWN.get(id)); |
| | | } |
| | | if (!TaskState.isDone(state)) |
| | | { |
| | | cancelNotDoneTask(entry, state, writer, reader); |
| | | } |
| | | else if (TaskState.isRecurring(state)) |
| | | { |
| | | cancelRecurringTask(entry, writer, reader); |
| | | } |
| | | else |
| | | { |
| | | throw new TaskClientException(ERR_TASK_CLIENT_UNCANCELABLE_TASK.get(id)); |
| | | } |
| | | } |
| | | |
| | | private void cancelNotDoneTask(TaskEntry entry, TaskState state, LDAPWriter writer, LDAPReader reader) |
| | | throws IOException, LDAPException |
| | | { |
| | | ByteString dn = ByteString.valueOfUtf8(entry.getDN().toString()); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | |
| | | String newState; |
| | | if (TaskState.isPending(state)) |
| | | { |
| | | newState = TaskState.CANCELED_BEFORE_STARTING.name(); |
| | | } |
| | | else |
| | | { |
| | | newState = TaskState.STOPPED_BY_ADMINISTRATOR.name(); |
| | | } |
| | | LDAPAttribute attr = new LDAPAttribute(ATTR_TASK_STATE, newState); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, attr)); |
| | | |
| | | ModifyRequestProtocolOp modRequest = new ModifyRequestProtocolOp(dn, mods); |
| | | LDAPMessage requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(), modRequest, null); |
| | | |
| | | writer.writeMessage(requestMessage); |
| | | |
| | | LDAPMessage responseMessage = reader.readMessage(); |
| | | if (responseMessage == null) |
| | | { |
| | | LocalizableMessage message = ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get(); |
| | | throw new LDAPException(UNAVAILABLE.intValue(), message); |
| | | } |
| | | if (responseMessage.getProtocolOpType() != LDAPConstants.OP_TYPE_MODIFY_RESPONSE) |
| | | { |
| | | throw new LDAPException(LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, ERR_TASK_CLIENT_INVALID_RESPONSE_TYPE |
| | | .get(responseMessage.getProtocolOpName())); |
| | | } |
| | | |
| | | ModifyResponseProtocolOp modResponse = responseMessage.getModifyResponseProtocolOp(); |
| | | LocalizableMessage errorMessage = modResponse.getErrorMessage(); |
| | | if (errorMessage != null) |
| | | { |
| | | throw new LDAPException(LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, errorMessage); |
| | | } |
| | | } |
| | | |
| | | private void cancelRecurringTask(TaskEntry entry, LDAPWriter writer, LDAPReader reader) |
| | | throws IOException, LDAPException |
| | | { |
| | | ByteString dn = ByteString.valueOfUtf8(entry.getDN().toString()); |
| | | DeleteRequestProtocolOp deleteRequest = new DeleteRequestProtocolOp(dn); |
| | | LDAPMessage requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(), deleteRequest, null); |
| | | writer.writeMessage(requestMessage); |
| | | |
| | | LDAPMessage responseMessage = reader.readMessage(); |
| | | if (responseMessage == null) |
| | | { |
| | | LocalizableMessage message = ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get(); |
| | | throw new LDAPException(UNAVAILABLE.intValue(), message); |
| | | } |
| | | if (responseMessage.getProtocolOpType() != LDAPConstants.OP_TYPE_DELETE_RESPONSE) |
| | | { |
| | | LocalizableMessage msg = ERR_TASK_CLIENT_INVALID_RESPONSE_TYPE.get(responseMessage.getProtocolOpName()); |
| | | throw new LDAPException(LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, msg); |
| | | } |
| | | |
| | | DeleteResponseProtocolOp deleteResponse = responseMessage.getDeleteResponseProtocolOp(); |
| | | LocalizableMessage errorMessage = deleteResponse.getErrorMessage(); |
| | | if (errorMessage != null) |
| | | { |
| | | throw new LDAPException(LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR, errorMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Writes a search to the directory writer. |
| | |
| | | // Send the request to the server and read the response. |
| | | writer.writeMessage(requestMessage); |
| | | } |
| | | |
| | | } |
| | |
| | | class FileManager |
| | | { |
| | | /** Describes the approach taken to deleting a file or directory. */ |
| | | public static enum DeletionPolicy |
| | | private static enum DeletionPolicy |
| | | { |
| | | /** Delete the file or directory immediately. */ |
| | | DELETE_IMMEDIATELY, |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.server.tools.upgrade; |
| | |
| | | * @return <CODE>true</CODE> if the license has been accepted by the user |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | static boolean getApproval() |
| | | private static boolean getApproval() |
| | | { |
| | | return approved; |
| | | } |
| | |
| | | * The call-back handler for interacting with the upgrade |
| | | * application. |
| | | */ |
| | | public UpgradeContext(final BuildVersion fromVersion, |
| | | private UpgradeContext(final BuildVersion fromVersion, |
| | | final BuildVersion toVersion, CallbackHandler handler) |
| | | { |
| | | this.fromVersion = fromVersion; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the callback handler. |
| | | * |
| | | * @return The actual callback handler. |
| | | */ |
| | | CallbackHandler getHandler() |
| | | { |
| | | return handler; |
| | | } |
| | | |
| | | /** |
| | | * Returns the status of the interactive mode. |
| | | * |
| | | * @return {@code true} if interactive mode is activated. |
| | |
| | | static int countErrors; |
| | | |
| | | /** Contains all the indexes to rebuild. */ |
| | | static Set<String> indexesToRebuild = new HashSet<>(); |
| | | private static final Set<String> indexesToRebuild = new HashSet<>(); |
| | | |
| | | /** A flag to avoid rebuild single indexes if 'rebuild all' is selected. */ |
| | | static boolean isRebuildAllIndexesIsPresent; |
| | | |
| | | private static boolean isRebuildAllIndexesIsPresent; |
| | | /** A flag for marking 'rebuild all' task accepted by user. */ |
| | | static boolean isRebuildAllIndexesTaskAccepted; |
| | | private static boolean isRebuildAllIndexesTaskAccepted; |
| | | |
| | | private static final List<String> SUPPORTED_LOCALES_FOR_3_0_0 = Arrays.asList( |
| | | "ca_ES", "de", "es", "fr", "ja", "ko", "pl", "zh_CN", "zh_TW"); |
| | |
| | | } |
| | | |
| | | /** This inner classes causes JE to be lazily linked and prevents runtime errors if JE is not in the classpath. */ |
| | | static final class JEHelper { |
| | | private static final class JEHelper { |
| | | private static ClientException clientException(final File backendDirectory, final DatabaseException e) { |
| | | logger.error(LocalizableMessage.raw(StaticUtils.stackTraceToString(e))); |
| | | return new ClientException(ReturnCode.CONSTRAINT_VIOLATION, |
| | | INFO_UPGRADE_TASK_MIGRATE_JE_ENV_UNREADABLE.get(backendDirectory), e); |
| | | } |
| | | |
| | | static Set<String> listDatabases(final File backendDirectory) throws ClientException { |
| | | private static Set<String> listDatabases(final File backendDirectory) throws ClientException { |
| | | try (Environment je = new Environment(backendDirectory, null)) { |
| | | Set<String> databases = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); |
| | | databases.addAll(je.getDatabaseNames()); |
| | |
| | | } |
| | | } |
| | | |
| | | static void migrateDatabases(final File envDir, final Map<String, String> renamedDbs) throws ClientException { |
| | | private static void migrateDatabases(final File envDir, final Map<String, String> renamedDbs) |
| | | throws ClientException { |
| | | EnvironmentConfig config = new EnvironmentConfig().setTransactional(true); |
| | | try (Environment je = new Environment(envDir, config)) { |
| | | final Transaction txn = je.beginTransaction(null, new TransactionConfig()); |
| | |
| | | } |
| | | } |
| | | }; |
| | | |
| | | } |
| | | |
| | | /** Prevent instantiation. */ |
| | |
| | | import static org.opends.server.tools.upgrade.Installation.*; |
| | | import static org.opends.server.util.ChangeOperationType.*; |
| | | |
| | | /** |
| | | * Common utility methods needed by the upgrade. |
| | | */ |
| | | /** Common utility methods needed by the upgrade. */ |
| | | final class UpgradeUtils |
| | | { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The config folder of the current instance. */ |
| | |
| | | /** The config/schema folder of the current instance. */ |
| | | static final File configSchemaDirectory = new File(configDirectory, SCHEMA_PATH_RELATIVE); |
| | | /** The template folder of the current installation. */ |
| | | static final File templateDirectory = new File(getInstallationPath(), TEMPLATE_RELATIVE_PATH); |
| | | private static final File templateDirectory = new File(getInstallationPath(), TEMPLATE_RELATIVE_PATH); |
| | | /** The template/config folder of the current installation. */ |
| | | static final File templateConfigDirectory = new File(templateDirectory, CONFIG_PATH_RELATIVE); |
| | | /** The template/config/schema folder of the current installation. */ |
| | |
| | | static final File binDirectory = new File(getInstallationPath(), UNIX_BINARIES_PATH_RELATIVE); |
| | | /** The bat folder of the current installation. */ |
| | | static final File batDirectory = new File(getInstallationPath(), WINDOWS_BINARIES_PATH_RELATIVE); |
| | | /** The server configuration file path */ |
| | | /** The server configuration file path. */ |
| | | static final String CONFIG_FILE_PATH = |
| | | Paths.get(configDirectory.getAbsolutePath(), CURRENT_CONFIG_FILE_NAME).toString(); |
| | | |
| | |
| | | * |
| | | * @return the path of the installation of the directory server. |
| | | */ |
| | | static String getInstallPathFromClasspath() |
| | | private static String getInstallPathFromClasspath() |
| | | { |
| | | String installPath = DirectoryServer.getServerRoot(); |
| | | if (installPath != null) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns the absolute path for the given parentPath and relativePath. |
| | | * |
| | | * @param parentPath |
| | | * the parent path. |
| | | * @param relativePath |
| | | * the relative path. |
| | | * @return the absolute path for the given parentPath and relativePath. |
| | | */ |
| | | static String getPath(final String parentPath, final String relativePath) |
| | | { |
| | | return getPath(new File(new File(parentPath), relativePath)); |
| | | } |
| | | |
| | | static File getFileForPath(String path) |
| | | { |
| | | final File f = new File(path); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Determines whether one file is the parent of another. |
| | | * |
| | | * @param ancestor |
| | | * possible parent of <code>descendant</code> |
| | | * @param descendant |
| | | * possible child 0f <code>ancestor</code> |
| | | * @return return true if ancestor is a parent of descendant |
| | | */ |
| | | static boolean isParentOf(final File ancestor, File descendant) |
| | | { |
| | | if (ancestor != null) |
| | | { |
| | | if (ancestor.equals(descendant)) |
| | | { |
| | | return false; |
| | | } |
| | | while (descendant != null && !ancestor.equals(descendant)) |
| | | { |
| | | descendant = descendant.getParentFile(); |
| | | } |
| | | } |
| | | return ancestor != null && descendant != null; |
| | | } |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if the first provided path is under the second |
| | | * path in the file system. |
| | | * @param descendant the descendant candidate path. |
| | | * @param path the path. |
| | | * @return <CODE>true</CODE> if the first provided path is under the second |
| | | * path in the file system; <code>false</code> otherwise or if |
| | | * either of the files are null |
| | | */ |
| | | static boolean isDescendant(File descendant, File path) { |
| | | if (descendant != null && path != null) { |
| | | File parent = descendant.getParentFile(); |
| | | while (parent != null) { |
| | | if (path.equals(parent)) { |
| | | return true; |
| | | } |
| | | parent = parent.getParentFile(); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Returns the instance root directory (the path where the instance is |
| | | * installed). |
| | | * |
| | |
| | | * |
| | | * @return A schema which may used in the upgrade context. |
| | | */ |
| | | static Schema getUpgradeSchema() { |
| | | private static Schema getUpgradeSchema() |
| | | { |
| | | final SchemaBuilder sb = new SchemaBuilder(Schema.getCoreSchema()) |
| | | .setOption(DEFAULT_MATCHING_RULE_OID, getCaseExactMatchingRule().getOID()) |
| | | .setOption(DEFAULT_SYNTAX_OID, getDirectoryStringSyntax().getOID()); |
| | |
| | | mayInvoke=true) |
| | | public final class AuthenticationInfo |
| | | { |
| | | |
| | | /** Indicates whether this connection is currently authenticated. */ |
| | | private boolean isAuthenticated; |
| | | |
| | | /** Indicates whether this connection is authenticated as a root user. */ |
| | | private boolean isRoot; |
| | | |
| | | /** |
| | | * Indicates whether the user's password must be changed before any other |
| | | * operation will be allowed. |
| | |
| | | |
| | | /** The entry of the user that is currently authenticated. */ |
| | | private Entry authenticationEntry; |
| | | |
| | | /** |
| | | * The entry of the user that will be used as the default authorization |
| | | * identity. |
| | | */ |
| | | /** The entry of the user that will be used as the default authorization identity. */ |
| | | private Entry authorizationEntry; |
| | | |
| | | /** The type of authentication performed on this connection. */ |
| | | private AuthenticationType authenticationType; |
| | | |
| | | /** The SASL mechanism used to authenticate. */ |
| | | private String saslMechanism; |
| | | |
| | | /** The bind DN used to authenticate using simple authentication. */ |
| | | private DN simpleBindDN; |
| | | private final DN simpleBindDN; |
| | | |
| | | /** |
| | | * Creates a new set of authentication information to be used for |
| | | * unauthenticated clients. |
| | | */ |
| | | /** Creates a new set of authentication information to be used for unauthenticated clients. */ |
| | | public AuthenticationInfo() |
| | | { |
| | | isAuthenticated = false; |
| | |
| | | saslMechanism = null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new set of authentication information to be used for |
| | | * clients that are authenticated internally. |
| | |
| | | this.authenticationType = AuthenticationType.SIMPLE; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new set of authentication information to be used for |
| | | * clients that have authenticated using a SASL mechanism. |
| | |
| | | this.saslMechanism = saslMechanism; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new set of authentication information to be used for |
| | | * clients that have authenticated using a SASL mechanism. |
| | |
| | | this.saslMechanism = saslMechanism; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this client has successfully authenticated to |
| | | * the server. |
| | |
| | | return isAuthenticated; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this client should be considered a root user. |
| | | * |
| | |
| | | return isRoot; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the authenticated user must change his/her |
| | | * password before any other operation will be allowed. |
| | |
| | | return mustChangePassword; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether the authenticated user must change his/her |
| | | * password before any other operation will be allowed. |
| | |
| | | this.mustChangePassword = mustChangePassword; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this client has authenticated using the |
| | | * specified authentication type. |
| | |
| | | return this.authenticationType == authenticationType; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the entry for the user as whom the client is |
| | | * authenticated. |
| | |
| | | return authenticationEntry; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the DN of the user as whom the client is authenticated. |
| | | * |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets the DN of the user as whom the client is authenticated, |
| | | * does nothing if the client is unauthenticated. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the entry for the user that should be used as the |
| | | * default authorization identity. |
| | |
| | | return authorizationEntry; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the DN for the user that should be used as the default |
| | | * authorization identity. |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets the DN for the user that should be used as the default |
| | | * authorization identity, does nothing if the client is |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the bind DN that the client used for simple |
| | | * authentication. |
| | |
| | | return simpleBindDN; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the client is currently authenticated using the |
| | | * specified SASL mechanism. |
| | |
| | | return buffer.toString(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Appends a string representation of this authentication info |
| | | * structure to the provided buffer. |
| | |
| | | * @param buffer The buffer to which the information is to be |
| | | * appended. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | buffer.append("AuthenticationInfo(isAuthenticated="); |
| | | buffer.append(isAuthenticated); |
| | |
| | | buffer.append(")"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a duplicate of this {@code AuthenticationInfo} object |
| | | * with the new authentication and authorization entries. |
| | |
| | | return authInfo; |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | |
| | | * the configuration entry for the backend associated with the |
| | | * backups in this directory. |
| | | */ |
| | | public static final String PROPERTY_BACKEND_CONFIG_DN = "backend_dn"; |
| | | private static final String PROPERTY_BACKEND_CONFIG_DN = "backend_dn"; |
| | | |
| | | /** |
| | | * The DN of the configuration entry for the backend with which this |
| | |
| | | * Information about the set of backups available within the |
| | | * specified directory. |
| | | */ |
| | | public BackupDirectory(String path, DN configEntryDN, LinkedHashMap<String, BackupInfo> backups) |
| | | private BackupDirectory(String path, DN configEntryDN, LinkedHashMap<String, BackupInfo> backups) |
| | | { |
| | | this.path = path; |
| | | this.configEntryDN = configEntryDN; |
| | |
| | | // Iterate through all of the backups and add them to the file. |
| | | for (BackupInfo backup : backups.values()) |
| | | { |
| | | List<String> backupLines = backup.encode(); |
| | | for (String line : backupLines) |
| | | for (String line : backup.encode()) |
| | | { |
| | | writer.write(line); |
| | | writer.newLine(); |
| | |
| | | import java.util.HashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.TimeZone; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The name of the property that holds the date that the backup was created. */ |
| | | public static final String PROPERTY_BACKUP_DATE = "backup_date"; |
| | | private static final String PROPERTY_BACKUP_DATE = "backup_date"; |
| | | /** The name of the property that holds the backup ID in encoded representations. */ |
| | | public static final String PROPERTY_BACKUP_ID = "backup_id"; |
| | | private static final String PROPERTY_BACKUP_ID = "backup_id"; |
| | | |
| | | /** The name of the property that holds the incremental flag in encoded representations. */ |
| | | public static final String PROPERTY_IS_INCREMENTAL = "incremental"; |
| | | private static final String PROPERTY_IS_INCREMENTAL = "incremental"; |
| | | /** The name of the property that holds the compressed flag in encoded representations. */ |
| | | public static final String PROPERTY_IS_COMPRESSED = "compressed"; |
| | | private static final String PROPERTY_IS_COMPRESSED = "compressed"; |
| | | /** The name of the property that holds the encrypted flag in encoded representations. */ |
| | | public static final String PROPERTY_IS_ENCRYPTED = "encrypted"; |
| | | private static final String PROPERTY_IS_ENCRYPTED = "encrypted"; |
| | | /** The name of the property that holds the unsigned hash in encoded representations. */ |
| | | public static final String PROPERTY_UNSIGNED_HASH = "hash"; |
| | | private static final String PROPERTY_UNSIGNED_HASH = "hash"; |
| | | /** The name of the property that holds the signed hash in encoded representations. */ |
| | | public static final String PROPERTY_SIGNED_HASH = "signed_hash"; |
| | | private static final String PROPERTY_SIGNED_HASH = "signed_hash"; |
| | | /** |
| | | * The name of the property that holds the set of dependencies in |
| | | * encoded representations (one dependency per instance). |
| | | */ |
| | | public static final String PROPERTY_DEPENDENCY = "dependency"; |
| | | private static final String PROPERTY_DEPENDENCY = "dependency"; |
| | | /** |
| | | * The prefix to use with custom backup properties. The name of the |
| | | * property will be appended to this prefix. |
| | | */ |
| | | public static final String PROPERTY_CUSTOM_PREFIX = "property."; |
| | | private static final String PROPERTY_CUSTOM_PREFIX = "property."; |
| | | |
| | | /** The backup directory with which this backup info structure is associated. */ |
| | | private BackupDirectory backupDirectory; |
| | | private final BackupDirectory backupDirectory; |
| | | |
| | | /** Indicates whether this backup is compressed. */ |
| | | private boolean isCompressed; |
| | | private final boolean isCompressed; |
| | | /** Indicates whether this backup is encrypted. */ |
| | | private boolean isEncrypted; |
| | | private final boolean isEncrypted; |
| | | /** Indicates whether this is an incremental backup. */ |
| | | private boolean isIncremental; |
| | | private final boolean isIncremental; |
| | | |
| | | /** The signed hash for this backup, if appropriate. */ |
| | | private byte[] signedHash; |
| | | private final byte[] signedHash; |
| | | /** The unsigned hash for this backup, if appropriate. */ |
| | | private byte[] unsignedHash; |
| | | private final byte[] unsignedHash; |
| | | |
| | | /** The time that this backup was created. */ |
| | | private Date backupDate; |
| | | private final Date backupDate; |
| | | |
| | | /** The set of backup ID(s) on which this backup is dependent. */ |
| | | private HashSet<String> dependencies; |
| | | private final Set<String> dependencies; |
| | | |
| | | /** |
| | | * The set of additional properties associated with this backup. |
| | |
| | | * the name must not contain an equal sign and neither the name nor |
| | | * the value may contain line breaks; |
| | | */ |
| | | private HashMap<String,String> backupProperties; |
| | | private final Map<String, String> backupProperties; |
| | | |
| | | /** The unique ID for this backup. */ |
| | | private String backupID; |
| | | private final String backupID; |
| | | |
| | | /** |
| | | * Creates a new backup info structure with the provided |
| | |
| | | * @return The set of the backup IDs for the backups on which this |
| | | * backup is dependent. |
| | | */ |
| | | public HashSet<String> getDependencies() |
| | | public Set<String> getDependencies() |
| | | { |
| | | return dependencies; |
| | | } |
| | |
| | | * @return A set of additional properties that should be associated |
| | | * with this backup. |
| | | */ |
| | | public HashMap<String,String> getBackupProperties() |
| | | public Map<String, String> getBackupProperties() |
| | | { |
| | | return backupProperties; |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the value of the backup property with the specified |
| | | * name. |
| | | * |
| | | * @param name The name of the backup property to retrieve. |
| | | * |
| | | * @return The value of the backup property with the specified |
| | | * name, or <CODE>null</CODE> if there is no such property. |
| | | */ |
| | | public String getBackupProperty(String name) |
| | | { |
| | | return backupProperties.get(name); |
| | | } |
| | | |
| | | /** |
| | | * Encodes this backup info structure to a multi-line string |
| | | * representation. This representation may be parsed by the |
| | | * <CODE>decode</CODE> method to reconstruct the structure. |
| | |
| | | * @return A multi-line string representation of this backup info |
| | | * structure. |
| | | */ |
| | | public LinkedList<String> encode() |
| | | public List<String> encode() |
| | | { |
| | | LinkedList<String> list = new LinkedList<>(); |
| | | SimpleDateFormat dateFormat = |
| | |
| | | * @param buffer The buffer to which the information should be |
| | | * written. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | LinkedList<String> lines = encode(); |
| | | for (String line : lines) |
| | | for (String line : encode()) |
| | | { |
| | | buffer.append(line); |
| | | buffer.append(EOL); |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.SchemaElement; |
| | | |
| | |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | |
| | | import static org.forgerock.util.Reject.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | |
| | | * user-defined name for that class. |
| | | */ |
| | | private final Set<ObjectClass> auxiliaryClasses; |
| | | |
| | | /** The set of optional attribute types for this DIT content rule. */ |
| | | private final Set<AttributeType> optionalAttributes; |
| | | |
| | | /** The set of prohibited attribute types for this DIT content rule. */ |
| | | private final Set<AttributeType> prohibitedAttributes; |
| | | |
| | | /** The set of required attribute types for this DIT content rule. */ |
| | | private final Set<AttributeType> requiredAttributes; |
| | | |
| | | /** The definition string used to create this DIT content rule. */ |
| | | private final String definition; |
| | | |
| | | /** The description for this DIT content rule. */ |
| | | private final String description; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new DIT content rule definition with the provided |
| | | * information. |
| | |
| | | ifNull(definition, structuralClass); |
| | | |
| | | this.structuralClass = structuralClass; |
| | | this.description = description; |
| | | this.description = description; |
| | | this.isObsolete = isObsolete; |
| | | |
| | | int schemaFilePos = definition.indexOf(SCHEMA_PROPERTY_FILENAME); |
| | |
| | | */ |
| | | public String getNameOrOID() |
| | | { |
| | | if (names.isEmpty()) |
| | | { |
| | | return null; |
| | | } |
| | | else |
| | | { |
| | | return names.values().iterator().next(); |
| | | } |
| | | return !names.isEmpty() ? names.values().iterator().next() : null; |
| | | } |
| | | |
| | | |
| | |
| | | return requiredAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided attribute type is included in the |
| | | * required attribute list for this DIT content rule. |
| | | * |
| | | * @param attributeType The attribute type for which to make the |
| | | * determination. |
| | | * |
| | | * @return {@code true} if the provided attribute type is required |
| | | * by this DIT content rule, or {@code false} if not. |
| | | */ |
| | | public boolean isRequired(AttributeType attributeType) |
| | | { |
| | | return requiredAttributes.contains(attributeType); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of optional attributes for this DIT content |
| | | * rule. |
| | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided attribute type is included in the |
| | | * optional attribute list for this DIT content rule. |
| | | * |
| | | * @param attributeType The attribute type for which to make the |
| | | * determination. |
| | | * |
| | | * @return {@code true} if the provided attribute type is optional |
| | | * for this DIT content rule, or {@code false} if not. |
| | | */ |
| | | public boolean isOptional(AttributeType attributeType) |
| | | { |
| | | return optionalAttributes.contains(attributeType); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided attribute type is in the list of |
| | | * required or optional attributes for this DIT content rule. |
| | | * |
| | |
| | | * @param checkIfServerIsRunning |
| | | * If {@code true}, prevent any change when server is running. |
| | | */ |
| | | public DirectoryEnvironmentConfig(Properties properties, boolean checkIfServerIsRunning) |
| | | private DirectoryEnvironmentConfig(Properties properties, boolean checkIfServerIsRunning) |
| | | { |
| | | this.checkIfServerIsRunning = checkIfServerIsRunning; |
| | | configProperties = new HashMap<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new directory environment configuration initialized |
| | | * with a copy of the provided set of properties. |
| | | * |
| | | * @param properties The properties to use when initializing this |
| | | * environment configuration, or {@code null} |
| | | * to use an empty set of properties. |
| | | * @param checkIfServerIsRunning |
| | | * If {@code true}, prevent any change when server is running. |
| | | */ |
| | | public DirectoryEnvironmentConfig(Map<String,String> properties, boolean checkIfServerIsRunning) |
| | | { |
| | | this.checkIfServerIsRunning = checkIfServerIsRunning; |
| | | if (properties == null) |
| | | { |
| | | configProperties = new HashMap<>(); |
| | | } |
| | | else |
| | | { |
| | | configProperties = new HashMap<>(properties); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the property with the specified name. The check will |
| | | * first be made in the local config properties, but if no value is |
| | |
| | | * @return The property with the specified name, or {@code null} if |
| | | * no such property is defined. |
| | | */ |
| | | public String getProperty(String name) |
| | | private String getProperty(String name) |
| | | { |
| | | String value = configProperties.get(name); |
| | | if (value == null) |
| | | { |
| | | value = System.getProperty(name); |
| | | } |
| | | |
| | | return value; |
| | | } |
| | | |
| | |
| | | * @return The directory that should be considered the instance |
| | | * root, or {@code null} if it is not defined. |
| | | */ |
| | | public static File getInstanceRootFromServerRoot(File serverRoot) |
| | | private static File getInstanceRootFromServerRoot(File serverRoot) |
| | | { |
| | | return new File(Utils.getInstancePathFromInstallPath(serverRoot.getAbsolutePath())); |
| | | } |
| | |
| | | public File getConfigFile() |
| | | { |
| | | String configFilePath = getProperty(PROPERTY_CONFIG_FILE); |
| | | if (configFilePath == null) |
| | | { |
| | | File serverRoot = getServerRoot(); |
| | | if (serverRoot != null) |
| | | { |
| | | File instanceRoot = getInstanceRootFromServerRoot(serverRoot); |
| | | File configDir = new File(instanceRoot, CONFIG_DIR_NAME); |
| | | File configFile = new File(configDir, CONFIG_FILE_NAME); |
| | | if (configFile.exists()) |
| | | { |
| | | return configFile; |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | else |
| | | if (configFilePath != null) |
| | | { |
| | | return new File(configFilePath); |
| | | } |
| | | |
| | | File serverRoot = getServerRoot(); |
| | | if (serverRoot != null) |
| | | { |
| | | File instanceRoot = getInstanceRootFromServerRoot(serverRoot); |
| | | File configDir = new File(instanceRoot, CONFIG_DIR_NAME); |
| | | File configFile = new File(configDir, CONFIG_FILE_NAME); |
| | | if (configFile.exists()) |
| | | { |
| | | return configFile; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Specifies whether the Directory Server should attempt to start |
| | | * using the last known good configuration rather than the |
| | | * current active configuration. |
| | | * |
| | | * @param useLastKnownGoodConfiguration Indicates whether the |
| | | * Directory Server should |
| | | * attempt to start using the |
| | | * last known good |
| | | * configuration. |
| | | * |
| | | * @return The previous setting for this configuration option. If |
| | | * no previous value was specified, then {@code false} will |
| | | * be returned. |
| | | * |
| | | * @throws InitializationException If the Directory Server is |
| | | * already running. |
| | | */ |
| | | public boolean setUseLastKnownGoodConfiguration( |
| | | boolean useLastKnownGoodConfiguration) |
| | | throws InitializationException |
| | | { |
| | | return setBooleanProperty(PROPERTY_USE_LAST_KNOWN_GOOD_CONFIG, |
| | | useLastKnownGoodConfiguration); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the Directory Server should maintain an archive |
| | | * of previous configurations. If no explicit value is defined, |
| | | * then a default result of {@code true} will be returned. |
| | |
| | | try |
| | | { |
| | | int maxSize = Integer.parseInt(maxSizeStr); |
| | | if (maxSize > 0) |
| | | { |
| | | return maxSize; |
| | | } |
| | | else |
| | | { |
| | | return 0; |
| | | } |
| | | return maxSize > 0 ? maxSize : 0; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the maximum number of archived configurations that the |
| | | * Directory Server should maintain. A value that is less than or |
| | | * equal to zero may be used to indicate that there should not be |
| | | * any limit to the number of archived configurations. |
| | | * |
| | | * @param maxConfigArchiveSize The maximum number of archived |
| | | * configurations that the Directory |
| | | * Server should maintain. |
| | | * |
| | | * @return The previous setting for this configuration option. If |
| | | * no previous value was specified, then zero will be |
| | | * returned. |
| | | * |
| | | * @throws InitializationException If the Directory Server is |
| | | * already running. |
| | | */ |
| | | public int setMaxConfigArchiveSize(int maxConfigArchiveSize) |
| | | throws InitializationException |
| | | { |
| | | checkServerIsRunning(); |
| | | |
| | | if (maxConfigArchiveSize < 0) |
| | | { |
| | | maxConfigArchiveSize = 0; |
| | | } |
| | | |
| | | String oldMaxSizeStr = |
| | | setProperty(PROPERTY_MAX_CONFIG_ARCHIVE_SIZE, |
| | | String.valueOf(maxConfigArchiveSize)); |
| | | if (oldMaxSizeStr == null) |
| | | { |
| | | return 0; |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | int oldMaxSize = Integer.parseInt(oldMaxSizeStr); |
| | | if (oldMaxSize > 0) |
| | | { |
| | | return oldMaxSize; |
| | | } |
| | | else |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the directory that contains the server schema |
| | | * configuration files. If no value is defined, but a default |
| | |
| | | */ |
| | | public File getSchemaDirectory() |
| | | { |
| | | String schemaDirectoryPath = |
| | | getProperty(PROPERTY_SCHEMA_DIRECTORY); |
| | | if (schemaDirectoryPath == null) |
| | | { |
| | | File serverRoot = getServerRoot(); |
| | | if (serverRoot != null) |
| | | { |
| | | File instanceRoot = |
| | | getInstanceRootFromServerRoot(serverRoot); |
| | | File schemaDir = new File(instanceRoot.getAbsolutePath() |
| | | + File.separator + PATH_SCHEMA_DIR); |
| | | if (schemaDir.exists() && schemaDir.isDirectory()) |
| | | { |
| | | return schemaDir; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | else |
| | | String schemaDirectoryPath = getProperty(PROPERTY_SCHEMA_DIRECTORY); |
| | | if (schemaDirectoryPath != null) |
| | | { |
| | | return new File(schemaDirectoryPath); |
| | | } |
| | | |
| | | File serverRoot = getServerRoot(); |
| | | if (serverRoot != null) |
| | | { |
| | | File instanceRoot = getInstanceRootFromServerRoot(serverRoot); |
| | | File schemaDir = new File(instanceRoot.getAbsolutePath() + File.separator + PATH_SCHEMA_DIR); |
| | | if (schemaDir.exists() && schemaDir.isDirectory()) |
| | | { |
| | | return schemaDir; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | public File getLockDirectory() |
| | | { |
| | | String lockFilePath = getProperty(PROPERTY_LOCK_DIRECTORY); |
| | | if (lockFilePath == null) |
| | | { |
| | | File serverRoot = getServerRoot(); |
| | | if (serverRoot == null) |
| | | { |
| | | return null; |
| | | } |
| | | else |
| | | { |
| | | File instanceRoot = getInstanceRootFromServerRoot(serverRoot); |
| | | return new File(instanceRoot, LOCKS_DIRECTORY); |
| | | } |
| | | } |
| | | else |
| | | if (lockFilePath != null) |
| | | { |
| | | return new File(lockFilePath); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the directory that should be used to hold the server |
| | | * lock files. If the specified path already exists, then it must |
| | | * be a directory and its contents must be writable by the server. |
| | | * If it does not exist, then its parent directory must exist and |
| | | * the server should have permission to create a new subdirectory in |
| | | * it. |
| | | * |
| | | * @param lockDirectory The directory that should be used to hold |
| | | * the server lock files. |
| | | * |
| | | * @return The previously-defined lock directory, or {@code null} |
| | | * if none was defined. |
| | | * |
| | | * @throws InitializationException If the Directory Server is |
| | | * already running or there is a |
| | | * problem with the provided lock |
| | | * directory. |
| | | */ |
| | | public File setLockDirectory(File lockDirectory) |
| | | throws InitializationException |
| | | { |
| | | checkServerIsRunning(); |
| | | |
| | | if (lockDirectory.exists()) |
| | | File serverRoot = getServerRoot(); |
| | | if (serverRoot != null) |
| | | { |
| | | if (! lockDirectory.isDirectory()) |
| | | { |
| | | throw new InitializationException( |
| | | ERR_DIRCFG_INVALID_LOCK_DIRECTORY.get( |
| | | lockDirectory.getAbsolutePath())); |
| | | } |
| | | File instanceRoot = getInstanceRootFromServerRoot(serverRoot); |
| | | return new File(instanceRoot, LOCKS_DIRECTORY); |
| | | } |
| | | else |
| | | { |
| | | File parentFile = lockDirectory.getParentFile(); |
| | | if (!parentFile.exists() || !parentFile.isDirectory()) |
| | | { |
| | | throw new InitializationException( |
| | | ERR_DIRCFG_INVALID_LOCK_DIRECTORY.get( |
| | | lockDirectory.getAbsolutePath())); |
| | | } |
| | | } |
| | | |
| | | return setPathProperty(PROPERTY_LOCK_DIRECTORY, lockDirectory); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the Directory Server startup process should |
| | | * skip the connection handler creation and initialization phases. |
| | |
| | | return isPropertyTrue(PROPERTY_DISABLE_EXEC); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether the Directory Server should be allowed to use |
| | | * the {@code Runtime.exec()} method to be able to launch external |
| | | * commands on the underlying system. |
| | | * |
| | | * @param disableExec Indicates whether the Directory Server |
| | | * should be allowed to launch external |
| | | * commands on the underlying system. |
| | | * |
| | | * @return The previous setting for this configuration option. If |
| | | * no previous value was specified, then {@code false} will |
| | | * be returned. |
| | | * |
| | | * @throws InitializationException If the Directory Server is |
| | | * already running. |
| | | */ |
| | | public boolean setDisableExec(boolean disableExec) |
| | | throws InitializationException |
| | | { |
| | | return setBooleanProperty(PROPERTY_DISABLE_EXEC, disableExec); |
| | | } |
| | | |
| | | |
| | | |
| | | /** Throws an exception if server is running and it is not allowed. */ |
| | | private void checkServerIsRunning() throws InitializationException |
| | | { |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.IOException; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | |
| | | /** |
| | | * This class provides a mechanism for setting file permissions in a |
| | | * more abstract manner than is provided by the underlying operating |
| | |
| | | mayInvoke=true) |
| | | public class FilePermission |
| | | { |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * readable by its owner. |
| | | */ |
| | | public static final int OWNER_READABLE = 0x0100; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * writable by its owner. |
| | | */ |
| | | public static final int OWNER_WRITABLE = 0x0080; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * executable by its owner. |
| | | */ |
| | | public static final int OWNER_EXECUTABLE = 0x0040; |
| | | |
| | | |
| | | |
| | | /** The bitmask that should be used for indicating whether a file is readable by its owner. */ |
| | | private static final int OWNER_READABLE = 0x0100; |
| | | /** The bitmask that should be used for indicating whether a file is writable by its owner. */ |
| | | private static final int OWNER_WRITABLE = 0x0080; |
| | | /** The bitmask that should be used for indicating whether a file is executable by its owner. */ |
| | | private static final int OWNER_EXECUTABLE = 0x0040; |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * readable by members of its group. |
| | | */ |
| | | public static final int GROUP_READABLE = 0x0020; |
| | | |
| | | |
| | | |
| | | private static final int GROUP_READABLE = 0x0020; |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * writable by members of its group. |
| | | */ |
| | | public static final int GROUP_WRITABLE = 0x0010; |
| | | |
| | | |
| | | |
| | | private static final int GROUP_WRITABLE = 0x0010; |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * executable by members of its group. |
| | | */ |
| | | public static final int GROUP_EXECUTABLE = 0x0008; |
| | | |
| | | |
| | | |
| | | private static final int GROUP_EXECUTABLE = 0x0008; |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * readable by users other than the owner or group members. |
| | | */ |
| | | public static final int OTHER_READABLE = 0x0004; |
| | | |
| | | |
| | | |
| | | private static final int OTHER_READABLE = 0x0004; |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * writable by users other than the owner or group members. |
| | | */ |
| | | public static final int OTHER_WRITABLE = 0x0002; |
| | | |
| | | |
| | | |
| | | private static final int OTHER_WRITABLE = 0x0002; |
| | | /** |
| | | * The bitmask that should be used for indicating whether a file is |
| | | * executable by users other than the owner or group members. |
| | | */ |
| | | public static final int OTHER_EXECUTABLE = 0x0001; |
| | | |
| | | |
| | | private static final int OTHER_EXECUTABLE = 0x0001; |
| | | |
| | | /** The encoded representation for this file permission. */ |
| | | private int encodedPermission; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new file permission object with the provided encoded |
| | | * representation. |
| | |
| | | this.encodedPermission = encodedPermission; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new file permission with the specified rights for the |
| | | * file owner. Users other than the owner will not have any rights. |
| | | * |
| | | * @param ownerReadable Indicates whether the owner should have |
| | | * the read permission. |
| | | * @param ownerWritable Indicates whether the owner should have |
| | | * the write permission. |
| | | * @param ownerExecutable Indicates whether the owner should have |
| | | * the execute permission. |
| | | */ |
| | | public FilePermission(boolean ownerReadable, boolean ownerWritable, |
| | | boolean ownerExecutable) |
| | | { |
| | | encodedPermission = 0x0000; |
| | | |
| | | if (ownerReadable) |
| | | { |
| | | encodedPermission |= OWNER_READABLE; |
| | | } |
| | | |
| | | if (ownerWritable) |
| | | { |
| | | encodedPermission |= OWNER_WRITABLE; |
| | | } |
| | | |
| | | if (ownerExecutable) |
| | | { |
| | | encodedPermission |= OWNER_EXECUTABLE; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new file permission with the specified rights for the |
| | | * file owner, group members, and other users. |
| | | * |
| | | * @param ownerReadable Indicates whether the owner should have |
| | | * the read permission. |
| | | * @param ownerWritable Indicates whether the owner should have |
| | | * the write permission. |
| | | * @param ownerExecutable Indicates whether the owner should have |
| | | * the execute permission. |
| | | * @param groupReadable Indicates whether members of the file's |
| | | * group should have the read permission. |
| | | * @param groupWritable Indicates whether members of the file's |
| | | * group should have the write permission. |
| | | * @param groupExecutable Indicates whether members of the file's |
| | | * group should have the execute |
| | | * permission. |
| | | * @param otherReadable Indicates whether other users should |
| | | * have the read permission. |
| | | * @param otherWritable Indicates whether other users should |
| | | * have the write permission. |
| | | * @param otherExecutable Indicates whether other users should |
| | | * have the execute permission. |
| | | */ |
| | | public FilePermission(boolean ownerReadable, boolean ownerWritable, |
| | | boolean ownerExecutable, |
| | | boolean groupReadable, boolean groupWritable, |
| | | boolean groupExecutable, |
| | | boolean otherReadable, boolean otherWritable, |
| | | boolean otherExecutable) |
| | | { |
| | | encodedPermission = 0x0000; |
| | | |
| | | if (ownerReadable) |
| | | { |
| | | encodedPermission |= OWNER_READABLE; |
| | | } |
| | | |
| | | if (ownerWritable) |
| | | { |
| | | encodedPermission |= OWNER_WRITABLE; |
| | | } |
| | | |
| | | if (ownerExecutable) |
| | | { |
| | | encodedPermission |= OWNER_EXECUTABLE; |
| | | } |
| | | |
| | | if (groupReadable) |
| | | { |
| | | encodedPermission |= GROUP_READABLE; |
| | | } |
| | | |
| | | if (groupWritable) |
| | | { |
| | | encodedPermission |= GROUP_WRITABLE; |
| | | } |
| | | |
| | | if (groupExecutable) |
| | | { |
| | | encodedPermission |= GROUP_EXECUTABLE; |
| | | } |
| | | |
| | | if (otherReadable) |
| | | { |
| | | encodedPermission |= OTHER_READABLE; |
| | | } |
| | | |
| | | if (otherWritable) |
| | | { |
| | | encodedPermission |= OTHER_WRITABLE; |
| | | } |
| | | |
| | | if (otherExecutable) |
| | | { |
| | | encodedPermission |= OTHER_EXECUTABLE; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the owner read |
| | | * permission. |
| | |
| | | return is(encodedPermission, OWNER_READABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the owner write |
| | | * permission. |
| | |
| | | return is(encodedPermission, OWNER_WRITABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the owner execute |
| | | * permission. |
| | |
| | | return is(encodedPermission, OWNER_EXECUTABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the group read |
| | | * permission. |
| | |
| | | return is(encodedPermission, GROUP_READABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the group write |
| | | * permission. |
| | |
| | | return is(encodedPermission, GROUP_WRITABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the group execute |
| | | * permission. |
| | |
| | | return is(encodedPermission, GROUP_EXECUTABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the other read |
| | | * permission. |
| | |
| | | return is(encodedPermission, OTHER_READABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the other write |
| | | * permission. |
| | |
| | | return is(encodedPermission, OTHER_WRITABLE); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this file permission includes the other execute |
| | | * permission. |
| | |
| | | return buffer.toString(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Appends a three-character string that is the UNIX mode for the |
| | | * provided file permission to the given buffer. Each character of |
| | |
| | | * appended. |
| | | * @param p The permission to retrieve as a UNIX mode string. |
| | | */ |
| | | public static void toUNIXMode(StringBuilder buffer, |
| | | private static void toUNIXMode(StringBuilder buffer, |
| | | FilePermission p) |
| | | { |
| | | byte modeByte = 0x00; |
| | |
| | | buffer.append(modeByte); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Decodes the provided string as a UNIX mode and retrieves the |
| | | * corresponding file permission. The mode string must contain |
| | |
| | | return new FilePermission(encodedPermission); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Build a file permissions string in the "rwx" form expected by NIO, |
| | | * but with optional prefix strings before each three character block. |
| | |
| | | buffer.append(p.isOtherExecutable() ? "x" : "-"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a string representation of this file permission. |
| | | * |
| | |
| | | return buffer.toString(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Appends a string representation of this file permission to the |
| | | * given buffer. |
| | | * |
| | | * @param buffer The buffer to which the data should be appended. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | toPOSIXString(this, buffer, "Owner=", ", Group=", ", Other="); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | /** |
| | | * This class defines a data structure for holding information that |
| | |
| | | @org.opends.server.types.PublicAPI( |
| | | stability=org.opends.server.types.StabilityLevel.VOLATILE, |
| | | mayInstantiate=true, |
| | | mayExtend=false, |
| | | mayInvoke=true) |
| | | public final class IntermediateResponse |
| | | { |
| | | /** The value for this intermediate response. */ |
| | | private ByteString value; |
| | | |
| | | /** The set of controls for this intermediate response. */ |
| | | private List<Control> controls; |
| | | |
| | | private final List<Control> controls; |
| | | /** The operation with which this intermediate response is associated. */ |
| | | private Operation operation; |
| | | |
| | | private final Operation operation; |
| | | /** The OID for this intermediate response. */ |
| | | private String oid; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new intermediate response with the provided |
| | | * information. |
| | |
| | | this.oid = oid; |
| | | this.value = value; |
| | | |
| | | if (controls == null) |
| | | { |
| | | this.controls = new ArrayList<>(0); |
| | | } |
| | | else |
| | | if (controls != null) |
| | | { |
| | | this.controls = controls; |
| | | } |
| | | else |
| | | { |
| | | this.controls = new ArrayList<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the operation with which this intermediate response |
| | | * message is associated. |
| | |
| | | return operation; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the OID for this intermediate response. |
| | | * |
| | |
| | | return oid; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the OID for this intermediate response. |
| | | * |
| | |
| | | this.oid = oid; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the value for this intermediate response. |
| | | * |
| | |
| | | return value; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the value for this intermediate response. |
| | | * |
| | |
| | | this.value = value; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of controls for this intermediate response. |
| | | * The contents of the list may be altered by intermediate response |
| | |
| | | return controls; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a string representation of this intermediate response. |
| | | * |
| | |
| | | return buffer.toString(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Appends a string representation of this intermediate response to |
| | | * the provided buffer. |
| | |
| | | * @param buffer The buffer to which the information should be |
| | | * appended. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | buffer.append("IntermediateResponse(operation="); |
| | | operation.toString(buffer); |
| | |
| | | buffer.append(")"); |
| | | } |
| | | } |
| | | |
| | |
| | | /** The default scheme that will be used if none is provided. */ |
| | | public static final String DEFAULT_SCHEME = "ldap"; |
| | | /** The default port value that will be used if none is provided. */ |
| | | public static final int DEFAULT_PORT = 389; |
| | | private static final int DEFAULT_PORT = 389; |
| | | /** The default base DN that will be used if none is provided. */ |
| | | public static final DN DEFAULT_BASE_DN = DN.rootDN(); |
| | | private static final DN DEFAULT_BASE_DN = DN.rootDN(); |
| | | /** The default search scope that will be used if none is provided. */ |
| | | public static final SearchScope DEFAULT_SEARCH_SCOPE = |
| | | private static final SearchScope DEFAULT_SEARCH_SCOPE = |
| | | SearchScope.BASE_OBJECT; |
| | | /** The default search filter that will be used if none is provided. */ |
| | | public static final SearchFilter DEFAULT_SEARCH_FILTER = |
| | |
| | | private String rawFilter; |
| | | |
| | | /** The set of attributes for this LDAP URL. */ |
| | | private LinkedHashSet<String> attributes; |
| | | private final LinkedHashSet<String> attributes; |
| | | /** The set of extensions for this LDAP URL. */ |
| | | private LinkedList<String> extensions; |
| | | private final List<String> extensions; |
| | | |
| | | |
| | | /** The scheme (i.e., protocol) for this LDAP URL. */ |
| | |
| | | public LDAPURL(String scheme, String host, int port, |
| | | String rawBaseDN, LinkedHashSet<String> attributes, |
| | | SearchScope scope, String rawFilter, |
| | | LinkedList<String> extensions) |
| | | List<String> extensions) |
| | | { |
| | | this.host = toLowerCase(host); |
| | | |
| | |
| | | */ |
| | | public LDAPURL(String scheme, String host, int port, DN baseDN, |
| | | LinkedHashSet<String> attributes, SearchScope scope, |
| | | SearchFilter filter, LinkedList<String> extensions) |
| | | SearchFilter filter, List<String> extensions) |
| | | { |
| | | this.host = toLowerCase(host); |
| | | |
| | |
| | | DEFAULT_SEARCH_SCOPE, DEFAULT_SEARCH_FILTER, |
| | | null); |
| | | } |
| | | else |
| | | { |
| | | startPos = pos; |
| | | } |
| | | startPos = pos; |
| | | |
| | | |
| | | // The next delimiter should be a question mark. If there isn't |
| | |
| | | * |
| | | * @return The set of extensions for this LDAP URL. |
| | | */ |
| | | public LinkedList<String> getExtensions() |
| | | public List<String> getExtensions() |
| | | { |
| | | return extensions; |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.io.*; |
| | | import java.io.BufferedWriter; |
| | | import java.io.Closeable; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.OutputStreamWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | |
| | | import java.util.zip.GZIPOutputStream; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | /** |
| | | * This class defines a data structure for holding configuration |
| | | * information to use when performing an LDIF export. |
| | |
| | | public final class LDIFExportConfig extends OperationConfig |
| | | implements Closeable |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** Indicates whether the data should be compressed as it is written. */ |
| | | private boolean compressData; |
| | | |
| | | /** Indicates whether the data should be encrypted as it is written. */ |
| | | private boolean encryptData; |
| | | |
| | | /** |
| | | * Indicates whether to generate a cryptographic hash of the data as it is |
| | | * written. |
| | | */ |
| | | /** Indicates whether to generate a cryptographic hash of the data as it is written. */ |
| | | private boolean hashData; |
| | | |
| | | /** |
| | | * Indicates whether to include the objectclasses in the entries written in |
| | | * the export. |
| | | */ |
| | | /** Indicates whether to include the objectclasses in the entries written in the export. */ |
| | | private boolean includeObjectClasses; |
| | | |
| | | /** |
| | | * Indicates whether to include operational attributes in the export. |
| | | */ |
| | | /** Indicates whether to include operational attributes in the export. */ |
| | | private boolean includeOperationalAttributes; |
| | | |
| | | /** Indicates whether to include virtual attributes in the export. */ |
| | | private boolean includeVirtualAttributes; |
| | | |
| | | /** |
| | | * Indicates whether to invoke LDIF export plugins on entries being exported. |
| | | */ |
| | | /** Indicates whether to invoke LDIF export plugins on entries being exported. */ |
| | | private boolean invokeExportPlugins; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private boolean signHash; |
| | | |
| | | /** |
| | | * Indicates whether to include attribute types (i.e., names) only or both |
| | | * types and values. |
| | | */ |
| | | /** Indicates whether to include attribute types (i.e., names) only or both types and values. */ |
| | | private boolean typesOnly; |
| | | |
| | | /** The path to the LDIF file that should be written. */ |
| | | private final String ldifFile; |
| | | /** The buffered writer to which the LDIF data should be written. */ |
| | | private BufferedWriter writer; |
| | | /** The output stream to which the LDIF data should be written. */ |
| | | private OutputStream ldifOutputStream; |
| | | |
| | | /** |
| | | * The behavior that should be used when writing an LDIF file and a file with |
| | | * the same name already exists. |
| | | */ |
| | | private ExistingFileBehavior existingFileBehavior; |
| | | private final ExistingFileBehavior existingFileBehavior; |
| | | |
| | | /** The column number at which long lines should be wrapped. */ |
| | | private int wrapColumn; |
| | | |
| | | /** The set of base DNs to exclude from the export. */ |
| | | private List<DN> excludeBranches; |
| | | |
| | | /** The set of base DNs to include from the export. */ |
| | | private List<DN> includeBranches; |
| | | |
| | | /** The set of search filters for entries to exclude from the export. */ |
| | | private List<SearchFilter> excludeFilters; |
| | | |
| | | /** The set of search filters for entries to include in the export. */ |
| | | private List<SearchFilter> includeFilters; |
| | | |
| | | /** The output stream to which the LDIF data should be written. */ |
| | | private OutputStream ldifOutputStream; |
| | | |
| | | /** |
| | | * The set of attribute types that should be excluded from the export. |
| | | */ |
| | | /** The set of attribute types that should be excluded from the export. */ |
| | | private Set<AttributeType> excludeAttributes; |
| | | |
| | | /** The set of attribute types that should be included in the export. */ |
| | | private Set<AttributeType> includeAttributes; |
| | | |
| | | /** The path to the LDIF file that should be written. */ |
| | | private String ldifFile; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new LDIF export configuration that will write to the |
| | | * specified LDIF file. |
| | |
| | | wrapColumn = -1; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new LDIF export configuration that will write to the |
| | | * provided output stream. |
| | |
| | | wrapColumn = -1; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the writer that should be used to write the LDIF data. |
| | | * If compression or encryption are to be used, then they must be |
| | |
| | | LocalizableMessage message = ERR_LDIF_FILE_EXISTS.get(ldifFile); |
| | | throw new IOException(message.toString()); |
| | | } |
| | | else |
| | | { |
| | | // Create new file ensuring that we can set its permissions. |
| | | f.createNewFile(); |
| | | mustSetPermissions = true; |
| | | ldifOutputStream = new FileOutputStream(ldifFile); |
| | | } |
| | | // Create new file ensuring that we can set its permissions. |
| | | f.createNewFile(); |
| | | mustSetPermissions = true; |
| | | ldifOutputStream = new FileOutputStream(ldifFile); |
| | | break; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // See if we should compress the output. |
| | | OutputStream outputStream; |
| | | if (compressData) |
| | |
| | | // See if we should encrypt the output. |
| | | if (encryptData) |
| | | { |
| | | // FIXME -- Implement this. |
| | | // FIXME -- To be implemented: See OPENDJ-448. |
| | | } |
| | | |
| | | |
| | |
| | | return writer; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the LDIF export plugins should be invoked for |
| | | * entries as they are exported. |
| | |
| | | return invokeExportPlugins; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether the LDIF export plugins should be invoked for |
| | | * entries as they are exported. |
| | |
| | | this.invokeExportPlugins = invokeExportPlugins; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the LDIF data should be compressed as it is |
| | | * written. |
| | | * |
| | | * @return <CODE>true</CODE> if the LDIF data should be compressed |
| | | * as it is written, or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean compressData() |
| | | { |
| | | return compressData; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether the LDIF data should be compressed as it is |
| | | * written. If compression should be used, then this must be set |
| | |
| | | return typesOnly; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether the LDIF generated should include attribute |
| | | * types (i.e., attribute names) only or both attribute types and |
| | |
| | | this.typesOnly = typesOnly; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the column at which long lines should be wrapped. |
| | | * |
| | |
| | | return wrapColumn; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the column at which long lines should be wrapped. A |
| | | * value less than or equal to zero indicates that no wrapping |
| | |
| | | this.wrapColumn = wrapColumn; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of base DNs that specify the set of entries to |
| | | * exclude from the export. The list that is returned may be |
| | |
| | | return excludeBranches; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of base DNs that specify the set of entries to |
| | | * exclude from the export. |
| | |
| | | */ |
| | | public void setExcludeBranches(List<DN> excludeBranches) |
| | | { |
| | | if (excludeBranches == null) |
| | | { |
| | | this.excludeBranches = new ArrayList<>(0); |
| | | } |
| | | else |
| | | if (excludeBranches != null) |
| | | { |
| | | this.excludeBranches = excludeBranches; |
| | | } |
| | | else |
| | | { |
| | | this.excludeBranches = new ArrayList<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of base DNs that specify the set of entries to |
| | | * include in the export. The list that is returned may be altered |
| | |
| | | return includeBranches; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of base DNs that specify the set of entries to |
| | | * include in the export. |
| | |
| | | */ |
| | | public void setIncludeBranches(List<DN> includeBranches) |
| | | { |
| | | if (includeBranches == null) |
| | | { |
| | | this.includeBranches = new ArrayList<>(0); |
| | | } |
| | | else |
| | | if (includeBranches != null) |
| | | { |
| | | this.includeBranches = includeBranches; |
| | | } |
| | | else |
| | | { |
| | | this.includeBranches = new ArrayList<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the set of objectclasses should be included in |
| | | * the entries written to LDIF. |
| | |
| | | return includeObjectClasses; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the set of operational attributes should be |
| | | * included in the export. |
| | |
| | | return includeOperationalAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether the objectclasss attribute should be |
| | | * included in the export. |
| | |
| | | this.includeOperationalAttributes = includeOperationalAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether virtual attributes should be included in the |
| | | * export. |
| | |
| | | return includeVirtualAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether virtual attributes should be included in the |
| | | * export. |
| | |
| | | this.includeVirtualAttributes = includeVirtualAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of attributes that should be excluded from the |
| | | * entries written to LDIF. The set that is returned may be altered |
| | |
| | | return excludeAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of attributes that should be excluded from the |
| | | * entries written to LDIF. |
| | |
| | | public void setExcludeAttributes( |
| | | Set<AttributeType> excludeAttributes) |
| | | { |
| | | if (excludeAttributes == null) |
| | | { |
| | | this.excludeAttributes = new HashSet<>(0); |
| | | } |
| | | else |
| | | if (excludeAttributes != null) |
| | | { |
| | | this.excludeAttributes = excludeAttributes; |
| | | } |
| | | else |
| | | { |
| | | this.excludeAttributes = new HashSet<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of attributes that should be included in the |
| | | * entries written to LDIF. The set that is returned may be altered |
| | |
| | | return includeAttributes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of attributes that should be included in the |
| | | * entries written to LDIF. |
| | |
| | | */ |
| | | public void setIncludeAttributes(Set<AttributeType> includeAttributes) |
| | | { |
| | | if (includeAttributes == null) |
| | | { |
| | | this.includeAttributes = new HashSet<>(0); |
| | | } |
| | | else |
| | | if (includeAttributes != null) |
| | | { |
| | | this.includeAttributes = includeAttributes; |
| | | } |
| | | else |
| | | { |
| | | this.includeAttributes = new HashSet<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the specified attribute should be included in |
| | | * the entries written to LDIF. |
| | |
| | | || includeAttributes.contains(attributeType)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of search filters that should be used to |
| | | * determine which entries to exclude from the LDIF. The list that |
| | |
| | | return excludeFilters; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of search filters that should be used to |
| | | * determine which entries to exclude from the LDIF. |
| | |
| | | */ |
| | | public void setExcludeFilters(List<SearchFilter> excludeFilters) |
| | | { |
| | | if (excludeFilters == null) |
| | | { |
| | | this.excludeFilters = new ArrayList<>(0); |
| | | } |
| | | else |
| | | if (excludeFilters != null) |
| | | { |
| | | this.excludeFilters = excludeFilters; |
| | | } |
| | | else |
| | | { |
| | | this.excludeFilters = new ArrayList<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of search filters that should be used to |
| | | * determine which entries to include in the LDIF. The list that is |
| | |
| | | return includeFilters; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of search filters that should be used to |
| | | * determine which entries to include in the LDIF. |
| | |
| | | */ |
| | | public void setIncludeFilters(List<SearchFilter> includeFilters) |
| | | { |
| | | if (includeFilters == null) |
| | | { |
| | | this.includeFilters = new ArrayList<>(0); |
| | | } |
| | | else |
| | | if (includeFilters != null) |
| | | { |
| | | this.includeFilters = includeFilters; |
| | | } |
| | | else |
| | | { |
| | | this.includeFilters = new ArrayList<>(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the specified entry should be included in the |
| | | * export based on the configured set of include and exclude |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Closes any resources that this export config might have open. |
| | | */ |
| | | /** Closes any resources that this export config might have open. */ |
| | | @Override |
| | | public void close() |
| | | { |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import java.io.BufferedReader; |
| | | import java.io.BufferedWriter; |
| | | import java.io.Closeable; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.io.OutputStreamWriter; |
| | | import java.io.Reader; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.zip.GZIPInputStream; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.tools.makeldif.MakeLDIFInputStream; |
| | | import org.opends.server.tools.makeldif.TemplateFile; |
| | | import org.opends.server.util.CollectionUtils; |
| | |
| | | private int bufferSize = DEFAULT_BUFFER_SIZE; |
| | | |
| | | /** The iterator used to read through the set of LDIF files. */ |
| | | private Iterator<String> ldifFileIterator; |
| | | private final Iterator<String> ldifFileIterator; |
| | | |
| | | /** The set of base DNs to exclude from the import. */ |
| | | private Set<DN> excludeBranches = new HashSet<>(0); |
| | |
| | | private List<SearchFilter> includeFilters = new ArrayList<>(0); |
| | | |
| | | /** The set of LDIF files to be imported. */ |
| | | private List<String> ldifFiles; |
| | | private final List<String> ldifFiles; |
| | | |
| | | /** The set of attribute types that should be excluded from the import. */ |
| | | private Set<AttributeType> excludeAttributes = new HashSet<>(0); |
| | |
| | | */ |
| | | public LDIFImportConfig(InputStream ldifInputStream) |
| | | { |
| | | this(Collections.<String> emptyList()); |
| | | this.ldifInputStream = ldifInputStream; |
| | | } |
| | | |
| | |
| | | */ |
| | | public LDIFImportConfig(Reader ldifInputReader) |
| | | { |
| | | this(Collections.<String> emptyList()); |
| | | reader = getBufferedReader(ldifInputReader); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Indicates that skipped entries should be written to the provided |
| | | * output stream. Note that this does not apply to entries that are |
| | | * rejected because they are invalid (e.g., are malformed or don't |
| | | * conform to schema requirements), but only apply to entries that |
| | | * are skipped because they matched exclude criteria. |
| | | * |
| | | * @param outputStream The output stream to which skipped entries |
| | | * should be written. |
| | | */ |
| | | public void writeSkippedEntries(OutputStream outputStream) |
| | | { |
| | | if (outputStream == null) |
| | | { |
| | | closeSkipWriter(); |
| | | return; |
| | | } |
| | | skipWriter = |
| | | new BufferedWriter(new OutputStreamWriter(outputStream)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class defines a data structure for providing information about |
| | | * the state of a completed LDIF import, including the total number of |
| | |
| | | { |
| | | /** The total number of entries read during the import. */ |
| | | private final long entriesRead; |
| | | |
| | | /** The total number of entries rejected during the import. */ |
| | | private final long entriesRejected; |
| | | |
| | | /** The total number of entries skipped during the import. */ |
| | | private final long entriesSkipped; |
| | | |
| | |
| | | * @param buffer The buffer to which the information should be |
| | | * appended. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | buffer.append("LDIFImportResult(entriesRead="); |
| | | buffer.append(entriesRead); |
| | |
| | | buffer.append(")"); |
| | | } |
| | | } |
| | | |
| | |
| | | mayInstantiate = false, mayExtend = false, mayInvoke = true) |
| | | public final class LockManager |
| | | { |
| | | /** |
| | | * A lock on an entry or subtree. A lock can only be unlocked once. |
| | | */ |
| | | /** A lock on an entry or subtree. A lock can only be unlocked once. */ |
| | | public final class DNLock |
| | | { |
| | | private final DNLockHolder lock; |
| | |
| | | isLocked = false; |
| | | } |
| | | |
| | | // For unit testing. |
| | | /** For unit testing. */ |
| | | int refCount() |
| | | { |
| | | return lock.refCount.get(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Lock implementation |
| | | */ |
| | | /** Lock implementation. */ |
| | | private final class DNLockHolder |
| | | { |
| | | private final AtomicInteger refCount = new AtomicInteger(); |
| | |
| | | return "\"" + dn + "\" : " + refCount; |
| | | } |
| | | |
| | | /** |
| | | * Unlocks the subtree read lock from the parent of this lock up to the root. |
| | | */ |
| | | /** Unlocks the subtree read lock from the parent of this lock up to the root. */ |
| | | void releaseParentSubtreeReadLock() |
| | | { |
| | | for (DNLockHolder lock = parent; lock != null; lock = lock.parent) |
| | |
| | | return tryLock(subtreeLock.writeLock(), entryLock.writeLock()); |
| | | } |
| | | |
| | | /** |
| | | * Locks the subtree read lock from the root down to the parent of this lock. |
| | | */ |
| | | /** Locks the subtree read lock from the root down to the parent of this lock. */ |
| | | private boolean tryAcquireParentSubtreeReadLock() |
| | | { |
| | | // First lock the parents of the parent. |
| | |
| | | private final long lockTimeout; |
| | | private final TimeUnit lockTimeoutUnits; |
| | | |
| | | // Avoid sub-classing in order to workaround class leaks in app servers. |
| | | /** Avoid sub-classing in order to workaround class leaks in app servers. */ |
| | | private final ThreadLocal<LinkedList<DNLockHolder>> threadLocalCache = new ThreadLocal<>(); |
| | | |
| | | /** |
| | |
| | | * The number of buckets to use in the lock table. The minimum number of buckets is 64. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public LockManager(final long lockTimeout, final TimeUnit lockTimeoutUnit, final int numberOfBuckets) |
| | | private LockManager(final long lockTimeout, final TimeUnit lockTimeoutUnit, final int numberOfBuckets) |
| | | { |
| | | Reject.ifFalse(lockTimeout >= 0, "lockTimeout must be a non-negative integer"); |
| | | Reject.ifNull(lockTimeoutUnit, "lockTimeoutUnit must be non-null"); |
| | |
| | | return acquireLockFromCache(subtree).tryWriteLockSubtree(); |
| | | } |
| | | |
| | | // For unit testing. |
| | | /** For unit testing. */ |
| | | int getLockTableRefCountFor(final DN dn) |
| | | { |
| | | final int dnHashCode = dn.hashCode(); |
| | |
| | | } |
| | | } |
| | | |
| | | //For unit testing. |
| | | /** For unit testing. */ |
| | | int getThreadLocalCacheRefCountFor(final DN dn) |
| | | { |
| | | final LinkedList<DNLockHolder> cache = threadLocalCache.get(); |
| | |
| | | return lockTable[dnHashCode & numberOfBuckets - 1]; |
| | | } |
| | | |
| | | /* |
| | | /** |
| | | * Ensure that the number of buckets is a power of 2 in order to make it easier to map hash codes |
| | | * to bucket indexes. |
| | | */ |
| | |
| | | * 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 org.opends.server.types; |
| | | |
| | |
| | | * |
| | | * @param buffer The buffer to which the information should be appended. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | buffer.append("Modification(").append(modificationType).append(", ").append(attribute); |
| | | } |
| | |
| | | * 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 org.opends.server.types; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | |
| | | import java.security.SecureRandom; |
| | | import java.util.Random; |
| | | import java.util.SortedSet; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class provides a data structure that makes it possible to |
| | | * associate a name with a given set of characters. The name must |
| | |
| | | { |
| | | /** The characters contained in this character set. */ |
| | | private final char[] characters; |
| | | |
| | | /** The random number generator to use with this character set. */ |
| | | private final Random random; |
| | | |
| | | /** The name assigned to this character set. */ |
| | | private final String name; |
| | | |
| | |
| | | * @throws ConfigException If the provided name contains one or |
| | | * more illegal characters. |
| | | */ |
| | | public NamedCharacterSet(String name, char[] characters) |
| | | private NamedCharacterSet(String name, char[] characters) |
| | | throws ConfigException |
| | | { |
| | | this(name, characters, new SecureRandom()); |
| | |
| | | * @throws ConfigException If the provided name contains one or |
| | | * more illegal characters. |
| | | */ |
| | | public NamedCharacterSet(String name, char[] characters, |
| | | private NamedCharacterSet(String name, char[] characters, |
| | | Random random) |
| | | throws ConfigException |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Encodes this character set to a form suitable for use in the |
| | | * value of a configuration attribute. |
| | | * |
| | | * @return The encoded character set in a form suitable for use in |
| | | * the value of a configuration attribute. |
| | | */ |
| | | public String encode() |
| | | { |
| | | return name + ":" + new String(characters); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Decodes the values of the provided configuration attribute as a |
| | | * set of character set definitions. |
| | |
| | | * that already contain one or more real values for the associated |
| | | * collective attribute. |
| | | */ |
| | | public static enum CollectiveConflictBehavior { |
| | | public enum CollectiveConflictBehavior { |
| | | /** |
| | | * Indicates that the virtual attribute provider is to preserve |
| | | * any real values contained in the entry and merge them with the |
| | |
| | | } |
| | | |
| | | /** The lowercased name of the "collectiveConflictBehavior" attribute type. */ |
| | | public static final String ATTR_COLLECTIVE_CONFLICT_BEHAVIOR_LC = "collectiveconflictbehavior"; |
| | | private static final String ATTR_COLLECTIVE_CONFLICT_BEHAVIOR_LC = "collectiveconflictbehavior"; |
| | | /** The lowercased name of the "inheritFromDNAttribute" attribute type. */ |
| | | public static final String ATTR_INHERIT_COLLECTIVE_FROM_DN_LC = "inheritfromdnattribute"; |
| | | private static final String ATTR_INHERIT_COLLECTIVE_FROM_DN_LC = "inheritfromdnattribute"; |
| | | /** The lowercased name of the "inheritFromRDNAttribute" attribute type. */ |
| | | public static final String ATTR_INHERIT_COLLECTIVE_FROM_RDN_LC = "inheritfromrdnattribute"; |
| | | private static final String ATTR_INHERIT_COLLECTIVE_FROM_RDN_LC = "inheritfromrdnattribute"; |
| | | /** The lowercased name of the "inheritFromRDNType" attribute type. */ |
| | | public static final String ATTR_INHERIT_COLLECTIVE_FROM_RDN_TYPE_LC = "inheritfromrdntype"; |
| | | private static final String ATTR_INHERIT_COLLECTIVE_FROM_RDN_TYPE_LC = "inheritfromrdntype"; |
| | | /** The lowercased name of the "inheritFromBaseRDN" attribute type. */ |
| | | public static final String ATTR_INHERIT_COLLECTIVE_FROM_BASE_LC = "inheritfrombaserdn"; |
| | | private static final String ATTR_INHERIT_COLLECTIVE_FROM_BASE_LC = "inheritfrombaserdn"; |
| | | /** The lowercased name of the "inheritAttribute" attribute type. */ |
| | | public static final String ATTR_INHERIT_COLLECTIVE_ATTR_LC = "inheritattribute"; |
| | | private static final String ATTR_INHERIT_COLLECTIVE_ATTR_LC = "inheritattribute"; |
| | | /** Attribute option to mark attributes collective. */ |
| | | private static final String ATTR_OPTION_COLLECTIVE = "collective"; |
| | | |
| | | /** Entry object. */ |
| | | private Entry entry; |
| | | private final Entry entry; |
| | | |
| | | /** Subtree specification. */ |
| | | private final SubtreeSpecification subTreeSpec; |
| | | |
| | | /** Collective subentry flag. */ |
| | | private boolean isCollective; |
| | | private final boolean isCollective; |
| | | /** Inherited collective subentry flag. */ |
| | | private boolean isInheritedCollective; |
| | | private final boolean isInheritedCollective; |
| | | /** Inherited collective from DN subentry flag. */ |
| | | private boolean isInheritedFromDNCollective; |
| | | private final boolean isInheritedFromDNCollective; |
| | | /** Inherited collective from RDN subentry flag. */ |
| | | private boolean isInheritedFromRDNCollective; |
| | | private final boolean isInheritedFromRDNCollective; |
| | | |
| | | /** Inherited collective DN attribute type. */ |
| | | private AttributeType inheritFromDNType; |
| | |
| | | private AttributeType inheritFromRDNAttrType; |
| | | /** Inherited collective RDN type attribute type. */ |
| | | private AttributeType inheritFromRDNType; |
| | | |
| | | /** Inherited collective RDN attribute value. */ |
| | | private ByteString inheritFromRDNAttrValue; |
| | | /** Inherited collective from DN value. */ |
| | |
| | | this.isInheritedFromDNCollective = entry.isInheritedFromDNCollectiveAttributeSubentry(); |
| | | this.isInheritedFromRDNCollective = entry.isInheritedFromRDNCollectiveAttributeSubentry(); |
| | | } |
| | | else |
| | | { |
| | | this.isInheritedFromDNCollective = false; |
| | | this.isInheritedFromRDNCollective = false; |
| | | } |
| | | |
| | | // Process collective attributes. |
| | | if (this.isCollective) |
| | |
| | | * refinement filters entries based on all of the underlying |
| | | * refinements being <code>true</code>. |
| | | */ |
| | | public static final class AndRefinement extends Refinement |
| | | private static final class AndRefinement extends Refinement |
| | | { |
| | | /** The set of refinements which must all be true. */ |
| | | private final Collection<Refinement> refinementSet; |
| | |
| | | * The set of refinements which must all be |
| | | * <code>true</code>. |
| | | */ |
| | | public AndRefinement(final Collection<Refinement> refinementSet) |
| | | private AndRefinement(final Collection<Refinement> refinementSet) |
| | | { |
| | | this.refinementSet = refinementSet; |
| | | } |
| | |
| | | * @param filter |
| | | * The search filter. |
| | | */ |
| | | public FilterRefinement(final SearchFilter filter) |
| | | private FilterRefinement(final SearchFilter filter) |
| | | { |
| | | this.filter = filter; |
| | | } |
| | |
| | | * refinement filters entries based on the presence of a specified |
| | | * object class. |
| | | */ |
| | | public static final class ItemRefinement extends Refinement |
| | | private static final class ItemRefinement extends Refinement |
| | | { |
| | | /** The item's object class. */ |
| | | private final String objectClass; |
| | |
| | | * @param objectClass |
| | | * The item's object class. |
| | | */ |
| | | public ItemRefinement(final String objectClass) |
| | | private ItemRefinement(final String objectClass) |
| | | { |
| | | this.objectClass = objectClass; |
| | | this.normalizedObjectClass = StaticUtils |
| | |
| | | * being <code>false</code> |
| | | * . |
| | | */ |
| | | public static final class NotRefinement extends Refinement |
| | | private static final class NotRefinement extends Refinement |
| | | { |
| | | /** The inverted refinement. */ |
| | | private final Refinement refinement; |
| | |
| | | * @param refinement |
| | | * The refinement which must be <code>false</code>. |
| | | */ |
| | | public NotRefinement(final Refinement refinement) |
| | | private NotRefinement(final Refinement refinement) |
| | | { |
| | | this.refinement = refinement; |
| | | } |
| | |
| | | * refinement filters entries based on at least one of the |
| | | * underlying refinements being <code>true</code>. |
| | | */ |
| | | public static final class OrRefinement extends Refinement |
| | | private static final class OrRefinement extends Refinement |
| | | { |
| | | /** The set of refinements of which at least one must be true. */ |
| | | private final Collection<Refinement> refinementSet; |
| | |
| | | * The set of refinements of which at least one must be |
| | | * <code>true</code>. |
| | | */ |
| | | public OrRefinement(final Collection<Refinement> refinementSet) |
| | | private OrRefinement(final Collection<Refinement> refinementSet) |
| | | { |
| | | this.refinementSet = refinementSet; |
| | | } |
| | |
| | | } |
| | | |
| | | /** Abstract interface for RFC3672 specification filter refinements. */ |
| | | public static abstract class Refinement |
| | | private static abstract class Refinement |
| | | { |
| | | /** Create a new RFC3672 specification filter refinement. */ |
| | | protected Refinement() |
| | |
| | | * Internal utility class which can be used by sub-classes to help |
| | | * parse string representations. |
| | | */ |
| | | protected static final class Parser |
| | | private static final class Parser |
| | | { |
| | | /** Text scanner used to parse the string value. */ |
| | | private final Scanner scanner; |
| | | |
| | | /** Pattern used to detect left braces. */ |
| | | private static Pattern LBRACE = Pattern.compile("\\{.*"); |
| | | private static final Pattern LBRACE = Pattern.compile("\\{.*"); |
| | | /** Pattern used to parse left braces. */ |
| | | private static Pattern LBRACE_TOKEN = Pattern.compile("\\{"); |
| | | private static final Pattern LBRACE_TOKEN = Pattern.compile("\\{"); |
| | | /** Pattern used to detect right braces. */ |
| | | private static Pattern RBRACE = Pattern.compile("\\}.*"); |
| | | private static final Pattern RBRACE = Pattern.compile("\\}.*"); |
| | | /** Pattern used to parse right braces. */ |
| | | private static Pattern RBRACE_TOKEN = Pattern.compile("\\}"); |
| | | private static final Pattern RBRACE_TOKEN = Pattern.compile("\\}"); |
| | | /** Pattern used to detect comma separators. */ |
| | | private static Pattern SEP = Pattern.compile(",.*"); |
| | | private static final Pattern SEP = Pattern.compile(",.*"); |
| | | /** Pattern used to parse comma separators. */ |
| | | private static Pattern SEP_TOKEN = Pattern.compile(","); |
| | | private static final Pattern SEP_TOKEN = Pattern.compile(","); |
| | | /** Pattern used to detect colon separators. */ |
| | | private static Pattern COLON = Pattern.compile(":.*"); |
| | | private static final Pattern COLON = Pattern.compile(":.*"); |
| | | /** Pattern used to parse colon separators. */ |
| | | private static Pattern COLON_TOKEN = Pattern.compile(":"); |
| | | private static final Pattern COLON_TOKEN = Pattern.compile(":"); |
| | | /** Pattern used to detect integer values. */ |
| | | private static Pattern INT = Pattern.compile("\\d.*"); |
| | | private static final Pattern INT = Pattern.compile("\\d.*"); |
| | | /** Pattern used to parse integer values. */ |
| | | private static Pattern INT_TOKEN = Pattern.compile("\\d+"); |
| | | private static final Pattern INT_TOKEN = Pattern.compile("\\d+"); |
| | | /** Pattern used to detect name values. */ |
| | | private static Pattern NAME = Pattern.compile("[\\w_;-].*"); |
| | | private static final Pattern NAME = Pattern.compile("[\\w_;-].*"); |
| | | /** Pattern used to parse name values. */ |
| | | private static Pattern NAME_TOKEN = Pattern.compile("[\\w_;-]+"); |
| | | private static final Pattern NAME_TOKEN = Pattern.compile("[\\w_;-]+"); |
| | | /** Pattern used to detect RFC3641 string values. */ |
| | | private static Pattern STRING_VALUE = Pattern.compile("\".*"); |
| | | private static final Pattern STRING_VALUE = Pattern.compile("\".*"); |
| | | /** Pattern used to parse RFC3641 string values. */ |
| | | private static Pattern STRING_VALUE_TOKEN = Pattern |
| | | private static final Pattern STRING_VALUE_TOKEN = Pattern |
| | | .compile("\"([^\"]|(\"\"))*\""); |
| | | |
| | | /** |
| | |
| | | * @param value |
| | | * The subtree specification string value. |
| | | */ |
| | | public Parser(final String value) |
| | | private Parser(final String value) |
| | | { |
| | | this.scanner = new Scanner(value); |
| | | } |
| | |
| | | * @return <code>true</code> if and only if there are remaining |
| | | * tokens. |
| | | */ |
| | | public boolean hasNext() |
| | | private boolean hasNext() |
| | | { |
| | | return scanner.hasNext(); |
| | | } |
| | |
| | | * @return <code>true</code> if and only if the next token is a |
| | | * valid right brace character. |
| | | */ |
| | | public boolean hasNextRightBrace() |
| | | private boolean hasNextRightBrace() |
| | | { |
| | | return scanner.hasNext(RBRACE); |
| | | } |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public int nextInt() throws InputMismatchException, |
| | | private int nextInt() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | final String s = nextValue(INT, INT_TOKEN); |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public String nextKey() throws InputMismatchException, |
| | | private String nextKey() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | return StaticUtils.toLowerCase(scanner.next()); |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public String nextName() throws InputMismatchException, |
| | | private String nextName() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | return nextValue(NAME, NAME_TOKEN); |
| | |
| | | * If an error occurred when attempting to parse a |
| | | * DN value. |
| | | */ |
| | | public void nextSpecificExclusions(final Set<DN> chopBefore, |
| | | private void nextSpecificExclusions(final Set<DN> chopBefore, |
| | | final Set<DN> chopAfter) throws InputMismatchException, |
| | | NoSuchElementException, DirectoryException |
| | | { |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public String nextStringValue() throws InputMismatchException, |
| | | private String nextStringValue() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | final String s = nextValue(STRING_VALUE, STRING_VALUE_TOKEN); |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public void skipColon() throws InputMismatchException, |
| | | private void skipColon() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | nextValue(COLON, COLON_TOKEN); |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public void skipLeftBrace() throws InputMismatchException, |
| | | private void skipLeftBrace() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | nextValue(LBRACE, LBRACE_TOKEN); |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public void skipRightBrace() throws InputMismatchException, |
| | | private void skipRightBrace() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | nextValue(RBRACE, RBRACE_TOKEN); |
| | |
| | | * @throws NoSuchElementException |
| | | * If input is exhausted. |
| | | */ |
| | | public void skipSeparator() throws InputMismatchException, |
| | | private void skipSeparator() throws InputMismatchException, |
| | | NoSuchElementException |
| | | { |
| | | nextValue(SEP, SEP_TOKEN); |
| | |
| | | |
| | | /** Optional set of chop before absolute DNs (mapping to their local-names). */ |
| | | private final Map<DN, DN> chopBefore; |
| | | |
| | | /** Optional set of chop after absolute DNs (mapping to their local-names). */ |
| | | private final Map<DN, DN> chopAfter; |
| | | |
| | | /** The root DN. */ |
| | | private final DN rootDN; |
| | | |
| | | /** The optional relative base DN. */ |
| | | private final DN relativeBaseDN; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.util.Utils; |
| | | import org.forgerock.opendj.server.config.meta.VirtualAttributeCfgDefn; |
| | | import org.forgerock.opendj.server.config.server.VirtualAttributeCfg; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.api.Group; |
| | | import org.opends.server.api.VirtualAttributeProvider; |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | // potentially most expensive are done last. First, check to see |
| | | // if real values should override virtual ones and if so whether |
| | | // the entry already has virtual values. |
| | | if (conflictBehavior == VirtualAttributeCfgDefn.ConflictBehavior. |
| | | REAL_OVERRIDES_VIRTUAL |
| | | && entry.hasAttribute(attributeType)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // If there are any base DNs defined, then the entry must be below one of them. |
| | | if (!baseDNs.isEmpty() && !matchesAnyBaseDN(entry.getName())) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // If there are any search filters defined, then the entry must match one of them. |
| | | if (!filters.isEmpty() && !matchesAnyFilter(entry)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // If there are any group memberships defined, then the entry must |
| | | // be a member of one of them. |
| | | if (!groupDNs.isEmpty() && !isMemberOfAnyGroup(entry)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // If we've gotten here, then the rule is applicable. |
| | | return true; |
| | | return (conflictBehavior != VirtualAttributeCfgDefn.ConflictBehavior.REAL_OVERRIDES_VIRTUAL |
| | | || !entry.hasAttribute(attributeType)) |
| | | // If there are any base DNs defined, then the entry must be below one of them. |
| | | && (baseDNs.isEmpty() || matchesAnyBaseDN(entry.getName())) |
| | | // If there are any search filters defined, then the entry must match one of them. |
| | | && (filters.isEmpty() || matchesAnyFilter(entry)) |
| | | // If there are any group memberships defined, then the entry must be a member of one of them. |
| | | && (groupDNs.isEmpty() || isMemberOfAnyGroup(entry)); |
| | | } |
| | | |
| | | private boolean matchesAnyBaseDN(DN entryDN) |
| | |
| | | * |
| | | * @param buffer The buffer to which the information should be written. |
| | | */ |
| | | public void toString(StringBuilder buffer) |
| | | private void toString(StringBuilder buffer) |
| | | { |
| | | buffer.append("VirtualAttributeRule(attrType="); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** |
| | | * The common prefix for archive files. |
| | | */ |
| | | /** The common prefix for archive files. */ |
| | | private static final String BACKUP_BASE_FILENAME = "backup-"; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static final String PROPERTY_LAST_LOGFILE_SIZE = "last_logfile_size"; |
| | | |
| | | |
| | | /** |
| | | * The name of the entry in an incremental backup archive file |
| | | * containing a list of log files that are unchanged since the |
| | |
| | | */ |
| | | private static final String ZIPENTRY_EMPTY_PLACEHOLDER = "empty.placeholder"; |
| | | |
| | | |
| | | /** |
| | | * The backend ID. |
| | | */ |
| | | /** The backend ID. */ |
| | | private final String backendID; |
| | | |
| | | /** |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message, e); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** Represents the cryptographic engine with no hash used for a backup. */ |
| | | private static final class NoHashCryptoEngine extends CryptoEngine |
| | | { |
| | | |
| | | NoHashCryptoEngine(boolean shouldEncrypt) |
| | | { |
| | | super(shouldEncrypt); |
| | |
| | | // check never fails because bytes are always null |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * Represents the cryptographic engine with signed hash. |
| | | */ |
| | | /** Represents the cryptographic engine with signed hash. */ |
| | | private static final class MacCryptoEngine extends CryptoEngine |
| | | { |
| | | private Mac mac; |
| | |
| | | private MacCryptoEngine(BackupInfo backupInfo) throws DirectoryException |
| | | { |
| | | super(backupInfo.isEncrypted()); |
| | | HashMap<String,String> backupProperties = backupInfo.getBackupProperties(); |
| | | Map<String, String> backupProperties = backupInfo.getBackupProperties(); |
| | | String macKeyID = backupProperties.get(BACKUP_PROPERTY_MAC_KEY_ID); |
| | | retrieveMacEngine(macKeyID); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | void updateHashWith(String s) |
| | | { |
| | | mac.update(getBytes(s)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | void updateHashWith(byte[] buffer, int offset, int len) |
| | | { |
| | |
| | | { |
| | | return "MacCryptoEngine [mac=" + mac + "]"; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** Represents the cryptographic engine with unsigned hash used for a backup. */ |
| | |
| | | private DigestCryptoEngine(BackupInfo backupInfo) throws DirectoryException |
| | | { |
| | | super(backupInfo.isEncrypted()); |
| | | HashMap<String, String> backupProperties = backupInfo.getBackupProperties(); |
| | | Map<String, String> backupProperties = backupInfo.getBackupProperties(); |
| | | String digestAlgorithm = backupProperties.get(BACKUP_PROPERTY_DIGEST_ALGORITHM); |
| | | digest = retrieveMessageDigest(digestAlgorithm); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void updateHashWith(String s) |
| | | { |
| | | digest.update(getBytes(s)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void updateHashWith(byte[] buffer, int offset, int len) |
| | | { |
| | | digest.update(buffer, offset, len); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] generateBytes() |
| | | { |
| | | return digest.digest(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | LocalizableMessage getErrorMessageForCheck(String backupID) |
| | | { |
| | |
| | | { |
| | | return "DigestCryptoEngine [digest=" + digest + "]"; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * Contains all parameters for creation of a new backup. |
| | | */ |
| | | /** Contains all parameters for creation of a new backup. */ |
| | | private static final class NewBackupParams |
| | | { |
| | | final String backupID; |
| | |
| | | { |
| | | return "BackupCreationParams [backupID=" + backupID + ", backupDir=" + backupDir.getPath() + "]"; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** Represents a new backup archive. */ |
| | | private static final class NewBackupArchive { |
| | | |
| | | private final String archiveFilename; |
| | | |
| | | private String latestFileName; |
| | |
| | | dependencies = new HashSet<>(); |
| | | if (backupParams.isIncremental) |
| | | { |
| | | HashMap<String,String> properties = backupParams.baseBackupInfo.getBackupProperties(); |
| | | Map<String, String> properties = backupParams.baseBackupInfo.getBackupProperties(); |
| | | latestFileName = properties.get(PROPERTY_LAST_LOGFILE_NAME); |
| | | latestFileSize = Long.parseLong(properties.get(PROPERTY_LAST_LOGFILE_SIZE)); |
| | | } |
| | |
| | | return "NewArchive [archive file=" + archiveFilename + ", latestFileName=" + latestFileName |
| | | + ", backendID=" + backendID + "]"; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** Represents an existing backup archive. */ |
| | | private static final class ExistingBackupArchive { |
| | | |
| | | private final String backupID; |
| | | private final BackupDirectory backupDir; |
| | | private final BackupInfo backupInfo; |
| | |
| | | |
| | | return archiveFile.delete(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** Represents a writer of a backup archive. */ |
| | | private static final class BackupArchiveWriter implements Closeable { |
| | | |
| | | private final ZipOutputStream zipOutputStream; |
| | | private final NewBackupArchive archive; |
| | | private final CryptoEngine cryptoEngine; |
| | |
| | | |
| | | cryptoMethod.updateHashWith(relativePath); |
| | | |
| | | InputStream inputStream = null; |
| | | long totalBytesRead = 0; |
| | | try { |
| | | inputStream = new FileInputStream(file.toFile()); |
| | | try (InputStream inputStream = new FileInputStream(file.toFile())) { |
| | | byte[] buffer = new byte[8192]; |
| | | int bytesRead = inputStream.read(buffer); |
| | | while (bytesRead > 0 && !backupConfig.isCancelled()) |
| | |
| | | bytesRead = inputStream.read(buffer); |
| | | } |
| | | } |
| | | finally { |
| | | StaticUtils.close(inputStream); |
| | | } |
| | | |
| | | zipOutputStream.closeEntry(); |
| | | logger.info(NOTE_BACKUP_ARCHIVED_FILE, zipEntry.getName()); |
| | |
| | | * <p> |
| | | * The unchanged files names are listed in the "unchanged.txt" file, which |
| | | * is put in the archive. |
| | | * |
| | | */ |
| | | void writeUnchangedFiles(Path rootDirectory, ListIterator<Path> files, BackupConfig backupConfig) |
| | | throws DirectoryException |
| | |
| | | archive.addBaseBackupAsDependency(); |
| | | } |
| | | |
| | | /** |
| | | * Writes the new files in the archive. |
| | | */ |
| | | /** Writes the new files in the archive. */ |
| | | void writeChangedFiles(Path rootDirectory, ListIterator<Path> files, BackupConfig backupConfig) |
| | | throws DirectoryException |
| | | { |
| | |
| | | return "BackupArchiveWriter [archive file=" + archive.getArchiveFilename() + ", backendId=" |
| | | + archive.getBackendID() + "]"; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** Represents a reader of a backup archive. */ |
| | | private static final class BackupArchiveReader { |
| | | |
| | | private final CryptoEngine cryptoEngine; |
| | | private final File archiveFile; |
| | | private final String identifier; |
| | |
| | | Set<String> readUnchangedDependentFiles() throws DirectoryException |
| | | { |
| | | Set<String> hashSet = new HashSet<>(); |
| | | ZipInputStream zipStream = null; |
| | | try |
| | | try (ZipInputStream zipStream = openZipStream()) |
| | | { |
| | | zipStream = openZipStream(); |
| | | |
| | | // Iterate through the entries in the zip file. |
| | | ZipEntry zipEntry = zipStream.getNextEntry(); |
| | |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), ERR_BACKUP_CANNOT_RESTORE.get( |
| | | identifier, stackTraceToSingleLineString(e)), e); |
| | | } |
| | | finally { |
| | | StaticUtils.close(zipStream); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | try |
| | | { |
| | | restoreArchive0(restoreDir, filesToRestore, restoreConfig, backupable); |
| | | restoreArchive0(restoreDir, filesToRestore, restoreConfig); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | |
| | | cryptoEngine.check(hash, backupInfo.getBackupID()); |
| | | } |
| | | |
| | | private void restoreArchive0(Path restoreDir, Set<String> filesToRestore, RestoreConfig restoreConfig, |
| | | Backupable backupable) throws DirectoryException, IOException { |
| | | |
| | | ZipInputStream zipStream = null; |
| | | try { |
| | | zipStream = openZipStream(); |
| | | |
| | | private void restoreArchive0(Path restoreDir, Set<String> filesToRestore, RestoreConfig restoreConfig) |
| | | throws DirectoryException, IOException |
| | | { |
| | | try (ZipInputStream zipStream = openZipStream()) |
| | | { |
| | | ZipEntry zipEntry = zipStream.getNextEntry(); |
| | | while (zipEntry != null && !restoreConfig.isCancelled()) |
| | | { |
| | |
| | | zipEntry = zipStream.getNextEntry(); |
| | | } |
| | | } |
| | | finally { |
| | | StaticUtils.close(zipStream); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return Pair.of(false, null); |
| | | } |
| | | |
| | | /** |
| | | * Restores a zip entry virtually (no actual write on disk). |
| | | */ |
| | | /** Restores a zip entry virtually (no actual write on disk). */ |
| | | private void restoreZipEntryVirtual(String zipEntryName, ZipInputStream zipStream, RestoreConfig restoreConfig) |
| | | throws FileNotFoundException, IOException |
| | | { |
| | |
| | | restoreFile(zipStream, null, restoreConfig); |
| | | } |
| | | |
| | | /** |
| | | * Restores a zip entry with actual write on disk. |
| | | */ |
| | | /** Restores a zip entry with actual write on disk. */ |
| | | private void restoreZipEntry(String zipEntryName, ZipInputStream zipStream, Path restoreDir, |
| | | RestoreConfig restoreConfig) throws IOException, DirectoryException |
| | | { |
| | | OutputStream outputStream = null; |
| | | long totalBytesRead = 0; |
| | | try |
| | | Path fileToRestore = restoreDir.resolve(zipEntryName); |
| | | ensureFileCanBeRestored(fileToRestore); |
| | | |
| | | try (OutputStream outputStream = new FileOutputStream(fileToRestore.toFile())) |
| | | { |
| | | Path fileToRestore = restoreDir.resolve(zipEntryName); |
| | | ensureFileCanBeRestored(fileToRestore); |
| | | outputStream = new FileOutputStream(fileToRestore.toFile()); |
| | | cryptoEngine.updateHashWith(zipEntryName); |
| | | totalBytesRead = restoreFile(zipStream, outputStream, restoreConfig); |
| | | long totalBytesRead = restoreFile(zipStream, outputStream, restoreConfig); |
| | | logger.info(NOTE_BACKUP_RESTORED_FILE, zipEntryName, totalBytesRead); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(outputStream); |
| | | } |
| | | } |
| | | |
| | | private void ensureFileCanBeRestored(Path fileToRestore) throws DirectoryException |
| | |
| | | final CryptoEngine cryptoEngine = CryptoEngine.forCreation(backupConfig, backupParams); |
| | | final NewBackupArchive newArchive = new NewBackupArchive(backendID, backupParams, cryptoEngine); |
| | | |
| | | BackupArchiveWriter archiveWriter = null; |
| | | try |
| | | final ListIterator<Path> files = backupable.getFilesToBackup(); |
| | | final Path rootDirectory = backupable.getDirectory().toPath(); |
| | | try (BackupArchiveWriter archiveWriter = new BackupArchiveWriter(newArchive)) |
| | | { |
| | | final ListIterator<Path> files = backupable.getFilesToBackup(); |
| | | final Path rootDirectory = backupable.getDirectory().toPath(); |
| | | archiveWriter = new BackupArchiveWriter(newArchive); |
| | | |
| | | if (files.hasNext()) |
| | | { |
| | | if (backupParams.isIncremental) { |
| | |
| | | archiveWriter.writeEmptyPlaceHolder(); |
| | | } |
| | | } |
| | | finally |
| | | catch (IOException e) |
| | | { |
| | | closeArchiveWriter(archiveWriter, newArchive.getArchiveFilename(), backupParams.backupDir.getPath()); |
| | | logger.traceException(e); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), ERR_BACKUP_CANNOT_CLOSE_ZIP_STREAM.get( |
| | | newArchive.getArchiveFilename(), backupParams.backupDir.getPath(), stackTraceToSingleLineString(e)), e); |
| | | } |
| | | |
| | | newArchive.updateBackupDirectory(); |
| | |
| | | } |
| | | return highestNumber; |
| | | } |
| | | |
| | | } |
| | |
| | | * @param point |
| | | * Point release version number. |
| | | */ |
| | | public BuildVersion(final int major, final int minor, final int point) |
| | | private BuildVersion(final int major, final int minor, final int point) |
| | | { |
| | | this(major, minor, point, ""); |
| | | } |
| | |
| | | * @param rev |
| | | * VCS revision. |
| | | */ |
| | | public BuildVersion(final int major, final int minor, final int point, final String rev) |
| | | private BuildVersion(final int major, final int minor, final int point, final String rev) |
| | | { |
| | | this.major = major; |
| | | this.minor = minor; |
| | |
| | | |
| | | |
| | | |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileReader; |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.server.core.DirectoryServer; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.StringArgument; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | private List<String> recipients; |
| | | |
| | | /** The set of attachments to include in this message. */ |
| | | private LinkedList<MimeBodyPart> attachments; |
| | | private final List<MimeBodyPart> attachments; |
| | | |
| | | /** The MIME type for the message body. */ |
| | | private String bodyMIMEType; |
| | |
| | | /** The body for the mail message. */ |
| | | private LocalizableMessageBuilder body; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new e-mail message with the provided information. |
| | | * |
| | | * @param sender The address of the sender for the message. |
| | | * @param recipient The address of the recipient for the message. |
| | | * @param subject The subject to use for the message. |
| | | */ |
| | | public EMailMessage(String sender, String recipient, String subject) |
| | | { |
| | | this.sender = sender; |
| | | this.subject = subject; |
| | | |
| | | recipients = CollectionUtils.newArrayList(recipient); |
| | | |
| | | body = new LocalizableMessageBuilder(); |
| | | attachments = new LinkedList<>(); |
| | | bodyMIMEType = "text/plain"; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new e-mail message with the provided information. |
| | | * |
| | |
| | | * |
| | | * @return The set of attachments for this message. |
| | | */ |
| | | public LinkedList<MimeBodyPart> getAttachments() |
| | | public List<MimeBodyPart> getAttachments() |
| | | { |
| | | return attachments; |
| | | } |
| | |
| | | * @throws MessagingException If there is a problem of some type with the |
| | | * attachment. |
| | | */ |
| | | public void addAttachment(File attachmentFile) |
| | | private void addAttachment(File attachmentFile) |
| | | throws MessagingException |
| | | { |
| | | MimeBodyPart attachment = new MimeBodyPart(); |
| | |
| | | * @throws MessagingException If a problem occurred while attempting to send |
| | | * the message. |
| | | */ |
| | | public void send(List<Properties> mailServerPropertySets) |
| | | private void send(List<Properties> mailServerPropertySets) |
| | | throws MessagingException |
| | | { |
| | | // Get information about the available mail servers that we can use. |
| | |
| | | // If we've gotten here, then we've tried all of the servers in the list and |
| | | // still failed. If we captured an earlier exception, then throw it. |
| | | // Otherwise, throw a generic exception. |
| | | if (sendException == null) |
| | | { |
| | | LocalizableMessage message = ERR_EMAILMSG_CANNOT_SEND.get(); |
| | | throw new MessagingException(message.toString()); |
| | | } |
| | | else |
| | | if (sendException != null) |
| | | { |
| | | throw sendException; |
| | | } |
| | | throw new MessagingException(ERR_EMAILMSG_CANNOT_SEND.get().toString()); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | /** The reader that will be used to read the data. */ |
| | | private BufferedReader reader; |
| | | |
| | | /** The import configuration that specifies what should be imported. */ |
| | | protected LDIFImportConfig importConfig; |
| | | protected final LDIFImportConfig importConfig; |
| | | |
| | | /** The lines that comprise the body of the last entry read. */ |
| | | protected List<StringBuilder> lastEntryBodyLines; |
| | | |
| | | /** |
| | | * The lines that comprise the header (DN and any comments) for the last entry |
| | | * read. |
| | | */ |
| | | /** The lines that comprise the header (DN and any comments) for the last entry read. */ |
| | | protected List<StringBuilder> lastEntryHeaderLines; |
| | | |
| | | |
| | | /** |
| | | * The number of entries that have been ignored by this LDIF reader because |
| | | * they didn't match the criteria. |
| | | */ |
| | | private final AtomicLong entriesIgnored = new AtomicLong(); |
| | | |
| | | /** |
| | | * The number of entries that have been read by this LDIF reader, including |
| | | * those that were ignored because they didn't match the criteria, and |
| | | * including those that were rejected because they were invalid in some way. |
| | | */ |
| | | protected final AtomicLong entriesRead = new AtomicLong(); |
| | | |
| | | /** The number of entries that have been rejected by this LDIF reader. */ |
| | | private final AtomicLong entriesRejected = new AtomicLong(); |
| | | |
| | | /** The line number on which the last entry started. */ |
| | | protected long lastEntryLineNumber = -1; |
| | | |
| | | /** |
| | | * The line number of the last line read from the LDIF file, starting with 1. |
| | | */ |
| | | /** The line number of the last line read from the LDIF file, starting with 1. */ |
| | | private long lineNumber; |
| | | |
| | | /** |
| | | * The plugin config manager that will be used if we are to invoke plugins on |
| | | * the entries as they are read. |
| | | */ |
| | | protected PluginConfigManager pluginConfigManager; |
| | | protected final PluginConfigManager pluginConfigManager; |
| | | |
| | | /** |
| | | * Creates a new LDIF reader that will read information from the specified |
| | |
| | | logToSkipWriter(lines, ERR_LDIF_SKIP.get(entryDN)); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | ERR_LDIF_COULD_NOT_EVALUATE_FILTERS_FOR_IMPORT.get(entry.getName(), lastEntryLineNumber, e); |
| | | throw new LDIFException(message, lastEntryLineNumber, true, e); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private boolean invokeImportPlugins(Entry entry, LinkedList<StringBuilder> lines) |
| | |
| | | if (!pluginResult.continueProcessing()) |
| | | { |
| | | final DN entryDN = entry.getName(); |
| | | LocalizableMessage m; |
| | | LocalizableMessage rejectMessage = pluginResult.getErrorMessage(); |
| | | if (rejectMessage == null) |
| | | { |
| | | m = ERR_LDIF_REJECTED_BY_PLUGIN_NOMESSAGE.get(entryDN); |
| | | } |
| | | else |
| | | { |
| | | m = ERR_LDIF_REJECTED_BY_PLUGIN.get(entryDN, rejectMessage); |
| | | } |
| | | LocalizableMessage m = rejectMessage != null |
| | | ? ERR_LDIF_REJECTED_BY_PLUGIN.get(entryDN, rejectMessage) |
| | | : ERR_LDIF_REJECTED_BY_PLUGIN_NOMESSAGE.get(entryDN); |
| | | |
| | | logToRejectWriter(lines, m); |
| | | return false; |
| | |
| | | * @param builders the list of AttributeBuilders |
| | | * @return a new list of Attributes |
| | | */ |
| | | protected List<Attribute> toAttributesList(List<AttributeBuilder> builders) |
| | | private List<Attribute> toAttributesList(List<AttributeBuilder> builders) |
| | | { |
| | | List<Attribute> results = new ArrayList<>(builders.size()); |
| | | for (AttributeBuilder builder : builders) |
| | |
| | | } |
| | | |
| | | String changeType = readChangeType(lines); |
| | | |
| | | ChangeRecordEntry entry; |
| | | |
| | | if(changeType != null) |
| | | { |
| | | if(changeType.equals("add")) |
| | | switch (changeType) |
| | | { |
| | | entry = parseAddChangeRecordEntry(entryDN, lines); |
| | | } else if (changeType.equals("delete")) |
| | | { |
| | | entry = parseDeleteChangeRecordEntry(entryDN, lines); |
| | | } else if (changeType.equals("modify")) |
| | | { |
| | | entry = parseModifyChangeRecordEntry(entryDN, lines); |
| | | } else if (changeType.equals("modrdn")) |
| | | { |
| | | entry = parseModifyDNChangeRecordEntry(entryDN, lines); |
| | | } else if (changeType.equals("moddn")) |
| | | { |
| | | entry = parseModifyDNChangeRecordEntry(entryDN, lines); |
| | | } else |
| | | { |
| | | case "add": |
| | | return parseAddChangeRecordEntry(entryDN, lines); |
| | | case "delete": |
| | | return parseDeleteChangeRecordEntry(entryDN, lines); |
| | | case "modify": |
| | | return parseModifyChangeRecordEntry(entryDN, lines); |
| | | case "modrdn": |
| | | return parseModifyDNChangeRecordEntry(entryDN, lines); |
| | | case "moddn": |
| | | return parseModifyDNChangeRecordEntry(entryDN, lines); |
| | | default: |
| | | LocalizableMessage message = ERR_LDIF_INVALID_CHANGETYPE_ATTRIBUTE.get( |
| | | changeType, "add, delete, modify, moddn, modrdn"); |
| | | throw new LDIFException(message, lastEntryLineNumber, false); |
| | | } |
| | | } else |
| | | { |
| | | // default to "add"? |
| | | if(defaultAdd) |
| | | { |
| | | entry = parseAddChangeRecordEntry(entryDN, lines); |
| | | } else |
| | | { |
| | | LocalizableMessage message = ERR_LDIF_INVALID_CHANGETYPE_ATTRIBUTE.get( |
| | | null, "add, delete, modify, moddn, modrdn"); |
| | | throw new LDIFException(message, lastEntryLineNumber, false); |
| | | } |
| | | } |
| | | |
| | | return entry; |
| | | else if (defaultAdd) |
| | | { |
| | | // default to "add" |
| | | return parseAddChangeRecordEntry(entryDN, lines); |
| | | } |
| | | else |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_LDIF_INVALID_CHANGETYPE_ATTRIBUTE.get(null, "add, delete, modify, moddn, modrdn"); |
| | | throw new LDIFException(message, lastEntryLineNumber, false); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | protected LinkedList<StringBuilder> readEntryLines() throws IOException, LDIFException |
| | | { |
| | | // Read the entry lines into a buffer. |
| | | LinkedList<StringBuilder> lines = new LinkedList<>(); |
| | | int lastLine = -1; |
| | | |
| | | if(reader == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | // Read the entry lines into a buffer. |
| | | LinkedList<StringBuilder> lines = new LinkedList<>(); |
| | | int lastLine = -1; |
| | | while (true) |
| | | { |
| | | String line = reader.readLine(); |
| | |
| | | break; |
| | | } |
| | | reader = importConfig.nextReader(); |
| | | if (reader != null) |
| | | { |
| | | return readEntryLines(); |
| | | } |
| | | return null; |
| | | return reader != null ? readEntryLines() : null; |
| | | } |
| | | else if (line.length() == 0) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Closes this LDIF reader and the underlying file or input stream. |
| | | */ |
| | | /** Closes this LDIF reader and the underlying file or input stream. */ |
| | | @Override |
| | | public void close() |
| | | { |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | | import static org.forgerock.util.Utils.closeSilently; |
| | | |
| | | import java.io.*; |
| | | import java.io.BufferedReader; |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.FileReader; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | import java.net.Socket; |
| | |
| | | public static final String OPENDJ_JAVA_ARGS = "OPENDJ_JAVA_ARGS"; |
| | | |
| | | /** |
| | | * Java property used to know which are the jar files that must be downloaded |
| | | * lazily. The current code in WebStartDownloader that uses this property |
| | | * assumes that the URL are separated with an space. |
| | | */ |
| | | public static final String LAZY_JAR_URLS = |
| | | "org.opends.quicksetup.lazyjarurls"; |
| | | |
| | | /** |
| | | * Java property used to know which is the name of the zip file that must |
| | | * be unzipped and whose contents must be extracted during the Web Start |
| | | * based setup. |
| | | */ |
| | | public static final String ZIP_FILE_NAME = |
| | | "org.opends.quicksetup.zipfilename"; |
| | | |
| | | /** |
| | | * The relative path where all the libraries (jar files) are. |
| | | */ |
| | | public static final String LIBRARIES_PATH_RELATIVE = "lib"; |
| | |
| | | public static final String URL_REPOSITORY = "URL Repository"; |
| | | /** The version qualifier. */ |
| | | public static final String VERSION_QUALIFIER = "Version Qualifier"; |
| | | /** Incompatibilities found between builds (used by the upgrade tool). */ |
| | | public static final String INCOMPATIBILITY_EVENTS = "Upgrade Event IDs"; |
| | | /** Fix IDs associated with the build. */ |
| | | public static final String FIX_IDS = "Fix IDs"; |
| | | /** Debug build identifier. */ |
| | |
| | | lines.add("description: This is the description for {cn}."); |
| | | } |
| | | |
| | | BufferedWriter writer = new BufferedWriter(new FileWriter(templateFile)); |
| | | for (String line : lines) |
| | | try (BufferedWriter writer = new BufferedWriter(new FileWriter(templateFile))) |
| | | { |
| | | writer.write(line); |
| | | writer.newLine(); |
| | | for (String line : lines) |
| | | { |
| | | writer.write(line); |
| | | writer.newLine(); |
| | | } |
| | | } |
| | | |
| | | writer.flush(); |
| | | writer.close(); |
| | | |
| | | return templateFile; |
| | | } |
| | | |
| | |
| | | * @return {@code true} if the provided port is free and we can use it, |
| | | * {@code false} otherwise. |
| | | */ |
| | | public static boolean canUseAsPort(String hostname, int port) |
| | | private static boolean canUseAsPort(String hostname, int port) |
| | | { |
| | | boolean canUseAsPort = false; |
| | | ServerSocket serverSocket = null; |
| | | try |
| | | try (ServerSocket serverSocket = new ServerSocket()) |
| | | { |
| | | InetSocketAddress socketAddress; |
| | | if (hostname != null) |
| | |
| | | { |
| | | socketAddress = new InetSocketAddress(port); |
| | | } |
| | | serverSocket = new ServerSocket(); |
| | | if (!OperatingSystem.isWindows()) |
| | | { |
| | | serverSocket.setReuseAddress(true); |
| | | } |
| | | serverSocket.bind(socketAddress); |
| | | canUseAsPort = true; |
| | | |
| | | serverSocket.close(); |
| | | |
| | | /* Try to create a socket because sometimes even if we can create a server |
| | | * socket there is already someone listening to the port (is the case |
| | | * of products as Sun DS 6.0). |
| | | */ |
| | | Socket s = null; |
| | | try |
| | | try (Socket s = new Socket()) |
| | | { |
| | | s = new Socket(); |
| | | s.connect(socketAddress, 1000); |
| | | canUseAsPort = false; |
| | | return false; |
| | | } catch (Throwable t) |
| | | { |
| | | } |
| | | finally |
| | | { |
| | | if (s != null) |
| | | { |
| | | try |
| | | { |
| | | s.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } catch (IOException ex) |
| | | { |
| | | canUseAsPort = false; |
| | | } finally |
| | | { |
| | | try |
| | | { |
| | | if (serverSocket != null) |
| | | { |
| | | serverSocket.close(); |
| | | } |
| | | } catch (Exception ex) |
| | | { |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | return canUseAsPort; |
| | | } |
| | | |
| | | /** |
| | |
| | | certManager.getCertificate(alias != null ? alias : certManager.getCertificateAliases()[0]); |
| | | byte[] certificateBytes = certificate.getEncoded(); |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(path, false); |
| | | try |
| | | try (FileOutputStream outputStream = new FileOutputStream(path, false)) |
| | | { |
| | | outputStream.write(certificateBytes); |
| | | } |
| | | finally |
| | | { |
| | | closeSilently(outputStream); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | String hostName = null; |
| | | File f = new File(installationRoot + File.separator + HOST_NAME_FILE); |
| | | BufferedReader br = null; |
| | | try |
| | | try (BufferedReader br = new BufferedReader(new FileReader(f))) |
| | | { |
| | | br = new BufferedReader(new FileReader(f)); |
| | | String s = br.readLine(); |
| | | s = s.trim(); |
| | | |
| | |
| | | catch (IOException ioe) |
| | | { |
| | | } |
| | | finally |
| | | { |
| | | closeSilently(br); |
| | | } |
| | | if (hostName == null) |
| | | { |
| | | hostName = lastReadHostName; |
| | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.Closeable; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.InetAddress; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | import java.net.Socket; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.channels.SelectionKey; |
| | | import java.nio.channels.Selector; |
| | | import java.nio.channels.SocketChannel; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.RandomAccess; |
| | | import java.util.TimeZone; |
| | | |
| | | import javax.naming.InitialContext; |
| | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.messages.ToolMessages; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ServerContext; |
| | | import org.opends.server.types.Attribute; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Appends a string representation of the remaining unread data in the |
| | | * provided byte buffer to the given buffer using the specified indent. |
| | | * The data will be formatted with sixteen hex bytes in a row followed by |
| | | * the ASCII representation, then wrapping to a new line as necessary. |
| | | * The state of the byte buffer is not changed. |
| | | * |
| | | * @param buffer The buffer to which the information is to be appended. |
| | | * @param b The byte buffer containing the data to write. |
| | | * The data from the position to the limit is written. |
| | | * @param indent The number of spaces to indent the output. |
| | | */ |
| | | public static void byteArrayToHexPlusAscii(StringBuilder buffer, ByteBuffer b, |
| | | int indent) |
| | | { |
| | | StringBuilder indentBuf = new StringBuilder(indent); |
| | | for (int i=0 ; i < indent; i++) |
| | | { |
| | | indentBuf.append(' '); |
| | | } |
| | | |
| | | |
| | | int position = b.position(); |
| | | int limit = b.limit(); |
| | | int length = limit - position; |
| | | int pos = 0; |
| | | while (length - pos >= 16) |
| | | { |
| | | StringBuilder asciiBuf = new StringBuilder(17); |
| | | |
| | | byte currentByte = b.get(); |
| | | buffer.append(indentBuf); |
| | | buffer.append(byteToHex(currentByte)); |
| | | asciiBuf.append(byteToASCII(currentByte)); |
| | | pos++; |
| | | |
| | | for (int i=1; i < 16; i++, pos++) |
| | | { |
| | | currentByte = b.get(); |
| | | buffer.append(' '); |
| | | buffer.append(byteToHex(currentByte)); |
| | | asciiBuf.append(byteToASCII(currentByte)); |
| | | |
| | | if (i == 7) |
| | | { |
| | | buffer.append(" "); |
| | | asciiBuf.append(' '); |
| | | } |
| | | } |
| | | |
| | | buffer.append(" "); |
| | | buffer.append(asciiBuf); |
| | | buffer.append(EOL); |
| | | } |
| | | |
| | | |
| | | int remaining = length - pos; |
| | | if (remaining > 0) |
| | | { |
| | | StringBuilder asciiBuf = new StringBuilder(remaining+1); |
| | | |
| | | byte currentByte = b.get(); |
| | | buffer.append(indentBuf); |
| | | buffer.append(byteToHex(currentByte)); |
| | | asciiBuf.append(byteToASCII(currentByte)); |
| | | |
| | | for (int i=1; i < 16; i++) |
| | | { |
| | | buffer.append(' '); |
| | | |
| | | if (i < remaining) |
| | | { |
| | | currentByte = b.get(); |
| | | buffer.append(byteToHex(currentByte)); |
| | | asciiBuf.append(byteToASCII(currentByte)); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(" "); |
| | | } |
| | | |
| | | if (i == 7) |
| | | { |
| | | buffer.append(" "); |
| | | |
| | | if (i < remaining) |
| | | { |
| | | asciiBuf.append(' '); |
| | | } |
| | | } |
| | | } |
| | | |
| | | buffer.append(" "); |
| | | buffer.append(asciiBuf); |
| | | buffer.append(EOL); |
| | | } |
| | | |
| | | b.position(position); |
| | | b.limit(limit); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Compare two byte arrays for order. Returns a negative integer, |
| | | * zero, or a positive integer as the first argument is less than, |
| | | * equal to, or greater than the second. |
| | |
| | | return a.length - a2.length; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the two array lists are equal. They will be |
| | | * considered equal if they have the same number of elements, and |
| | | * the corresponding elements between them are equal (in the same |
| | | * order). |
| | | * |
| | | * @param list1 |
| | | * The first list for which to make the determination. |
| | | * @param list2 |
| | | * The second list for which to make the determination. |
| | | * @return {@code true} if the two array lists are equal, or |
| | | * {@code false} if they are not. |
| | | */ |
| | | public static boolean listsAreEqual(List<?> list1, List<?> list2) |
| | | { |
| | | if (list1 == null) |
| | | { |
| | | return list2 == null; |
| | | } |
| | | else if (list2 == null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | int numElements = list1.size(); |
| | | if (numElements != list2.size()) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // If either of the lists doesn't support random access, then fall back |
| | | // on their equals methods and go ahead and create some garbage with the |
| | | // iterators. |
| | | if (!(list1 instanceof RandomAccess) || |
| | | !(list2 instanceof RandomAccess)) |
| | | { |
| | | return list1.equals(list2); |
| | | } |
| | | |
| | | // Otherwise we can just retrieve the elements efficiently via their index. |
| | | for (int i=0; i < numElements; i++) |
| | | { |
| | | Object o1 = list1.get(i); |
| | | Object o2 = list2.get(i); |
| | | |
| | | if (o1 == null) |
| | | { |
| | | if (o2 != null) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | else if (! o1.equals(o2)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the best human-readable message for the provided exception. For |
| | | * exceptions defined in the OpenDJ project, it will attempt to use the |
| | |
| | | return com.forgerock.opendj.util.StaticUtils.stackTraceToSingleLineString(t, DynamicConstants.DEBUG_BUILD); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Appends a single-line string representation of the provided exception to |
| | | * the given buffer. |
| | | * |
| | | * @param buffer The buffer to which the information is to be appended. |
| | | * @param t The exception for which to retrieve the stack trace. |
| | | */ |
| | | public static void stackTraceToSingleLineString(StringBuilder buffer, |
| | | Throwable t) |
| | | { |
| | | com.forgerock.opendj.util.StaticUtils.stackTraceToSingleLineString(buffer, t, DynamicConstants.DEBUG_BUILD); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a string representation of the stack trace for the provided |
| | | * exception. |
| | |
| | | * @param buffer The buffer to which the information is to be appended. |
| | | * @param t The exception for which to retrieve the stack trace. |
| | | */ |
| | | public static void stackTraceToString(StringBuilder buffer, Throwable t) |
| | | private static void stackTraceToString(StringBuilder buffer, Throwable t) |
| | | { |
| | | if (t == null) |
| | | { |
| | |
| | | * @return {@code true} if the use of the exec method should be allowed, |
| | | * or {@code false} if it should not be allowed. |
| | | */ |
| | | public static boolean mayUseExec() |
| | | private static boolean mayUseExec() |
| | | { |
| | | return !DirectoryServer.getEnvironmentConfig().disableExec(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Executes the specified command on the system and captures its output. This |
| | | * will not return until the specified process has completed. |
| | | * |
| | | * @param command The command to execute. |
| | | * @param args The set of arguments to provide to the command. |
| | | * @param workingDirectory The working directory to use for the command, or |
| | | * {@code null} if the default directory |
| | | * should be used. |
| | | * @param environment The set of environment variables that should be |
| | | * set when executing the command, or |
| | | * {@code null} if none are needed. |
| | | * @param output The output generated by the command while it was |
| | | * running. This will include both standard |
| | | * output and standard error. It may be |
| | | * {@code null} if the output does not need to |
| | | * be captured. |
| | | * |
| | | * @return The exit code for the command. |
| | | * |
| | | * @throws IOException If an I/O problem occurs while trying to execute the |
| | | * command. |
| | | * |
| | | * @throws SecurityException If the security policy will not allow the |
| | | * command to be executed. |
| | | * |
| | | * @throws InterruptedException If the current thread is interrupted by |
| | | * another thread while it is waiting, then |
| | | * the wait is ended and an InterruptedException |
| | | * is thrown. |
| | | */ |
| | | public static int exec(String command, String[] args, File workingDirectory, |
| | | Map<String,String> environment, List<String> output) |
| | | throws IOException, SecurityException, InterruptedException |
| | | { |
| | | // See whether we'll allow the use of exec on this system. If not, then |
| | | // throw an exception. |
| | | if (! mayUseExec()) |
| | | { |
| | | throw new SecurityException(ERR_EXEC_DISABLED.get(command).toString()); |
| | | } |
| | | |
| | | |
| | | ArrayList<String> commandAndArgs = new ArrayList<>(); |
| | | commandAndArgs.add(command); |
| | | if (args != null && args.length > 0) |
| | | { |
| | | Collections.addAll(commandAndArgs, args); |
| | | } |
| | | |
| | | ProcessBuilder processBuilder = new ProcessBuilder(commandAndArgs); |
| | | processBuilder.redirectErrorStream(true); |
| | | |
| | | if (workingDirectory != null && workingDirectory.isDirectory()) |
| | | { |
| | | processBuilder.directory(workingDirectory); |
| | | } |
| | | |
| | | if (environment != null && !environment.isEmpty()) |
| | | { |
| | | processBuilder.environment().putAll(environment); |
| | | } |
| | | |
| | | Process process = processBuilder.start(); |
| | | |
| | | // We must exhaust stdout and stderr before calling waitfor. Since we |
| | | // redirected the error stream, we just have to read from stdout. |
| | | InputStream processStream = process.getInputStream(); |
| | | BufferedReader reader = |
| | | new BufferedReader(new InputStreamReader(processStream)); |
| | | String line = null; |
| | | |
| | | try |
| | | { |
| | | while((line = reader.readLine()) != null) |
| | | { |
| | | if(output != null) |
| | | { |
| | | output.add(line); |
| | | } |
| | | } |
| | | } |
| | | catch(IOException ioe) |
| | | { |
| | | // If this happens, then we have no choice but to forcefully terminate |
| | | // the process. |
| | | try |
| | | { |
| | | process.destroy(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | } |
| | | |
| | | throw ioe; |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch(IOException e) |
| | | { |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | |
| | | return process.waitFor(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided string contains a name or OID for a schema |
| | | * element like an attribute type or objectclass. |
| | |
| | | * @param buffer The buffer to which the uppercase form of the string should |
| | | * be appended. |
| | | */ |
| | | public static void toUpperCase(String s, StringBuilder buffer) |
| | | private static void toUpperCase(String s, StringBuilder buffer) |
| | | { |
| | | if (s == null) |
| | | { |
| | |
| | | return builder; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a string array containing the contents of the provided |
| | | * list of strings. |
| | | * |
| | | * @param stringList |
| | | * The string list to convert to an array. |
| | | * @return A string array containing the contents of the provided list |
| | | * of strings. |
| | | */ |
| | | public static String[] listToArray(List<String> stringList) |
| | | { |
| | | if (stringList == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | String[] stringArray = new String[stringList.size()]; |
| | | stringList.toArray(stringArray); |
| | | return stringArray; |
| | | } |
| | | |
| | | /** |
| | | * Retrieves an array list containing the contents of the provided array. |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided path refers to a relative path rather than |
| | | * an absolute path. |
| | | * |
| | | * @param path The path string for which to make the determination. |
| | | * |
| | | * @return {@code true} if the provided path is relative, or |
| | | * {@code false} if it is absolute. |
| | | */ |
| | | public static boolean isRelativePath(String path) |
| | | { |
| | | File f = new File(path); |
| | | return !f.isAbsolute(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a {@code File} object corresponding to the specified path. |
| | | * If the given path is an absolute path, then it will be used. If the path |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Writes the contents of the provided buffer to the client, |
| | | * terminating the connection if the write is unsuccessful for too |
| | | * long (e.g., if the client is unresponsive or there is a network |
| | | * problem). If possible, it will attempt to use the selector returned |
| | | * by the {@code ClientConnection.getWriteSelector} method, but it is |
| | | * capable of working even if that method returns {@code null}. <BR> |
| | | * |
| | | * Note that the original position and limit values will not be |
| | | * preserved, so if that is important to the caller, then it should |
| | | * record them before calling this method and restore them after it |
| | | * returns. |
| | | * |
| | | * @param clientConnection |
| | | * The client connection to which the data is to be written. |
| | | * @param buffer |
| | | * The data to be written to the client. |
| | | * @return {@code true} if all the data in the provided buffer was |
| | | * written to the client and the connection may remain |
| | | * established, or {@code false} if a problem occurred |
| | | * and the client connection is no longer valid. Note that if |
| | | * this method does return {@code false}, then it must |
| | | * have already disconnected the client. |
| | | * @throws IOException |
| | | * If a problem occurs while attempting to write data to the |
| | | * client. The caller will be responsible for catching this |
| | | * and terminating the client connection. |
| | | */ |
| | | public static boolean writeWithTimeout(ClientConnection clientConnection, |
| | | ByteBuffer buffer) throws IOException |
| | | { |
| | | SocketChannel socketChannel = clientConnection.getSocketChannel(); |
| | | long startTime = System.currentTimeMillis(); |
| | | long waitTime = clientConnection.getMaxBlockedWriteTimeLimit(); |
| | | if (waitTime <= 0) |
| | | { |
| | | // We won't support an infinite time limit, so fall back to using |
| | | // five minutes, which is a very long timeout given that we're |
| | | // blocking a worker thread. |
| | | waitTime = 300000L; |
| | | } |
| | | |
| | | long stopTime = startTime + waitTime; |
| | | |
| | | Selector selector = clientConnection.getWriteSelector(); |
| | | if (selector == null) |
| | | { |
| | | // The client connection does not provide a selector, so we'll |
| | | // fall back |
| | | // to a more inefficient way that will work without a selector. |
| | | while (buffer.hasRemaining() |
| | | && System.currentTimeMillis() < stopTime) |
| | | { |
| | | if (socketChannel.write(buffer) < 0) |
| | | { |
| | | // The client connection has been closed. |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if (buffer.hasRemaining()) |
| | | { |
| | | // If we've gotten here, then the write timed out. |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | // Register with the selector for handling write operations. |
| | | SelectionKey key = |
| | | socketChannel.register(selector, SelectionKey.OP_WRITE); |
| | | |
| | | try |
| | | { |
| | | selector.select(waitTime); |
| | | while (buffer.hasRemaining()) |
| | | { |
| | | long currentTime = System.currentTimeMillis(); |
| | | if (currentTime >= stopTime) |
| | | { |
| | | // We've been blocked for too long. |
| | | return false; |
| | | } |
| | | waitTime = stopTime - currentTime; |
| | | |
| | | Iterator<SelectionKey> iterator = |
| | | selector.selectedKeys().iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | SelectionKey k = iterator.next(); |
| | | if (k.isWritable()) |
| | | { |
| | | int bytesWritten = socketChannel.write(buffer); |
| | | if (bytesWritten < 0) |
| | | { |
| | | // The client connection has been closed. |
| | | return false; |
| | | } |
| | | |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | |
| | | if (buffer.hasRemaining()) |
| | | { |
| | | selector.select(waitTime); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | finally |
| | | { |
| | | if (key.isValid()) |
| | | { |
| | | key.cancel(); |
| | | selector.selectNow(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Add all of the superior objectclasses to the specified objectclass |
| | | * map if they don't already exist. Used by add and import-ldif to |
| | |
| | | * @return {@code true} if message corresponds to descriptor |
| | | */ |
| | | public static boolean hasDescriptor(LocalizableMessage msg, |
| | | LocalizableMessageDescriptor.Arg2<?, ?> desc) |
| | | { |
| | | return msg.ordinal() == desc.ordinal() |
| | | && msg.resourceName().equals(desc.resourceName()); |
| | | } |
| | | |
| | | /** |
| | | * Test if the provided message corresponds to the provided descriptor. |
| | | * |
| | | * @param msg |
| | | * The i18n message. |
| | | * @param desc |
| | | * The message descriptor. |
| | | * @return {@code true} if message corresponds to descriptor |
| | | */ |
| | | public static boolean hasDescriptor(LocalizableMessage msg, |
| | | LocalizableMessageDescriptor.Arg3<?, ?, ?> desc) |
| | | { |
| | | return msg.ordinal() == desc.ordinal() |
| | |
| | | */ |
| | | package org.opends.server.util.cli; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import java.io.PrintStream; |
| | | import java.util.LinkedList; |
| | | import java.util.Set; |
| | |
| | | */ |
| | | public class LDAPConnectionArgumentParser extends ArgumentParser |
| | | { |
| | | |
| | | private SecureConnectionCliArgs args; |
| | | |
| | | /** |
| | |
| | | * with which to connect |
| | | * @param options |
| | | * with which to connect |
| | | * @param out |
| | | * stream to write messages |
| | | * @param err |
| | | * stream to write error messages |
| | | * @return LDAPConnection created by this class from parsed arguments |
| | | * @throws LDAPConnectionException |
| | | * if there was a problem connecting to the server indicated by the |
| | | * input arguments |
| | | */ |
| | | public LDAPConnection connect(String host, int port, String bindDN, String bindPw, LDAPConnectionOptions options, |
| | | PrintStream out, PrintStream err) throws LDAPConnectionException |
| | | { |
| | | return connect(host, port, bindDN, bindPw, options, 0, out, err); |
| | | } |
| | | |
| | | /** |
| | | * Creates a connection from information provided. |
| | | * |
| | | * @param host |
| | | * of the server |
| | | * @param port |
| | | * of the server |
| | | * @param bindDN |
| | | * with which to connect |
| | | * @param bindPw |
| | | * with which to connect |
| | | * @param options |
| | | * with which to connect |
| | | * @param timeout |
| | | * the timeout to establish the connection in milliseconds. Use |
| | | * {@code 0} to express no timeout |
| | |
| | | * if there was a problem connecting to the server indicated by the |
| | | * input arguments |
| | | */ |
| | | public LDAPConnection connect(String host, int port, String bindDN, String bindPw, LDAPConnectionOptions options, |
| | | private LDAPConnection connect(String host, int port, String bindDN, String bindPw, LDAPConnectionOptions options, |
| | | int timeout, PrintStream out, PrintStream err) throws LDAPConnectionException |
| | | { |
| | | // Attempt to connect and authenticate to the Directory Server. |
| | |
| | | private Thread t; |
| | | private boolean stopPointAdder; |
| | | private boolean pointAdderStopped; |
| | | private long periodTime = DEFAULT_PERIOD_TIME; |
| | | private final long periodTime; |
| | | private final ProgressMessageFormatter formatter; |
| | | |
| | | /** The default period time used to write points in the output. */ |
| | | public static final long DEFAULT_PERIOD_TIME = 3000; |
| | | private static final long DEFAULT_PERIOD_TIME = 3000; |
| | | |
| | | /** |
| | | * Default constructor. |
| | |
| | | * @param formatter |
| | | * The text formatter. |
| | | */ |
| | | public PointAdder(ConsoleApplication app, long periodTime, ProgressMessageFormatter formatter) |
| | | private PointAdder(ConsoleApplication app, long periodTime, ProgressMessageFormatter formatter) |
| | | { |
| | | this.app = app; |
| | | this.periodTime = periodTime; |
| | |
| | | */ |
| | | package org.opends.server.workflowelement.localbackend; |
| | | |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | import static org.opends.server.types.AbstractOperation.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.opends.server.workflowelement.localbackend.LocalBackendWorkflowElement.*; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | import org.opends.server.types.operation.PreOperationAddOperation; |
| | | import org.opends.server.util.TimeThread; |
| | | |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | import static org.opends.server.types.AbstractOperation.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.opends.server.workflowelement.localbackend.LocalBackendWorkflowElement.*; |
| | | |
| | | /** |
| | | * This class defines an operation used to add an entry in a local backend |
| | | * of the Directory Server. |
| | |
| | | |
| | | /** The DN of the entry to be added. */ |
| | | private DN entryDN; |
| | | |
| | | /** The entry being added to the server. */ |
| | | private Entry entry; |
| | | |
| | |
| | | |
| | | /** The set of object classes for the entry to add. */ |
| | | private Map<ObjectClass, String> objectClasses; |
| | | |
| | | /** The set of operational attributes for the entry to add. */ |
| | | private Map<AttributeType, List<Attribute>> operationalAttributes; |
| | | |
| | | /** The set of user attributes for the entry to add. */ |
| | | private Map<AttributeType, List<Attribute>> userAttributes; |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | // The entry doesn't have a parent but isn't a suffix. This is not |
| | | // allowed. |
| | | // The entry doesn't have a parent but isn't a suffix. This is not allowed. |
| | | throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, ERR_ADD_ENTRY_NOT_SUFFIX.get(entryDN)); |
| | | } |
| | | } |
| | |
| | | attrList.add(Attributes.create(t, n, v)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds the provided objectClass to the entry, along with its superior classes |
| | | * if appropriate. |
| | | * |
| | | * @param objectClass The objectclass to add to the entry. |
| | | */ |
| | | public final void addObjectClassChain(ObjectClass objectClass) |
| | | { |
| | | Map<ObjectClass, String> objectClasses = getObjectClasses(); |
| | | if (objectClasses != null){ |
| | | if (! objectClasses.containsKey(objectClass)) |
| | | { |
| | | objectClasses.put(objectClass, objectClass.getNameOrOID()); |
| | | } |
| | | |
| | | for(ObjectClass superiorClass : objectClass.getSuperiorClasses()) |
| | | { |
| | | if (!objectClasses.containsKey(superiorClass)) |
| | | { |
| | | addObjectClassChain(superiorClass); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Performs all password policy processing necessary for the provided add |
| | | * operation. |
| | |
| | | * @throws DirectoryException If a problem occurs while performing password |
| | | * policy processing for the add operation. |
| | | */ |
| | | public final void handlePasswordPolicy() |
| | | private final void handlePasswordPolicy() |
| | | throws DirectoryException |
| | | { |
| | | // Construct any virtual/collective attributes which might |
| | |
| | | AuthenticationPolicy policy = AuthenticationPolicy.forUser(copy, false); |
| | | if (!policy.isPasswordPolicy()) |
| | | { |
| | | // The entry doesn't have a locally managed password, so no action is |
| | | // required. |
| | | // The entry doesn't have a locally managed password, so no action is required. |
| | | return; |
| | | } |
| | | PasswordPolicy passwordPolicy = (PasswordPolicy) policy; |
| | |
| | | && !passwordPolicy.isAllowMultiplePasswordValues() |
| | | && passwordAttr.size() > 1) |
| | | { |
| | | // FIXME -- What if they're pre-encoded and might all be the |
| | | // same? |
| | | // FIXME -- What if they're pre-encoded and might all be the same? |
| | | addPWPolicyControl(PasswordPolicyErrorType.PASSWORD_MOD_NOT_ALLOWED); |
| | | |
| | | LocalizableMessage message = ERR_PWPOLICY_MULTIPLE_PW_VALUES_NOT_ALLOWED |
| | |
| | | for (ByteString value : passwordAttr) |
| | | { |
| | | // See if the password is pre-encoded. |
| | | if (passwordPolicy.isAuthPasswordSyntax()) |
| | | boolean isPreEncoded = passwordPolicy.isAuthPasswordSyntax() |
| | | ? AuthPasswordSyntax.isEncoded(value) |
| | | : UserPasswordSyntax.isEncoded(value); |
| | | if (isPreEncoded) |
| | | { |
| | | if (AuthPasswordSyntax.isEncoded(value)) |
| | | { |
| | | if (isInternalOperation() |
| | | || passwordPolicy.isAllowPreEncodedPasswords()) |
| | | { |
| | | builder.add(value); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | addPWPolicyControl(PasswordPolicyErrorType.INSUFFICIENT_PASSWORD_QUALITY); |
| | | |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_PWPOLICY_PREENCODED_NOT_ALLOWED.get(passwordAttribute.getNameOrOID())); |
| | | } |
| | | } |
| | | } |
| | | else if (UserPasswordSyntax.isEncoded(value)) |
| | | { |
| | | if (isInternalOperation() |
| | | || passwordPolicy.isAllowPreEncodedPasswords()) |
| | | if (isInternalOperation() || passwordPolicy.isAllowPreEncodedPasswords()) |
| | | { |
| | | builder.add(value); |
| | | continue; |
| | |
| | | { |
| | | addPWPolicyControl(PasswordPolicyErrorType.INSUFFICIENT_PASSWORD_QUALITY); |
| | | |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_PWPOLICY_PREENCODED_NOT_ALLOWED.get(passwordAttribute.getNameOrOID())); |
| | | LocalizableMessage msg = ERR_PWPOLICY_PREENCODED_NOT_ALLOWED.get(passwordAttribute.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds a password policy response control if the corresponding request |
| | | * control was included. |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.simpleBind(ByteString.valueOfUtf8(searchBindDNString), |
| | | ByteString.valueOfUtf8(userPassword)); |
| | | fail("Bind attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.unblock(); |
| | | server.stop(); |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.simpleBind(ByteString.valueOfUtf8(searchBindDNString), |
| | | ByteString.valueOfUtf8(userPassword)); |
| | | fail("Bind attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.simpleBind(ByteString.valueOfUtf8(searchBindDNString), |
| | | ByteString.valueOfUtf8(userPassword)); |
| | | fail("Bind attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.simpleBind(ByteString.valueOfUtf8(searchBindDNString), |
| | | ByteString.valueOfUtf8(userPassword)); |
| | | fail("Bind attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.simpleBind(ByteString.valueOfUtf8(searchBindDNString), |
| | | ByteString.valueOfUtf8(userPassword)); |
| | | fail("Bind attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.simpleBind(ByteString.valueOfUtf8(searchBindDNString), |
| | | ByteString.valueOfUtf8(userPassword)); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", port, cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | fail("Connect attempt should have failed"); |
| | | } |
| | | catch (final DirectoryException e) |
| | |
| | | assertEquals(e.getResultCode(), ResultCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | e.getMessage()); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | // FIXME: can we guarantee that "unknownhost" does not exist? |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "unknownhost", 31415, cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | fail("Connect attempt should have failed"); |
| | | } |
| | | catch (final DirectoryException e) |
| | |
| | | assertEquals(e.getResultCode(), ResultCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | e.getMessage()); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, SearchFilter.objectClassPresent()); |
| | | fail("Search attempt should have timed out"); |
| | | } |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.unblock(); |
| | | server.stop(); |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | final ByteString username = connection.search(searchBindDN, |
| | | SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | // Test connect and close. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory( |
| | | "127.0.0.1", server.getPort(), cfg); |
| | | Connection connection = null; |
| | | try |
| | | try (Connection connection = factory.getConnection()) |
| | | { |
| | | connection = factory.getConnection(); |
| | | connection.search(searchBindDN, SearchScope.WHOLE_SUBTREE, |
| | | SearchFilter.createFilterFromString("(uid=aduser)")); |
| | | fail("Search attempt should have failed"); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(connection); |
| | | server.stop(); |
| | | } |
| | | } |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2012-2015 ForgeRock AS. |
| | | * Copyright 2012-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | import javax.xml.xpath.XPathFactory; |
| | | |
| | | import org.opends.server.DirectoryServerTestCase; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | import org.w3c.dom.Document; |
| | | import org.w3c.dom.NodeList; |
| | | |
| | | /** |
| | | * Tests for {@link TLSByteChannel} class. |
| | | */ |
| | | @Test(groups = { "slow" }, sequential = true) |
| | | /** Tests for {@link TLSByteChannel} class. */ |
| | | @Test(groups = "slow", sequential = true) |
| | | public class TLSByteChannelTestCase extends DirectoryServerTestCase |
| | | { |
| | | |
| | | /** |
| | | * Cipher suite hardcoded from the IANA registry on internet. |
| | | */ |
| | | /** Cipher suite hardcoded from the IANA registry on internet. */ |
| | | static final String[][] HARDCODED_CIPHER_SUITE = new String[][] { |
| | | { "TLS_NULL_WITH_NULL_NULL" }, |
| | | { "TLS_RSA_WITH_NULL_MD5" }, |
| | |
| | | String url = |
| | | "http://www.iana.org/assignments/tls-parameters/tls-parameters.xml"; |
| | | URLConnection conn = new URL(url).openConnection(); |
| | | BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); |
| | | |
| | | try |
| | | try (BufferedInputStream bis = new BufferedInputStream(conn.getInputStream())) |
| | | { |
| | | // JAXP boilerplate |
| | | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); |
| | |
| | | List<String> realCiphers = retrieveRealCiphers(doc, xpath, xPathExpr); |
| | | return toDataProviderResult(realCiphers); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(bis); |
| | | } |
| | | } |
| | | |
| | | private String[][] toDataProviderResult(List<String> realCiphers) |
| | |
| | | .getSSF("TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA")); |
| | | } |
| | | |
| | | /** |
| | | * Ensures that no new overlapping cipher strings are added to the cipher map. |
| | | */ |
| | | /** Ensures that no new overlapping cipher strings are added to the cipher map. */ |
| | | @Test |
| | | public void checkNoUnknownOverlappingCiphers() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Ensure the set (cipher1, cipher2) is different from the set (match1, |
| | | * match2). |
| | | */ |
| | | /** Ensure the set (cipher1, cipher2) is different from the set (match1, match2). */ |
| | | private boolean not(String cipher1, String cipher2, String match1, |
| | | String match2) |
| | | { |
| | | return (!cipher1.equals(match1) || !cipher2.equals(match2)) |
| | | && (!cipher2.equals(match1) || !cipher1.equals(match2)); |
| | | } |
| | | |
| | | } |
| | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testManageTasks(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(ManageTasks.mainTaskInfo(args, null, outStream, errStream, false), ERRORS_ON_STDOUT); |
| | | assertToolFailsWithUsage(ManageTasks.mainTaskInfo(args, outStream, errStream, false), ERRORS_ON_STDOUT); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | |
| | | @Test(dataProvider = "invalidArg") |
| | | public void testStatus(final String[] args) |
| | | { |
| | | assertToolFailsWithUsage(StatusCli.mainCLI(args, false, outStream, errStream, null), ERRORS_ON_STDOUT); |
| | | assertToolFailsWithUsage(StatusCli.mainCLI(args, outStream, errStream), ERRORS_ON_STDOUT); |
| | | } |
| | | |
| | | @Test(dataProvider = "invalidArgs") |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of test cases for the Upgrade tool. |
| | | */ |
| | | /** A set of test cases for the Upgrade tool. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class UpgradeTestCase extends ToolsTestCase |
| | | { |
| | |
| | | Assertions.assertThat(out).contains(expected); |
| | | } |
| | | |
| | | /** |
| | | * Tests display help information. |
| | | */ |
| | | /** Tests display help information. */ |
| | | @Test |
| | | public void testUpgradeToolDisplaysHelpUsage() |
| | | public void testUpgradeToolDisplaysHelpUsage() throws Exception |
| | | { |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | |
| | | try |
| | | try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos)) |
| | | { |
| | | // The 'main' should exit with success code. |
| | | assertEquals(UpgradeCli.main(setArgs("--help"), true, ps, ps), 0); |
| | | assertContainsMessage(baos.toString(), INFO_UPGRADE_DESCRIPTION_CLI.get()); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ps, baos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests display help information. |
| | | */ |
| | | /** Tests display help information. */ |
| | | @Test |
| | | public void testUpgradeToolDisplaysHelpUsage2() |
| | | public void testUpgradeToolDisplaysHelpUsage2() throws Exception |
| | | { |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | |
| | | try |
| | | try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos)) |
| | | { |
| | | // The 'main' should exit with success code. |
| | | assertEquals(UpgradeCli.main(setArgs("-H"), true, ps, ps), 0); |
| | | assertContainsMessage(baos.toString(), INFO_UPGRADE_DESCRIPTION_CLI.get()); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ps, baos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests display help information. |
| | | */ |
| | | /** Tests display help information. */ |
| | | @Test |
| | | public void testUpgradeToolDisplaysHelpUsage3() |
| | | public void testUpgradeToolDisplaysHelpUsage3() throws Exception |
| | | { |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | |
| | | try |
| | | try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos)) |
| | | { |
| | | // The 'main' should exit with success code. |
| | | assertEquals(UpgradeCli.main(setArgs("-?"), true, ps, ps), 0); |
| | | assertContainsMessage(baos.toString(), INFO_UPGRADE_DESCRIPTION_CLI.get()); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ps, baos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests the upgrade tool with an invalid sub-command. |
| | | */ |
| | | /** Tests the upgrade tool with an invalid sub-command. */ |
| | | @Test |
| | | public void testUpgradeToolDoesntAllowWrongSubcommand() |
| | | public void testUpgradeToolDoesntAllowWrongSubcommand() throws Exception |
| | | { |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | |
| | | try |
| | | try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos)) |
| | | { |
| | | // The 'main' should exit with an error code. |
| | | assertEquals(UpgradeCli.main(setArgs("-- wrong"), true, ps, ps), 1); |
| | | assertContainsMessage(baos.toString(), ERR_ERROR_PARSING_ARGS.get("")); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ps, baos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests the upgrade tool with an invalid sub-command. |
| | | */ |
| | | /** Tests the upgrade tool with an invalid sub-command. */ |
| | | @Test |
| | | public void testUpgradeToolDoesntAllowWrongSubcommand2() |
| | | public void testUpgradeToolDoesntAllowWrongSubcommand2() throws Exception |
| | | { |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | |
| | | try |
| | | try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos)) |
| | | { |
| | | // The 'main' should exit with an error code. |
| | | assertEquals(UpgradeCli.main(setArgs("--wrong"), true, ps, ps), 1); |
| | | assertContainsMessage(baos.toString(), ERR_ERROR_PARSING_ARGS.get("")); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ps, baos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * The upgrade tool disallows the force sub-command used with 'interactive |
| | | * mode'. |
| | | */ |
| | | /** The upgrade tool disallows the force sub-command used with 'interactive mode'. */ |
| | | @Test |
| | | public void testUpgradeToolDoesntAllowInteractiveAndForce() |
| | | public void testUpgradeToolDoesntAllowInteractiveAndForce() throws Exception |
| | | { |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | try |
| | | try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos)) |
| | | { |
| | | // The 'main' should exit with an error code. |
| | | assertEquals(UpgradeCli.main(setArgs("--force"), true, ps, ps), 1); |
| | |
| | | assertContainsMessage(baos.toString(), ERR_UPGRADE_INCOMPATIBLE_ARGS.get( |
| | | OPTION_LONG_FORCE_UPGRADE, "interactive mode")); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ps, baos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Upgrade tool allows use of force and no-prompt sub-commands. |
| | | */ |
| | | /** Upgrade tool allows use of force and no-prompt sub-commands. */ |
| | | @Test |
| | | public void testUpgradeToolAllowsNonInteractiveAndForce() throws Exception |
| | | { |
| | |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2006 Brighton Consulting, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.tasks.LdifFileWriter; |
| | | import org.opends.server.tools.ToolsTestCase; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.util.LDIFException; |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.testng.Assert.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of test cases for the MakeLDIF tool. |
| | | */ |
| | | public class MakeLDIFTestCase |
| | | extends ToolsTestCase |
| | | /** A set of test cases for the MakeLDIF tool. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class MakeLDIFTestCase extends ToolsTestCase |
| | | { |
| | | private String resourcePath; |
| | | |
| | |
| | | // Test must show "missingVar" missing on line 1. |
| | | // Previous behaviour showed "missingVar" on line 5. |
| | | |
| | | TemplateFile templateFile = new TemplateFile(resourcePath); |
| | | TemplateFile templateFile = new TemplateFile(resourcePath, new Random()); |
| | | List<LocalizableMessage> warns = new ArrayList<>(); |
| | | |
| | | try |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Test for parsing escaped character in templates. |
| | | */ |
| | | /** Test for parsing escaped character in templates. */ |
| | | @Test(dataProvider = "validTemplates") |
| | | public void testParsingEscapeCharInTemplate(String testName, String[] lines) |
| | | throws Exception |
| | | { |
| | | TemplateFile templateFile = new TemplateFile(resourcePath); |
| | | TemplateFile templateFile = new TemplateFile(resourcePath, new Random()); |
| | | List<LocalizableMessage> warns = new ArrayList<>(); |
| | | templateFile.parse(lines, warns); |
| | | assertTrue(warns.isEmpty(),"Warnings in parsing test template " + testName ); |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Test for escaped characters in templates, check LDIF output. |
| | | */ |
| | | @Test(dataProvider="templatesToTestLDIFOutput", dependsOnMethods = { "testParsingEscapeCharInTemplate"}) |
| | | /** Test for escaped characters in templates, check LDIF output. */ |
| | | @Test(dataProvider = "templatesToTestLDIFOutput", dependsOnMethods = "testParsingEscapeCharInTemplate") |
| | | public void testLDIFOutputFromTemplate(String testName, String[] lines, |
| | | String attrName, String expectedValue) throws Exception |
| | | { |
| | |
| | | * Test for escaped characters in templates, check LDIF output when |
| | | * the templates combines escaped characters and variables. |
| | | */ |
| | | @Test(dependsOnMethods = { "testParsingEscapeCharInTemplate"}) |
| | | @Test(dependsOnMethods = "testParsingEscapeCharInTemplate") |
| | | public void testOutputCombineEscapeCharInTemplate() throws Exception |
| | | { |
| | | String[] lines = |
| | |
| | | "", |
| | | }; |
| | | |
| | | |
| | | File tmpFile = File.createTempFile("combineEscapeChar", "out.ldif"); |
| | | tmpFile.deleteOnExit(); |
| | | String outLdifFilePath = tmpFile.getAbsolutePath(); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.BufferedReader; |
| | |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.channels.FileLock; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Create test strings for the |
| | | * {@link StaticUtils#isRelativePath(String)}. |
| | | * |
| | | * @return Returns an array of test data. |
| | | */ |
| | | @DataProvider(name = "isRelativePathTestData") |
| | | public Object[][] createIsRelativePathTestData() { |
| | | String root = File.listRoots()[0].getPath(); |
| | | return new Object[][] { { "", true }, { root, false }, |
| | | { root + "foo", false }, { "foo", true }, |
| | | { "foo" + File.separator + "bar", true }, |
| | | { root + "foo" + File.separator + "bar", false }, |
| | | { ".", true }, { "..", true }, |
| | | { root + "foo" + File.separator + ".", false }, |
| | | { root + "foo" + File.separator + "..", false } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#isRelativePath(String)} method. |
| | | * |
| | | * @param path |
| | | * The test string. |
| | | * @param result |
| | | * Expected result. |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test(dataProvider = "isRelativePathTestData") |
| | | public void testIsRelativePath(String path, boolean result) |
| | | throws Exception { |
| | | Assert.assertEquals(StaticUtils.isRelativePath(path), result); |
| | | } |
| | | |
| | | /** |
| | | * Create test lists for the {@link StaticUtils#listToArray(List)}. |
| | | * |
| | | * @return Returns an array of test data. |
| | | */ |
| | | @DataProvider(name = "listToArrayTestData") |
| | | public Object[][] createListToArrayTestData() { |
| | | return new Object[][] { { null }, { new String[] {} }, |
| | | { new String[] { "aaa" } }, |
| | | { new String[] { "aaa", "bbb", "ccc" } } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#listToArray(List)} method. |
| | | * |
| | | * @param strings |
| | | * The test string list. |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test(dataProvider = "listToArrayTestData") |
| | | public void testListToArray(String[] strings) throws Exception { |
| | | if (strings != null) { |
| | | List<String> list = new ArrayList<>(strings.length); |
| | | Collections.addAll(list, strings); |
| | | Assert.assertEquals(StaticUtils.listToArray(list), strings); |
| | | } else { |
| | | Assert.assertNull(StaticUtils.listToArray(null)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#moveFile(java.io.File, java.io.File)} |
| | | * method. |
| | | * |
| | |
| | | Assert.assertEquals(builder.toString(), expected); |
| | | } |
| | | |
| | | /** |
| | | * Create test lists for the |
| | | * {@link StaticUtils#listsAreEqual(List, List)} method. |
| | | * |
| | | * @return Returns an array of test data. |
| | | */ |
| | | @DataProvider(name = "listsAreEqualTestData") |
| | | public Object[][] createListsAreEqualTestData() { |
| | | return new Object[][] { |
| | | // Check null behaviour. |
| | | { null, null, true }, |
| | | { null, Collections.emptyList(), false }, |
| | | { Collections.emptyList(), null, false }, |
| | | |
| | | // Check empty-list behaviour. |
| | | { Collections.emptyList(), Collections.emptyList(), true }, |
| | | { Collections.singletonList(0), Collections.emptyList(), false }, |
| | | { Collections.emptyList(), Collections.singletonList(0), false }, |
| | | |
| | | // Check single-element behaviour. |
| | | { Collections.singletonList(0), Collections.singletonList(0), true }, |
| | | { Collections.singletonList(0), Collections.singletonList(1), false }, |
| | | |
| | | // Check multi-element random access behaviour. |
| | | { Arrays.asList(0, 1), Arrays.asList(0, 1), true }, |
| | | { Arrays.asList(0, 1), Arrays.asList(1, 0), false }, |
| | | |
| | | // ...With duplicates. |
| | | { Arrays.asList(0, 1), Arrays.asList(0, 1, 1), false }, |
| | | |
| | | // Check multi-element sequential behaviour. |
| | | { newLinkedList(0, 1), newLinkedList(0, 1), true }, |
| | | { newLinkedList(0, 1), newLinkedList(1, 0), false }, |
| | | |
| | | // ...With duplicates. |
| | | { newLinkedList(0, 1), newLinkedList(0, 1, 1), false } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#listsAreEqual(List, List)} method. |
| | | * |
| | | * @param list1 |
| | | * The first list. |
| | | * @param list2 |
| | | * The second list. |
| | | * @param result |
| | | * The expected equality result. |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test(dataProvider = "listsAreEqualTestData") |
| | | public void testListsAreEqual(List<?> list1, List<?> list2, boolean result) |
| | | throws Exception { |
| | | Assert.assertEquals(StaticUtils.listsAreEqual(list1, list2), result); |
| | | } |
| | | |
| | | @Test |
| | | public void testStackTraceHasCause() throws Exception |
| | | { |