OPENDJ-1235: Migrate configuration framework
* removed dependencies on DirectoryServer class
* renamed ClassLoaderProvider to ConfigurationFramework to make its responsibility for overall management of the configuration framework more obvious
* removed PropertyDefinitionsOptions and replaced with single "isClient" getter/setter in ConfigurationFramework. This is now used throughout the framework
* use default schema throughout. If we need to add support for customization of the schema then we could provide the capability via the ConfigurationFramework class
* pass in install/instance paths to ConfigurationFramework during initialization. Default to "user.dir" property if no paths are provided.
4 files deleted
1 files added
44 files modified
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Aci value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(Aci value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Aci decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public Aci decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | for (AggregationPropertyDefinition<?, ?> apd : getAllAggregationPropertyDefinitions()) { |
| | | |
| | | apd.initialize(); |
| | | // Now register the aggregation property in the referenced managed |
| | | // object |
| | | // definition for reverse lookups. |
| | | /* |
| | | * Now register the aggregation property in the referenced managed |
| | | * object definition for reverse lookups. |
| | | */ |
| | | registerReverseAggregationPropertyDefinition(apd); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public String decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value, options); |
| | | validateValue(value); |
| | | return value; |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(String value) { |
| | | try { |
| | | Reference.parseName(parentPath, relationDefinition, value); |
| | | } catch (IllegalArgumentException e) { |
| | |
| | | import java.util.EnumSet; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | |
| | | /** |
| | | * Attribute type property definition. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public AttributeType decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public AttributeType decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | String name = value.trim().toLowerCase(); |
| | | AttributeType type = DirectoryServer.getAttributeType(name, !options.checkSchemaForAttributes()); |
| | | |
| | | if (type == null) { |
| | | final String name = value.trim(); |
| | | if (!ConfigurationFramework.getInstance().isClient() |
| | | && !Schema.getDefaultSchema().hasAttributeType(name)) { |
| | | // If this is the server then the attribute type must be defined. |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } else { |
| | | try { |
| | | validateValue(type, options); |
| | | return type; |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | final AttributeType type = |
| | | Schema.getDefaultSchema().asNonStrictSchema().getAttributeType(name); |
| | | try { |
| | | validateValue(type); |
| | | return type; |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(AttributeType value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(AttributeType value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No implementation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Boolean value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(Boolean value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Boolean decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public Boolean decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | |
| | | * <p> |
| | | * Note that in a client/server environment, the client is probably not capable |
| | | * of validating the Java class (e.g. it will not be able to load it nor have |
| | | * access to the interfaces it is supposed to implement). For this reason, it is |
| | | * possible to switch off validation in the client by using the appropriate |
| | | * {@link PropertyDefinitionsOptions}. |
| | | * access to the interfaces it is supposed to implement). For this reason, |
| | | * validation is disabled in client applications. |
| | | */ |
| | | public final class ClassPropertyDefinition extends PropertyDefinition<String> { |
| | | |
| | |
| | | |
| | | // Load a named class. |
| | | private static Class<?> loadClass(String className, boolean initialize) throws ClassNotFoundException { |
| | | return Class.forName(className, initialize, ClassLoaderProvider.getInstance().getClassLoader()); |
| | | return Class.forName(className, initialize, ConfigurationFramework.getInstance().getClassLoader()); |
| | | } |
| | | |
| | | // List of interfaces which property values must implement. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public String decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value, options); |
| | | validateValue(value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value, e.getCause()); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Always make sure the name is a valid class name. |
| | |
| | | * If additional validation is enabled then attempt to load the class |
| | | * and check the interfaces that it implements/extends. |
| | | */ |
| | | if (options.allowClassValidation()) { |
| | | if (!ConfigurationFramework.getInstance().isClient()) { |
| | | validateClassInterfaces(value, false); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * CDDL HEADER START |
| | | * |
| | | * The contents of this file are subject to the terms of the |
| | | * Common Development and Distribution License, Version 1.0 only |
| | | * (the "License"). You may not use this file except in compliance |
| | | * with the License. |
| | | * |
| | | * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * See the License for the specific language governing permissions |
| | | * and limitations under the License. |
| | | * |
| | | * When distributing Covered Code, include this CDDL HEADER in each |
| | | * file and include the License file at legal-notices/CDDLv1_0.txt. |
| | | * If applicable, add the following below this CDDL HEADER, with the |
| | | * fields enclosed by brackets "[]" replaced with your own identifying |
| | | * information: |
| | | * Portions Copyright [yyyy] [name of copyright owner] |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.config; |
| | | |
| | | import static com.forgerock.opendj.ldap.AdminMessages.*; |
| | | import static com.forgerock.opendj.ldap.ExtensionMessages.NOTE_LOG_EXTENSION_INFORMATION; |
| | | import static com.forgerock.opendj.util.StaticUtils.EOL; |
| | | import static com.forgerock.opendj.util.StaticUtils.stackTraceToSingleLineString; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileFilter; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.PrintStream; |
| | | import java.lang.reflect.Method; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLClassLoader; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.jar.Attributes; |
| | | import java.util.jar.JarEntry; |
| | | import java.util.jar.JarFile; |
| | | import java.util.jar.Manifest; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.server.config.meta.RootCfgDefn; |
| | | import org.forgerock.util.Reject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.forgerock.opendj.ldap.AdminMessages; |
| | | |
| | | /** |
| | | * This class is responsible for managing the configuration framework including: |
| | | * <ul> |
| | | * <li>loading core components during application initialization |
| | | * <li>loading extensions during and after application initialization |
| | | * <li>changing the property validation strategy based on whether the |
| | | * application is a client or server. |
| | | * </ul> |
| | | * This class defines a class loader which will be used for loading components. |
| | | * For extensions which define their own extended configuration definitions, the |
| | | * class loader will make sure that the configuration definition classes are |
| | | * loaded and initialized. |
| | | * <p> |
| | | * Initially the configuration framework is disabled, and calls to the |
| | | * {@link #getClassLoader()} will return the system default class loader. |
| | | * <p> |
| | | * Applications <b>MUST NOT</b> maintain persistent references to the class |
| | | * loader as it can change at run-time. |
| | | */ |
| | | public final class ConfigurationFramework { |
| | | /** |
| | | * Private URLClassLoader implementation. This is only required so that we |
| | | * can provide access to the addURL method. |
| | | */ |
| | | private static final class MyURLClassLoader extends URLClassLoader { |
| | | |
| | | /** |
| | | * Create a class loader with the default parent class loader. |
| | | */ |
| | | public MyURLClassLoader() { |
| | | super(new URL[0]); |
| | | } |
| | | |
| | | /** |
| | | * Create a class loader with the provided parent class loader. |
| | | * |
| | | * @param parent |
| | | * The parent class loader. |
| | | */ |
| | | public MyURLClassLoader(final ClassLoader parent) { |
| | | super(new URL[0], parent); |
| | | } |
| | | |
| | | /** |
| | | * Add a Jar file to this class loader. |
| | | * |
| | | * @param jarFile |
| | | * The name of the Jar file. |
| | | * @throws MalformedURLException |
| | | * If a protocol handler for the URL could not be found, or |
| | | * if some other error occurred while constructing the URL. |
| | | * @throws SecurityException |
| | | * If a required system property value cannot be accessed. |
| | | */ |
| | | public void addJarFile(final File jarFile) throws MalformedURLException { |
| | | addURL(jarFile.toURI().toURL()); |
| | | } |
| | | |
| | | } |
| | | |
| | | private static final String MANIFEST = |
| | | "META-INF/services/org.forgerock.opendj.config.AbstractManagedObjectDefinition"; |
| | | |
| | | private static final LocalizedLogger adminLogger = LocalizedLogger |
| | | .getLocalizedLogger(AdminMessages.resourceName()); |
| | | private static final Logger debugLogger = LoggerFactory.getLogger(ConfigurationFramework.class); |
| | | |
| | | // The name of the lib directory. |
| | | private static final String LIB_DIR = "lib"; |
| | | |
| | | // The name of the extensions directory. |
| | | private static final String EXTENSIONS_DIR = "extensions"; |
| | | |
| | | // The singleton instance. |
| | | private static final ConfigurationFramework INSTANCE = new ConfigurationFramework(); |
| | | |
| | | // Attribute name in jar's MANIFEST corresponding to the revision number. |
| | | private static final String REVISION_NUMBER = "Revision-Number"; |
| | | |
| | | // The attribute names for build information is name, version and revision |
| | | // number |
| | | private static final String[] BUILD_INFORMATION_ATTRIBUTE_NAMES = new String[] { |
| | | Attributes.Name.EXTENSION_NAME.toString(), |
| | | Attributes.Name.IMPLEMENTATION_VERSION.toString(), REVISION_NUMBER }; |
| | | |
| | | /** |
| | | * Returns the single application wide configuration framework instance. |
| | | * |
| | | * @return The single application wide configuration framework instance. |
| | | */ |
| | | public static ConfigurationFramework getInstance() { |
| | | return INSTANCE; |
| | | } |
| | | |
| | | // Set of registered Jar files. |
| | | private Set<File> jarFiles = new HashSet<File>(); |
| | | |
| | | // Underlying class loader used to load classes and resources (null |
| | | // if disabled). |
| | | // |
| | | // We contain a reference to the URLClassLoader rather than |
| | | // sub-class it so that it is possible to replace the loader at |
| | | // run-time. For example, when removing or replacing extension Jar |
| | | // files (the URLClassLoader only supports adding new |
| | | // URLs, not removal). |
| | | private MyURLClassLoader loader = null; |
| | | |
| | | private boolean isClient = true; |
| | | private String installPath; |
| | | private String instancePath; |
| | | private ClassLoader parent; |
| | | |
| | | // Private constructor. |
| | | private ConfigurationFramework() { |
| | | // No implementation required. |
| | | } |
| | | |
| | | /** |
| | | * Loads the named extensions into the configuration framework. |
| | | * |
| | | * @param extensions |
| | | * The names of the extensions to be loaded. The names should not |
| | | * contain any path elements and must be located within the |
| | | * extensions folder. |
| | | * @throws ConfigException |
| | | * If one of the extensions could not be loaded and initialized. |
| | | * @throws IllegalStateException |
| | | * If the configuration framework has not yet been initialized. |
| | | * @throws IllegalArgumentException |
| | | * If one of the extension names was not a single relative path |
| | | * name element or was an absolute path. |
| | | */ |
| | | public synchronized void addExtension(final String... extensions) throws ConfigException { |
| | | Reject.ifNull(extensions); |
| | | ensureInitialized(); |
| | | |
| | | final File libPath = new File(instancePath, LIB_DIR); |
| | | final File extensionsPath = new File(libPath, EXTENSIONS_DIR); |
| | | |
| | | final ArrayList<File> files = new ArrayList<File>(extensions.length); |
| | | for (final String extension : extensions) { |
| | | final File file = new File(extensionsPath, extension); |
| | | |
| | | // For security reasons we need to make sure that the file name |
| | | // passed in did not contain any path elements and names a file |
| | | // in the extensions folder. |
| | | |
| | | // Can handle potential null parent. |
| | | if (!extensionsPath.equals(file.getParentFile())) { |
| | | throw new IllegalArgumentException("Illegal file name: " + extension); |
| | | } |
| | | |
| | | // The file is valid. |
| | | files.add(file); |
| | | } |
| | | |
| | | // Add the extensions. |
| | | addExtension(files.toArray(new File[files.size()])); |
| | | } |
| | | |
| | | /** |
| | | * Returns the class loader which should be used for loading classes and |
| | | * resources. When this configuration framework is disabled, the system |
| | | * default class loader will be returned by default. |
| | | * <p> |
| | | * Applications <b>MUST NOT</b> maintain persistent references to the class |
| | | * loader as it can change at run-time. |
| | | * |
| | | * @return Returns the class loader which should be used for loading classes |
| | | * and resources. |
| | | */ |
| | | public synchronized ClassLoader getClassLoader() { |
| | | if (loader != null) { |
| | | return loader; |
| | | } else { |
| | | return ClassLoader.getSystemClassLoader(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Initializes the configuration framework using the application's class |
| | | * loader as the parent class loader, and the current working directory as |
| | | * the install and instance path. |
| | | * |
| | | * @return The configuration framework. |
| | | * @throws ConfigException |
| | | * If the configuration framework could not initialize |
| | | * successfully. |
| | | * @throws IllegalStateException |
| | | * If the configuration framework has already been initialized. |
| | | */ |
| | | public ConfigurationFramework initialize() throws ConfigException { |
| | | return initialize(null); |
| | | } |
| | | |
| | | /** |
| | | * Initializes the configuration framework using the application's class |
| | | * loader as the parent class loader, and the provided install/instance |
| | | * path. |
| | | * |
| | | * @param installAndInstancePath |
| | | * The path where application binaries and data are located. |
| | | * @return The configuration framework. |
| | | * @throws ConfigException |
| | | * If the configuration framework could not initialize |
| | | * successfully. |
| | | * @throws IllegalStateException |
| | | * If the configuration framework has already been initialized. |
| | | */ |
| | | public ConfigurationFramework initialize(final String installAndInstancePath) |
| | | throws ConfigException { |
| | | return initialize(installAndInstancePath, installAndInstancePath); |
| | | } |
| | | |
| | | /** |
| | | * Initializes the configuration framework using the application's class |
| | | * loader as the parent class loader, and the provided install and instance |
| | | * paths. |
| | | * |
| | | * @param installPath |
| | | * The path where application binaries are located. |
| | | * @param instancePath |
| | | * The path where application data are located. |
| | | * @return The configuration framework. |
| | | * @throws ConfigException |
| | | * If the configuration framework could not initialize |
| | | * successfully. |
| | | * @throws IllegalStateException |
| | | * If the configuration framework has already been initialized. |
| | | */ |
| | | public ConfigurationFramework initialize(final String installPath, final String instancePath) |
| | | throws ConfigException { |
| | | return initialize(installPath, instancePath, RootCfgDefn.class.getClassLoader()); |
| | | } |
| | | |
| | | /** |
| | | * Initializes the configuration framework using the provided parent class |
| | | * loader and install and instance paths. |
| | | * |
| | | * @param installPath |
| | | * The path where application binaries are located. |
| | | * @param instancePath |
| | | * The path where application data are located. |
| | | * @param parent |
| | | * The parent class loader. |
| | | * @return The configuration framework. |
| | | * @throws ConfigException |
| | | * If the configuration framework could not initialize |
| | | * successfully. |
| | | * @throws IllegalStateException |
| | | * If the configuration framework has already been initialized. |
| | | */ |
| | | public synchronized ConfigurationFramework initialize(final String installPath, |
| | | final String instancePath, final ClassLoader parent) throws ConfigException { |
| | | if (loader != null) { |
| | | throw new IllegalStateException("configuration framework already initialized."); |
| | | } |
| | | this.installPath = installPath == null ? System.getProperty("user.dir") : installPath; |
| | | this.instancePath = instancePath == null ? installPath : instancePath; |
| | | this.parent = parent; |
| | | initialize0(); |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * Returns {@code true} if the configuration framework is being used within |
| | | * a client application. Client applications will perform less property |
| | | * value validation than server applications because they do not have |
| | | * resources available such as the server schema. |
| | | * |
| | | * @return {@code true} if the configuration framework is being used within |
| | | * a client application. |
| | | */ |
| | | public boolean isClient() { |
| | | return isClient; |
| | | } |
| | | |
| | | /** |
| | | * Returns {@code true} if the configuration framework has been enabled. |
| | | * |
| | | * @return {@code true} if the configuration framework has been enabled. |
| | | */ |
| | | public synchronized boolean isEnabled() { |
| | | return loader != null; |
| | | } |
| | | |
| | | /** |
| | | * Prints out all information about extensions. |
| | | * |
| | | * @return A string representing all information about extensions; |
| | | * <code>null</code> if there is no information available. |
| | | */ |
| | | public String printExtensionInformation() { |
| | | final File extensionsPath = |
| | | new File(new StringBuilder(installPath).append(File.separator).append(LIB_DIR) |
| | | .append(File.separator).append(EXTENSIONS_DIR).toString()); |
| | | |
| | | if (!extensionsPath.exists() || !extensionsPath.isDirectory()) { |
| | | // no extensions' directory |
| | | return null; |
| | | } |
| | | |
| | | final File[] extensions = extensionsPath.listFiles(new FileFilter() { |
| | | @Override |
| | | public boolean accept(final File pathname) { |
| | | // only files with names ending with ".jar" |
| | | return pathname.isFile() && pathname.getName().endsWith(".jar"); |
| | | } |
| | | }); |
| | | |
| | | if (extensions.length == 0) { |
| | | return null; |
| | | } |
| | | |
| | | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | final PrintStream ps = new PrintStream(baos); |
| | | // prints: |
| | | // -- |
| | | // Name Build number Revision number |
| | | ps.printf("--%s %-20s %-20s %-20s%s", EOL, "Name", "Build number", |
| | | "Revision number", EOL); |
| | | |
| | | for (final File extension : extensions) { |
| | | // retrieve MANIFEST entry and display name, build number and |
| | | // revision number |
| | | try { |
| | | final JarFile jarFile = new JarFile(extension); |
| | | final JarEntry entry = jarFile.getJarEntry(MANIFEST); |
| | | if (entry == null) { |
| | | continue; |
| | | } |
| | | |
| | | final String[] information = getBuildInformation(jarFile); |
| | | |
| | | ps.append("Extension: "); |
| | | boolean addBlank = false; |
| | | for (final String name : information) { |
| | | if (addBlank) { |
| | | ps.append(addBlank ? " " : ""); // add blank if not |
| | | // first append |
| | | } else { |
| | | addBlank = true; |
| | | } |
| | | |
| | | ps.printf("%-20s", name); |
| | | } |
| | | ps.append(EOL); |
| | | } catch (final Exception e) { |
| | | // ignore extra information for this extension |
| | | } |
| | | } |
| | | |
| | | return baos.toString(); |
| | | } |
| | | |
| | | /** |
| | | * Reloads the configuration framework. |
| | | * |
| | | * @throws ConfigException |
| | | * If the configuration framework could not initialize |
| | | * successfully. |
| | | * @throws IllegalStateException |
| | | * If the configuration framework has not yet been initialized. |
| | | */ |
| | | public synchronized void reload() throws ConfigException { |
| | | ensureInitialized(); |
| | | loader = null; |
| | | jarFiles = new HashSet<File>(); |
| | | initialize0(); |
| | | } |
| | | |
| | | /** |
| | | * Specifies whether or not the configuration framework is being used within |
| | | * a client application. Client applications will perform less property |
| | | * value validation than server applications because they do not have |
| | | * resources available such as the server schema. |
| | | * |
| | | * @param isClient |
| | | * {@code true} if the configuration framework is being used |
| | | * within a client application. |
| | | * @return The configuration framework. |
| | | */ |
| | | public ConfigurationFramework setIsClient(final boolean isClient) { |
| | | this.isClient = isClient; |
| | | return this; |
| | | } |
| | | |
| | | private void addExtension(final File... extensions) throws ConfigException { |
| | | // First add the Jar files to the class loader. |
| | | final List<JarFile> jars = new LinkedList<JarFile>(); |
| | | for (final File extension : extensions) { |
| | | if (jarFiles.contains(extension)) { |
| | | // Skip this file as it is already loaded. |
| | | continue; |
| | | } |
| | | |
| | | // Attempt to load it. |
| | | jars.add(loadJarFile(extension)); |
| | | |
| | | // Register the Jar file with the class loader. |
| | | try { |
| | | loader.addJarFile(extension); |
| | | } catch (final Exception e) { |
| | | debugLogger.trace("Unable to register the jar file with the class loader", e); |
| | | final LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(extension.getName(), extension |
| | | .getParent(), stackTraceToSingleLineString(e, true)); |
| | | throw new ConfigException(message); |
| | | } |
| | | jarFiles.add(extension); |
| | | } |
| | | |
| | | // Now forcefully load the configuration definition classes. |
| | | for (final JarFile jar : jars) { |
| | | initializeExtension(jar); |
| | | } |
| | | } |
| | | |
| | | private void ensureInitialized() { |
| | | if (loader == null) { |
| | | throw new IllegalStateException("configuration framework is disabled."); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns a String array with the following information : <br> |
| | | * index 0: the name of the extension. <br> |
| | | * index 1: the build number of the extension. <br> |
| | | * index 2: the revision number of the extension. |
| | | * |
| | | * @param extension |
| | | * the jar file of the extension |
| | | * @return a String array containing the name, the build number and the |
| | | * revision number of the extension given in argument |
| | | * @throws java.io.IOException |
| | | * thrown if the jar file has been closed. |
| | | */ |
| | | private String[] getBuildInformation(final JarFile extension) throws IOException { |
| | | final String[] result = new String[3]; |
| | | |
| | | // retrieve MANIFEST entry and display name, version and revision |
| | | final Manifest manifest = extension.getManifest(); |
| | | |
| | | if (manifest != null) { |
| | | final Attributes attributes = manifest.getMainAttributes(); |
| | | |
| | | int index = 0; |
| | | for (final String name : BUILD_INFORMATION_ATTRIBUTE_NAMES) { |
| | | String value = attributes.getValue(name); |
| | | if (value == null) { |
| | | value = "<unknown>"; |
| | | } |
| | | result[index++] = value; |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void initialize0() throws ConfigException { |
| | | if (parent != null) { |
| | | loader = new MyURLClassLoader(parent); |
| | | } else { |
| | | loader = new MyURLClassLoader(); |
| | | } |
| | | |
| | | // Forcefully load all configuration definition classes in |
| | | // OpenDS.jar. |
| | | initializeCoreComponents(); |
| | | |
| | | // Put extensions jars into the class loader and load all |
| | | // configuration definition classes in that they contain. |
| | | // First load the extension from the install directory, then |
| | | // from the instance directory. |
| | | File libDir; |
| | | File installExtensionsPath; |
| | | File instanceExtensionsPath; |
| | | |
| | | // load install dir extension |
| | | libDir = new File(installPath, LIB_DIR); |
| | | try { |
| | | installExtensionsPath = new File(libDir, EXTENSIONS_DIR).getCanonicalFile(); |
| | | } catch (final Exception e) { |
| | | installExtensionsPath = new File(libDir, EXTENSIONS_DIR); |
| | | } |
| | | initializeAllExtensions(installExtensionsPath); |
| | | |
| | | // load instance dir extension |
| | | libDir = new File(instancePath, LIB_DIR); |
| | | try { |
| | | instanceExtensionsPath = new File(libDir, EXTENSIONS_DIR).getCanonicalFile(); |
| | | } catch (final Exception e) { |
| | | instanceExtensionsPath = new File(libDir, EXTENSIONS_DIR); |
| | | } |
| | | if (!installExtensionsPath.getAbsolutePath().equals( |
| | | instanceExtensionsPath.getAbsolutePath())) { |
| | | initializeAllExtensions(instanceExtensionsPath); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Put extensions jars into the class loader and load all configuration |
| | | * definition classes in that they contain. |
| | | * |
| | | * @param extensionsPath |
| | | * Indicates where extensions are located. |
| | | * @throws ConfigException |
| | | * If the extensions folder could not be accessed or if a |
| | | * extension jar file could not be accessed or if one of the |
| | | * configuration definition classes could not be initialized. |
| | | */ |
| | | private void initializeAllExtensions(final File extensionsPath) throws ConfigException { |
| | | try { |
| | | if (!extensionsPath.exists()) { |
| | | // The extensions directory does not exist. This is not a |
| | | // critical problem. |
| | | adminLogger.error(ERR_ADMIN_NO_EXTENSIONS_DIR, String.valueOf(extensionsPath)); |
| | | return; |
| | | } |
| | | |
| | | if (!extensionsPath.isDirectory()) { |
| | | // The extensions directory is not a directory. This is more |
| | | // critical. |
| | | final LocalizableMessage message = |
| | | ERR_ADMIN_EXTENSIONS_DIR_NOT_DIRECTORY.get(String.valueOf(extensionsPath)); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | // Get each extension file name. |
| | | final FileFilter filter = new FileFilter() { |
| | | |
| | | /** |
| | | * Must be a Jar file. |
| | | */ |
| | | @Override |
| | | public boolean accept(final File pathname) { |
| | | if (!pathname.isFile()) { |
| | | return false; |
| | | } |
| | | |
| | | final String name = pathname.getName(); |
| | | return name.endsWith(".jar"); |
| | | } |
| | | |
| | | }; |
| | | |
| | | // Add and initialize the extensions. |
| | | addExtension(extensionsPath.listFiles(filter)); |
| | | } catch (final ConfigException e) { |
| | | debugLogger.trace("Unable to initialize all extensions", e); |
| | | throw e; |
| | | } catch (final Exception e) { |
| | | debugLogger.trace("Unable to initialize all extensions", e); |
| | | final LocalizableMessage message = |
| | | ERR_ADMIN_EXTENSIONS_CANNOT_LIST_FILES.get(String.valueOf(extensionsPath), |
| | | stackTraceToSingleLineString(e, true)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Make sure all core configuration definitions are loaded. |
| | | * |
| | | * @throws ConfigException |
| | | * If the core manifest file could not be read or if one of the |
| | | * configuration definition classes could not be initialized. |
| | | */ |
| | | private void initializeCoreComponents() throws ConfigException { |
| | | final InputStream is = RootCfgDefn.class.getResourceAsStream(MANIFEST); |
| | | if (is == null) { |
| | | final LocalizableMessage message = ERR_ADMIN_CANNOT_FIND_CORE_MANIFEST.get(MANIFEST); |
| | | throw new ConfigException(message); |
| | | } |
| | | try { |
| | | loadDefinitionClasses(is); |
| | | } catch (final ConfigException e) { |
| | | debugLogger.trace("Unable to initialize core components", e); |
| | | final LocalizableMessage message = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_CORE.get(MANIFEST, stackTraceToSingleLineString(e, |
| | | true)); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Make sure all the configuration definition classes in a extension are |
| | | * loaded. |
| | | * |
| | | * @param jarFile |
| | | * The extension's Jar file. |
| | | * @throws ConfigException |
| | | * If the extension jar file could not be accessed or if one of |
| | | * the configuration definition classes could not be |
| | | * initialized. |
| | | */ |
| | | private void initializeExtension(final JarFile jarFile) throws ConfigException { |
| | | final JarEntry entry = jarFile.getJarEntry(MANIFEST); |
| | | if (entry != null) { |
| | | InputStream is; |
| | | try { |
| | | is = jarFile.getInputStream(entry); |
| | | } catch (final Exception e) { |
| | | debugLogger.trace("Unable to get input stream from jar", e); |
| | | final LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_READ_EXTENSION_MANIFEST.get(MANIFEST, jarFile.getName(), |
| | | stackTraceToSingleLineString(e, true)); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | try { |
| | | loadDefinitionClasses(is); |
| | | } catch (final ConfigException e) { |
| | | debugLogger.trace("Unable to load classes from input stream", e); |
| | | final LocalizableMessage message = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_EXTENSION.get(jarFile.getName(), MANIFEST, |
| | | stackTraceToSingleLineString(e, true)); |
| | | throw new ConfigException(message); |
| | | } |
| | | try { |
| | | // Log build information of extensions in the error log |
| | | final String[] information = getBuildInformation(jarFile); |
| | | final LocalizableMessage message = |
| | | NOTE_LOG_EXTENSION_INFORMATION.get(jarFile.getName(), information[1], |
| | | information[2]); |
| | | LocalizedLogger.getLocalizedLogger(message.resourceName()).error(message); |
| | | } catch (final Exception e) { |
| | | // Do not log information for that extension |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Forcefully load configuration definition classes named in a manifest |
| | | * file. |
| | | * |
| | | * @param is |
| | | * The manifest file input stream. |
| | | * @throws ConfigException |
| | | * If the definition classes could not be loaded and |
| | | * initialized. |
| | | */ |
| | | private void loadDefinitionClasses(final InputStream is) throws ConfigException { |
| | | final BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| | | final List<AbstractManagedObjectDefinition<?, ?>> definitions = |
| | | new LinkedList<AbstractManagedObjectDefinition<?, ?>>(); |
| | | while (true) { |
| | | String className; |
| | | try { |
| | | className = reader.readLine(); |
| | | } catch (final IOException e) { |
| | | final LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_READ_MANIFEST_FILE.get(String.valueOf(e |
| | | .getMessage())); |
| | | throw new ConfigException(msg, e); |
| | | } |
| | | |
| | | // Break out when the end of the manifest is reached. |
| | | if (className == null) { |
| | | break; |
| | | } |
| | | |
| | | // Skip blank lines. |
| | | className = className.trim(); |
| | | if (className.length() == 0) { |
| | | continue; |
| | | } |
| | | |
| | | // Skip lines beginning with #. |
| | | if (className.startsWith("#")) { |
| | | continue; |
| | | } |
| | | |
| | | debugLogger.trace("Loading class " + className); |
| | | |
| | | // Load the class and get an instance of it if it is a definition. |
| | | Class<?> theClass; |
| | | try { |
| | | theClass = Class.forName(className, true, loader); |
| | | } catch (final Exception e) { |
| | | final LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_CLASS.get(className, String.valueOf(e |
| | | .getMessage())); |
| | | throw new ConfigException(msg, e); |
| | | } |
| | | if (AbstractManagedObjectDefinition.class.isAssignableFrom(theClass)) { |
| | | // We need to instantiate it using its getInstance() static |
| | | // method. |
| | | Method method; |
| | | try { |
| | | method = theClass.getMethod("getInstance"); |
| | | } catch (final Exception e) { |
| | | final LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_FIND_GET_INSTANCE_METHOD.get(className, String |
| | | .valueOf(e.getMessage())); |
| | | throw new ConfigException(msg, e); |
| | | } |
| | | |
| | | // Get the definition instance. |
| | | AbstractManagedObjectDefinition<?, ?> d; |
| | | try { |
| | | d = (AbstractManagedObjectDefinition<?, ?>) method.invoke(null); |
| | | } catch (final Exception e) { |
| | | final LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_INVOKE_GET_INSTANCE_METHOD.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | throw new ConfigException(msg, e); |
| | | } |
| | | definitions.add(d); |
| | | } |
| | | } |
| | | |
| | | // Initialize any definitions that were loaded. |
| | | for (final AbstractManagedObjectDefinition<?, ?> d : definitions) { |
| | | try { |
| | | d.initialize(); |
| | | } catch (final Exception e) { |
| | | final LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_INITIALIZE_DEFN.get(d.getName(), d.getClass() |
| | | .getName(), String.valueOf(e.getMessage())); |
| | | throw new ConfigException(msg, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private JarFile loadJarFile(final File jar) throws ConfigException { |
| | | try { |
| | | // Load the extension jar file. |
| | | return new JarFile(jar); |
| | | } catch (final Exception e) { |
| | | debugLogger.trace("Unable to load jar file: " + jar, e); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(jar.getName(), jar.getParent(), |
| | | stackTraceToSingleLineString(e, true)); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(DN value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(DN value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (baseDN != null) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public DN decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public DN decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | DN dn = DN.valueOf(value); |
| | | validateValue(dn, options); |
| | | validateValue(dn); |
| | | return dn; |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | |
| | | if (stringValues != null) { |
| | | for (String stringValue : stringValues) { |
| | | // TODO : is it correct to have no validation ? |
| | | values.add(pd.decodeValue(stringValue, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS)); |
| | | values.add(pd.decodeValue(stringValue)); |
| | | } |
| | | } |
| | | return values; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Long value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | long nvalue = baseUnit.toMilliSeconds(value); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public Long decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | |
| | | // Convert the value a long in the property's required unit. |
| | | Long i = (long) baseUnit.fromMilliSeconds(ms); |
| | | try { |
| | | validateValue(i, options); |
| | | validateValue(i); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public E decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public E decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(E value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(E value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(AddressMask value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(AddressMask value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public AddressMask decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public AddressMask decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(InetAddress value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(InetAddress value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public InetAddress decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public InetAddress decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Integer value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(Integer value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Integer decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public Integer decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (allowUnlimited) { |
| | |
| | | } |
| | | |
| | | try { |
| | | validateValue(i, options); |
| | | validateValue(i); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | |
| | | if (resourceBundle == null) { |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | resourceBundle = |
| | | ResourceBundle.getBundle(baseName, locale, ClassLoaderProvider.getInstance().getClassLoader()); |
| | | ResourceBundle.getBundle(baseName, locale, ConfigurationFramework.getInstance().getClassLoader()); |
| | | map.put(locale, resourceBundle); |
| | | } |
| | | |
| | |
| | | // Load the resource file. |
| | | String baseName = prefix + "." + d.getClass().getName(); |
| | | String path = baseName.replace('.', '/') + ".properties"; |
| | | InputStream stream = ClassLoaderProvider.getInstance().getClassLoader().getResourceAsStream(path); |
| | | InputStream stream = ConfigurationFramework.getInstance().getClassLoader().getResourceAsStream(path); |
| | | |
| | | if (stream == null) { |
| | | throw new MissingResourceException("Can't find resource " + path, baseName, ""); |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | |
| | | /** |
| | | * A path which can be used to determine the location of a managed object |
| | |
| | | |
| | | // Now add the single RDN representing the named instance. |
| | | String type = profile.getRelationChildRDNType(r); |
| | | AttributeType attrType = DirectoryServer.getAttributeType(type.toLowerCase(), true); |
| | | AttributeType attrType = Schema.getDefaultSchema().getAttributeType(type); |
| | | dn = dn.child(new RDN(attrType, name)); |
| | | } |
| | | |
| | |
| | | |
| | | // Now add the single RDN representing the instance. |
| | | String type = profile.getRelationChildRDNType(r); |
| | | AttributeType attrType = DirectoryServer.getAttributeType(type.toLowerCase(), true); |
| | | AttributeType attrType = Schema.getDefaultSchema().getAttributeType(type); |
| | | dn = dn.child(new RDN(attrType, d.getName())); |
| | | } |
| | | |
| | |
| | | * <p> |
| | | * This method only casts the object to the required type; it does not |
| | | * validate the value once it has been cast. Subsequent validation should be |
| | | * performed using the method {@link #validateValue(Object, PropertyDefinitionsOptions)}. |
| | | * performed using the method {@link #validateValue(Object)}. |
| | | * <p> |
| | | * This method guarantees the following expression is always |
| | | * <code>true</code>: |
| | |
| | | * |
| | | * @param value |
| | | * The property string value (must not be <code>null</code>). |
| | | * @param options |
| | | * Options to use when decoding value. |
| | | * @return Returns the decoded property value. |
| | | * @throws PropertyException |
| | | * If the property value string is invalid. |
| | | */ |
| | | public abstract T decodeValue(String value, PropertyDefinitionsOptions options); |
| | | public abstract T decodeValue(String value); |
| | | |
| | | /** |
| | | * Encode the provided property value into its string representation. |
| | |
| | | * This method may throw an exception if the provided value is invalid. |
| | | * However, applications should not assume that implementations of this |
| | | * method will always validate a value. This task is the responsibility of |
| | | * {@link #validateValue(Object, PropertyDefinitionsOptions)}. |
| | | * {@link #validateValue(Object)}. |
| | | * <p> |
| | | * This default implementation simply returns the string representation of |
| | | * the provided value. Sub-classes might want to override this method if |
| | |
| | | * |
| | | * @param value |
| | | * The property value (must not be <code>null</code>). |
| | | * @param options |
| | | * Options to use when decoding value. |
| | | * @throws PropertyException |
| | | * If the property value is invalid. |
| | | */ |
| | | public abstract void validateValue(T value, PropertyDefinitionsOptions options); |
| | | public abstract void validateValue(T value); |
| | | |
| | | /** |
| | | * Performs any run-time initialization required by this property |
| | |
| | | if (pd != null) { |
| | | try { |
| | | // TODO : is it correct to have no validation ? |
| | | T tvalue = pd.decodeValue(name, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | T tvalue = pd.decodeValue(name); |
| | | return pd.normalizeValue(tvalue); |
| | | } catch (PropertyException e) { |
| | | // Fall through to default normalization. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Long value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public Long decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | |
| | | } |
| | | |
| | | try { |
| | | validateValue(i, options); |
| | | validateValue(i); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | public String decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value, options); |
| | | validateValue(value); |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value, PropertyDefinitionsOptions options) { |
| | | public void validateValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (pattern != null) { |
| | |
| | | import org.forgerock.opendj.config.OperationsException; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionUsageBuilder; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | |
| | | /** |
| | | * Thrown when an attempt is made to create a new managed object with an illegal |
| | |
| | | private static final long serialVersionUID = 7491748228684293291L; |
| | | |
| | | /** Create the message. */ |
| | | private static LocalizableMessage createMessage(String illegalName, PropertyDefinition<?> namingPropertyDefinition, |
| | | PropertyDefinitionsOptions options) { |
| | | private static LocalizableMessage createMessage(String illegalName, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | if (illegalName.length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_EMPTY.get(); |
| | | } else if (illegalName.trim().length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_BLANK.get(); |
| | | } else if (namingPropertyDefinition != null) { |
| | | try { |
| | | namingPropertyDefinition.decodeValue(illegalName, options); |
| | | namingPropertyDefinition.decodeValue(illegalName); |
| | | } catch (PropertyException e) { |
| | | PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder(true); |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX.get(illegalName, |
| | | namingPropertyDefinition.getName(), builder.getUsage(namingPropertyDefinition)); |
| | | namingPropertyDefinition.getName(), builder |
| | | .getUsage(namingPropertyDefinition)); |
| | | } |
| | | } |
| | | |
| | |
| | | * The illegal managed object name. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName) { |
| | | this(illegalName, null, null); |
| | | this(illegalName, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * The illegal managed object name. |
| | | * @param namingPropertyDefinition |
| | | * The naming property definition. |
| | | * @param options |
| | | * Options to decode property definition values. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName, PropertyDefinition<?> namingPropertyDefinition, |
| | | PropertyDefinitionsOptions options) { |
| | | super(createMessage(illegalName, namingPropertyDefinition, options)); |
| | | public IllegalManagedObjectNameException(String illegalName, PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(createMessage(illegalName, namingPropertyDefinition)); |
| | | |
| | | this.illegalName = illegalName; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionVisitor; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.Reference; |
| | | import org.forgerock.opendj.config.RelationDefinition; |
| | |
| | | * A visitor which is used to decode property LDAP values. |
| | | */ |
| | | private static final class ValueDecoder extends PropertyDefinitionVisitor<Object, String> { |
| | | |
| | | private final PropertyDefinitionsOptions options; |
| | | |
| | | /** |
| | | * Decodes the provided property LDAP value. |
| | | * |
| | |
| | | * The property definition. |
| | | * @param value |
| | | * The LDAP string representation. |
| | | * @param options |
| | | * Decoding options for property definitions. |
| | | * @return Returns the decoded LDAP value. |
| | | * @throws PropertyException |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | | public static <P> P decode(PropertyDefinition<P> pd, Object value, PropertyDefinitionsOptions options) { |
| | | public static <P> P decode(PropertyDefinition<P> pd, Object value) { |
| | | String s = String.valueOf(value); |
| | | return pd.castValue(pd.accept(new ValueDecoder(options), s)); |
| | | return pd.castValue(pd.accept(new ValueDecoder(), s)); |
| | | } |
| | | |
| | | // Prevent instantiation. |
| | | private ValueDecoder(PropertyDefinitionsOptions options) { |
| | | this.options = options; |
| | | private ValueDecoder() { |
| | | // Do nothing. |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public <T> Object visitUnknown(PropertyDefinition<T> d, String p) { |
| | | // By default the property definition's decoder will do. |
| | | return d.decodeValue(p, options); |
| | | return d.decodeValue(p); |
| | | } |
| | | } |
| | | |
| | |
| | | * The LDAP connection. |
| | | * @param profile |
| | | * The LDAP profile. |
| | | * @param propertyDefOptions |
| | | * Options used to validate property definitions values |
| | | */ |
| | | public LDAPDriver(LDAPConnection connection, LDAPProfile profile, PropertyDefinitionsOptions propertyDefOptions) { |
| | | super(propertyDefOptions); |
| | | public LDAPDriver(LDAPConnection connection, LDAPProfile profile) { |
| | | this.connection = connection; |
| | | this.profile = profile; |
| | | } |
| | |
| | | |
| | | // Decode the values. |
| | | SortedSet<P> values = new TreeSet<P>(propertyDef); |
| | | PropertyDefinitionsOptions options = context.getPropertyDefOptions(); |
| | | if (attribute != null) { |
| | | for (ByteString byteValue : attribute) { |
| | | P value = ValueDecoder.decode(propertyDef, byteValue, options); |
| | | P value = ValueDecoder.decode(propertyDef, byteValue); |
| | | values.add(value); |
| | | } |
| | | } |
| | |
| | | |
| | | // Get the property's active values. |
| | | SortedSet<P> activeValues = new TreeSet<P>(propertyDef); |
| | | PropertyDefinitionsOptions options = context.getPropertyDefOptions(); |
| | | if (attribute != null) { |
| | | for (ByteString byteValue : attribute) { |
| | | P value = ValueDecoder.decode(propertyDef, byteValue, options); |
| | | P value = ValueDecoder.decode(propertyDef, byteValue); |
| | | activeValues.add(value); |
| | | } |
| | | } |
| | |
| | | LDAPManagedObject(LDAPDriver driver, ManagedObjectDefinition<T, ? extends Configuration> d, |
| | | ManagedObjectPath<T, ? extends Configuration> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(d, path, properties, existsOnServer, namingPropertyDefinition, |
| | | driver.getManagementContext().getPropertyDefOptions()); |
| | | super(d, path, properties, existsOnServer, namingPropertyDefinition); |
| | | this.driver = driver; |
| | | } |
| | | |
| | |
| | | package org.forgerock.opendj.config.client.ldap; |
| | | |
| | | import org.forgerock.opendj.config.LDAPProfile; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.client.spi.Driver; |
| | | import org.forgerock.util.Reject; |
| | |
| | | * The LDAP connection. |
| | | * @param profile |
| | | * The LDAP profile. |
| | | * @param options |
| | | * Options to decode values of property definitions. |
| | | * @return Returns the new management context. |
| | | */ |
| | | public static ManagementContext createFromContext(LDAPConnection connection, LDAPProfile profile, |
| | | PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(connection, profile, options); |
| | | LDAPDriver driver = new LDAPDriver(connection, profile, options); |
| | | LDAPManagementContext context = new LDAPManagementContext(driver, options); |
| | | public static ManagementContext createFromContext(LDAPConnection connection, LDAPProfile profile) { |
| | | Reject.ifNull(connection, profile); |
| | | LDAPDriver driver = new LDAPDriver(connection, profile); |
| | | LDAPManagementContext context = new LDAPManagementContext(driver); |
| | | driver.setManagementContext(context); |
| | | return context; |
| | | } |
| | |
| | | /** The LDAP management context driver. */ |
| | | private final LDAPDriver driver; |
| | | |
| | | /** Options to validate and decode values of property definitions. */ |
| | | private final PropertyDefinitionsOptions options; |
| | | |
| | | /** Private constructor. */ |
| | | private LDAPManagementContext(LDAPDriver driver, PropertyDefinitionsOptions options) { |
| | | private LDAPManagementContext(LDAPDriver driver) { |
| | | this.driver = driver; |
| | | this.options = options; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | protected Driver getDriver() { |
| | | return driver; |
| | | } |
| | | |
| | | /** |
| | | * Returns the property definitions options. |
| | | * |
| | | * @return the options to validate and decode values of property |
| | | * definitions. |
| | | */ |
| | | protected PropertyDefinitionsOptions getPropertyDefOptions() { |
| | | return options; |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.OptionalRelationDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.RelationDefinition; |
| | | import org.forgerock.opendj.config.RelationDefinitionVisitor; |
| | |
| | | // The managed object's properties. |
| | | private final PropertySet properties; |
| | | |
| | | /** Decoding options for property definitions values. */ |
| | | private final PropertyDefinitionsOptions propertyDefOptions; |
| | | |
| | | /** |
| | | * Creates a new abstract managed object. |
| | | * |
| | |
| | | * committed). |
| | | * @param namingPropertyDefinition |
| | | * Optional naming property definition. |
| | | * @param propertyDefOptions TODO |
| | | */ |
| | | protected AbstractManagedObject(ManagedObjectDefinition<T, ? extends Configuration> d, |
| | | ManagedObjectPath<T, ? extends Configuration> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition, PropertyDefinitionsOptions propertyDefOptions) { |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | this.definition = d; |
| | | this.path = path; |
| | | this.properties = properties; |
| | | this.existsOnServer = existsOnServer; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | | this.propertyDefOptions = propertyDefOptions; |
| | | } |
| | | |
| | | /** |
| | |
| | | PropertyDefinition<?> pd = r.getNamingPropertyDefinition(); |
| | | if (pd != null) { |
| | | try { |
| | | pd.decodeValue(name, propertyDefOptions); |
| | | pd.decodeValue(name); |
| | | } catch (PropertyException e) { |
| | | throw new IllegalManagedObjectNameException(name, pd, propertyDefOptions); |
| | | throw new IllegalManagedObjectNameException(name, pd); |
| | | } |
| | | } |
| | | |
| | |
| | | throw PropertyException.propertyIsReadOnlyException(pd); |
| | | } |
| | | |
| | | properties.setPropertyValues(pd, values, propertyDefOptions); |
| | | properties.setPropertyValues(pd, values); |
| | | |
| | | // If this is a naming property then update the name. |
| | | if (pd.equals(namingPropertyDefinition)) { |
| | |
| | | |
| | | // Set the naming property if there is one. |
| | | if (namingPropertyDefinition != null) { |
| | | P value = namingPropertyDefinition.decodeValue(name, propertyDefOptions); |
| | | childProperties.setPropertyValues(namingPropertyDefinition, Collections.singleton(value), |
| | | propertyDefOptions); |
| | | P value = namingPropertyDefinition.decodeValue(name); |
| | | childProperties.setPropertyValues(namingPropertyDefinition, Collections.singleton(value)); |
| | | } |
| | | |
| | | return newInstance(d, p, childProperties, false, namingPropertyDefinition); |
| | |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.OptionalRelationDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyNotFoundException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.RelationDefinition; |
| | |
| | | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | | values.add(nextProperty.decodeValue(stringValue, propertyDefOptions)); |
| | | values.add(nextProperty.decodeValue(stringValue)); |
| | | } catch (PropertyException e) { |
| | | exception = PropertyException.defaultBehaviorException(nextProperty, e); |
| | | break; |
| | |
| | | Collection<T> tmp = find(target, pd2); |
| | | Collection<T> values = new ArrayList<T>(tmp.size()); |
| | | for (T value : tmp) { |
| | | pd1.validateValue(value, propertyDefOptions); |
| | | pd1.validateValue(value); |
| | | values.add(value); |
| | | } |
| | | return values; |
| | |
| | | } |
| | | }; |
| | | |
| | | private final PropertyDefinitionsOptions propertyDefOptions; |
| | | |
| | | /** |
| | | * Creates a new abstract driver. |
| | | * |
| | | * @param propertyDefOptions |
| | | * Decoding options for property definitions values. |
| | | */ |
| | | protected Driver(PropertyDefinitionsOptions propertyDefOptions) { |
| | | this.propertyDefOptions = propertyDefOptions; |
| | | protected Driver() { |
| | | // Do nothing. |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | |
| | | /** |
| | |
| | | * property (an empty set indicates that the property should be |
| | | * reset to its default behavior). The set will not be referenced |
| | | * by this managed object. |
| | | * @param options |
| | | * Options to validate property definitions values. |
| | | * @throws PropertyException |
| | | * If a new pending value is deemed to be invalid according to |
| | | * the property definition. |
| | |
| | | * If the specified property definition is not associated with |
| | | * this managed object. |
| | | */ |
| | | <T> void setPropertyValues(PropertyDefinition<T> d, Collection<T> values, |
| | | PropertyDefinitionsOptions options) { |
| | | <T> void setPropertyValues(PropertyDefinition<T> d, Collection<T> values) { |
| | | MyProperty<T> property = (MyProperty<T>) getProperty(d); |
| | | |
| | | if (values.size() > 1 && !d.hasOption(PropertyOption.MULTI_VALUED)) { |
| | |
| | | throw new NullPointerException(); |
| | | } |
| | | |
| | | d.validateValue(e, options); |
| | | d.validateValue(e); |
| | | } |
| | | |
| | | // Update the property. |
| | |
| | | |
| | | import org.forgerock.opendj.config.AbstractManagedObjectDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.client.ManagedObject; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | |
| | | |
| | | // Creates the new private implementation. |
| | | private <T> void buildImpl(PropertyDefinition<T> pd) { |
| | | T value = pd.decodeValue(propertyStringValue, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | T value = pd.decodeValue(propertyStringValue); |
| | | this.impl = new Impl<T>(pd, value); |
| | | } |
| | | |
| | |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.opendj.server.config.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.server.config.server.RootCfg; |
| | | import org.forgerock.opendj.config.AbsoluteInheritedDefaultBehaviorProvider; |
| | |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.config.PropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyDefinitionVisitor; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyNotFoundException; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.Reference; |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | | values.add(nextProperty.decodeValue(stringValue, propertyDefOptions)); |
| | | values.add(nextProperty.decodeValue(stringValue)); |
| | | } catch (PropertyException e) { |
| | | exception = PropertyException.defaultBehaviorException(nextProperty, e); |
| | | break; |
| | |
| | | if (attributeValues.size() > 0) { |
| | | Collection<T> pvalues = new ArrayList<T>(); |
| | | for (String value : attributeValues) { |
| | | pvalues.add(ValueDecoder.decode(propDef1, value, propertyDefOptions)); |
| | | pvalues.add(ValueDecoder.decode(propDef1, value)); |
| | | } |
| | | return pvalues; |
| | | } else { |
| | |
| | | Collection<T> tmp = find(target, propDef2); |
| | | Collection<T> pvalues = new ArrayList<T>(tmp.size()); |
| | | for (T value : tmp) { |
| | | propDef1.validateValue(value, propertyDefOptions); |
| | | propDef1.validateValue(value); |
| | | pvalues.add(value); |
| | | } |
| | | return pvalues; |
| | |
| | | */ |
| | | private static final class ValueDecoder extends PropertyDefinitionVisitor<Object, String> { |
| | | |
| | | private final PropertyDefinitionsOptions options; |
| | | |
| | | /** |
| | | * Decodes the provided property LDAP value. |
| | | * |
| | |
| | | * The property definition. |
| | | * @param value |
| | | * The LDAP string representation. |
| | | * @param options |
| | | * Options to decode property definitions values. |
| | | * @return Returns the decoded LDAP value. |
| | | * @throws PropertyException |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | | public static <P> P decode(PropertyDefinition<P> propertyDef, String value, |
| | | PropertyDefinitionsOptions options) { |
| | | return propertyDef.castValue(propertyDef.accept(new ValueDecoder(options), value)); |
| | | public static <P> P decode(PropertyDefinition<P> propertyDef, String value) { |
| | | return propertyDef.castValue(propertyDef.accept(new ValueDecoder(), value)); |
| | | } |
| | | |
| | | // Prevent instantiation. |
| | | private ValueDecoder(PropertyDefinitionsOptions options) { |
| | | this.options = options; |
| | | private ValueDecoder() { |
| | | // Do nothing. |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public <T> Object visitUnknown(PropertyDefinition<T> d, String p) { |
| | | // By default the property definition's decoder will do. |
| | | return d.decodeValue(p, options); |
| | | return d.decodeValue(p); |
| | | } |
| | | } |
| | | |
| | |
| | | private final ConfigurationRepository configRepository; |
| | | |
| | | /** |
| | | * Options to use when decoding and validating values of property |
| | | * definitions. |
| | | */ |
| | | private final PropertyDefinitionsOptions propertyDefOptions; |
| | | |
| | | /** |
| | | * Creates a context from the provided configuration repository. |
| | | * |
| | | * @param repository |
| | | * The repository of configuration entries. |
| | | * @param propertyDefOptions |
| | | * Options to use when decoding and validating values |
| | | * of property definitions. |
| | | */ |
| | | ServerManagementContext(ConfigurationRepository repository, PropertyDefinitionsOptions propertyDefOptions) { |
| | | ServerManagementContext(ConfigurationRepository repository) { |
| | | configRepository = repository; |
| | | this.propertyDefOptions = propertyDefOptions; |
| | | } |
| | | |
| | | /** |
| | |
| | | // The property has values defined for it. |
| | | for (String value : attributeValues) { |
| | | try { |
| | | pvalues.add(ValueDecoder.decode(propertyDef, value, propertyDefOptions)); |
| | | pvalues.add(ValueDecoder.decode(propertyDef, value)); |
| | | } catch (PropertyException e) { |
| | | exception = e; |
| | | } |
| | |
| | | // We should log a warning here if this is the case |
| | | // since the attribute should have been defined. |
| | | String attrID = LDAPProfile.getInstance().getAttributeName(d, pd); |
| | | AttributeType type = DirectoryServer.getAttributeType(attrID, true); |
| | | AttributeType type = Schema.getDefaultSchema().getAttributeType(attrID); |
| | | Iterable<Attribute> attributes = configEntry.getAllAttributes(AttributeDescription.create(type)); |
| | | List<String> values = new ArrayList<String>(); |
| | | for (Attribute attribute : attributes) { |
| | |
| | | @Test |
| | | public void testValidateValue() { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | propertyDef.validateValue(Schema.getDefaultSchema().getAttributeType("cn"), new PropertyDefinitionsOptions()); |
| | | propertyDef.validateValue(Schema.getDefaultSchema().getAttributeType("cn")); |
| | | } |
| | | |
| | | @DataProvider(name = "valueLegalData") |
| | |
| | | public void testDecodeValue(String value) { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | AttributeType expected = Schema.getDefaultSchema().getAttributeType(value); |
| | | assertEquals(propertyDef.decodeValue(value, new PropertyDefinitionsOptions()), expected); |
| | | assertEquals(propertyDef.decodeValue(value), expected); |
| | | } |
| | | |
| | | @Test(dataProvider = "valueLegalData") |
| | | public void testEncodeValue(String value) { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | assertEquals(propertyDef.encodeValue(propertyDef.decodeValue(value, new PropertyDefinitionsOptions())), value); |
| | | assertEquals(propertyDef.encodeValue(propertyDef.decodeValue(value)), value); |
| | | } |
| | | |
| | | @DataProvider(name = "valueIllegalData") |
| | |
| | | |
| | | @Test(dataProvider = "valueIllegalData", expectedExceptions = { PropertyException.class }) |
| | | public void testDecodeValueIllegal(String value) { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | propertyDef.decodeValue(value, new PropertyDefinitionsOptions()); |
| | | ConfigurationFramework.getInstance().setIsClient(false); |
| | | try { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | propertyDef.decodeValue(value); |
| | | } finally { |
| | | ConfigurationFramework.getInstance().setIsClient(true); |
| | | } |
| | | } |
| | | |
| | | @Test(dataProvider = "valueIllegalData") |
| | | public void testDecodeValueIllegalNoSchemaCheck(String value) { |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | AttributeType type = propertyDef.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | AttributeType type = propertyDef.decodeValue(value); |
| | | assertEquals(type.getNameOrOID(), value); |
| | | } |
| | | |
| | |
| | | @Test |
| | | public void testValidateValue() { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.validateValue(Boolean.TRUE, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.validateValue(Boolean.TRUE); |
| | | } |
| | | |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | | public void testValidateValueIllegal() { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.validateValue(null, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.validateValue(null); |
| | | } |
| | | |
| | | @DataProvider(name = "decodeValueData") |
| | |
| | | @Test(dataProvider = "decodeValueData") |
| | | public void testDecodeValue(String value, Boolean expected) { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | assertEquals(def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS), expected); |
| | | assertEquals(def.decodeValue(value), expected); |
| | | } |
| | | |
| | | @DataProvider(name = "decodeValueDataIllegal") |
| | |
| | | PropertyException.class }) |
| | | public void testDecodeValueIllegal(String value) { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.decodeValue(value); |
| | | } |
| | | |
| | | private BooleanPropertyDefinition createPropertyDefinition() { |
| | |
| | | public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> provider, Void p) { |
| | | SortedSet<T> values = new TreeSet<T>(); |
| | | for (String stringValue : provider.getDefaultValues()) { |
| | | values.add(propertyDef.decodeValue(stringValue, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS)); |
| | | values.add(propertyDef.decodeValue(stringValue)); |
| | | } |
| | | return values; |
| | | } |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate), PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate)); |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = PropertyException.class) |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate), PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate)); |
| | | } |
| | | |
| | | @Test(dataProvider = "legalValues") |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.decodeValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.decodeValue(valueToValidate); |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = PropertyException.class) |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.decodeValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.decodeValue(valueToValidate); |
| | | } |
| | | } |
| | |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(true); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.decodeValue("unlimited"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = PropertyException.class) |
| | |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.decodeValue("unlimited"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = PropertyException.class) |
| | |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.validateValue(-1L, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.validateValue(-1L); |
| | | } |
| | | |
| | | @DataProvider(name = "validateValueData") |
| | |
| | | builder.setUpperLimit(higherLimitInMillis); |
| | | builder.setAllowUnlimited(isAllowUnlimited); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.validateValue(valueInSeconds, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.validateValue(valueInSeconds); |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValidateValueData") |
| | |
| | | builder.setUpperLimit(highLimitInMillis); |
| | | builder.setAllowUnlimited(isAllowUnlimited); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.validateValue(valueInSeconds, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.validateValue(valueInSeconds); |
| | | } |
| | | |
| | | @DataProvider(name = "encodeValueData") |
| | |
| | | builder.setMaximumUnit(DurationUnit.DAYS); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | |
| | | assertThat(def.decodeValue(valueToDecode, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS)). |
| | | assertThat(def.decodeValue(valueToDecode)). |
| | | isEqualTo(expectedValue); |
| | | } |
| | | |
| | |
| | | builder.setLowerLimit(5L); |
| | | builder.setUpperLimit(10L); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.decodeValue(valueToDecode, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.decodeValue(valueToDecode); |
| | | } |
| | | |
| | | private DurationPropertyDefinition.Builder createTestBuilder() { |
| | |
| | | @Test(dataProvider = "decodeValueData") |
| | | public void testDecodeValue(String value, TestEnum expectedValue) { |
| | | EnumPropertyDefinition<?> def = builder.getInstance(); |
| | | assertEquals(def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS), expectedValue); |
| | | assertEquals(def.decodeValue(value), expectedValue); |
| | | } |
| | | |
| | | /** |
| | |
| | | PropertyException.class }) |
| | | public void testDecodeValueIllegalData(String value) { |
| | | EnumPropertyDefinition<?> def = builder.getInstance(); |
| | | def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.decodeValue(value); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Test |
| | | public void testValidateValue() { |
| | | EnumPropertyDefinition<TestEnum> def = builder.getInstance(); |
| | | def.validateValue(TestEnum.ONE, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | def.validateValue(TestEnum.ONE); |
| | | } |
| | | |
| | | } |
| | |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(true); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.decodeValue("unlimited"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = PropertyException.class) |
| | |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.decodeValue("unlimited"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = PropertyException.class) |
| | |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(-1, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(-1); |
| | | } |
| | | |
| | | @DataProvider(name = "validateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(allowUnlimited); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(valueToValidate); |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValidateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(allowUnlimited); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(value); |
| | | } |
| | | |
| | | @DataProvider(name = "encodeValueData") |
| | |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(true); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.decodeValue("unlimited"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = PropertyException.class) |
| | |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.decodeValue("unlimited"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = PropertyException.class) |
| | |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(-1L, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(-1L); |
| | | } |
| | | |
| | | @DataProvider(name = "validateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(isAllowUnlimited); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(valueToValidate); |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValidateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(allowUnlimited); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | propertyDef.validateValue(valueToValidate); |
| | | } |
| | | |
| | | @DataProvider(name = "encodeValueData") |
| | |
| | | @Test |
| | | public void testValidateValueNoPattern() { |
| | | StringPropertyDefinition d = getDefinition(true, null); |
| | | d.validateValue("abc", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | d.validateValue("abc"); |
| | | } |
| | | |
| | | @Test |
| | | public void testValidateValuePatternMatches() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.validateValue("abc", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | d.validateValue("abc"); |
| | | } |
| | | |
| | | // TODO : I18N problem |
| | | @Test(enabled = false, expectedExceptions = PropertyException.class) |
| | | public void testValidateValuePatternDoesNotMatch() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.validateValue("abc123", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | d.validateValue("abc123"); |
| | | } |
| | | |
| | | @Test |
| | | public void testDecodeValuePatternMatches() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | assertEquals(d.decodeValue("abc", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS), "abc"); |
| | | assertEquals(d.decodeValue("abc"), "abc"); |
| | | } |
| | | |
| | | // TODO : I18N problem |
| | | @Test(enabled = false, expectedExceptions = PropertyException.class) |
| | | public void testDecodeValuePatternDoesNotMatch() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.decodeValue("abc123", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | d.decodeValue("abc123"); |
| | | } |
| | | |
| | | // Create a string property definition. |
| | |
| | | import org.forgerock.opendj.config.AdminTestCase; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.LDAPProfile; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfgClient; |
| | | import org.forgerock.opendj.config.TestChildCfgDefn; |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObject; |
| | | import org.forgerock.opendj.config.client.ManagedObjectDecodingException; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.server.config.client.RootCfgClient; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.testng.Assert; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | public void testAggregationEmpty() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 1"); |
| | | assertSetEquals(child.getAggregationProperty(), new String[0]); |
| | |
| | | public void testAggregationSingle() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | |
| | |
| | | public void testAggregationMultiple() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 3"); |
| | | assertSetEquals(child.getAggregationProperty(), "LDAPS Connection Handler", "LDAP Connection Handler"); |
| | |
| | | public void testAggregationBadBaseDN() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | |
| | | try { |
| | |
| | | c.addExpectedAttribute("ds-cfg-rotation-policy", |
| | | "cn=LDAP Connection Handler,cn=connection handlers, cn=config"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(Schema.getDefaultSchema().getAttributeType("description")); |
| | | child.setAggregationProperty(Collections.singleton("LDAP Connection Handler")); |
| | | child.commit(); |
| | | |
| | |
| | | c.addExpectedModification("ds-cfg-rotation-policy", |
| | | "cn=HTTP Connection Handler,cn=connection handlers, cn=config", |
| | | "cn=JMX Connection Handler,cn=connection handlers, cn=config"); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setAggregationProperty(Arrays.asList("JMX Connection Handler", "HTTP Connection Handler")); |
| | |
| | | import org.forgerock.opendj.config.LDAPProfile; |
| | | import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; |
| | | import org.forgerock.opendj.config.ManagedObjectNotFoundException; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfgClient; |
| | | import org.forgerock.opendj.config.TestChildCfgDefn; |
| | |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.server.config.client.RootCfgClient; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.testng.Assert; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | child.commit(); |
| | | |
| | | c.assertEntryIsCreated(); |
| | |
| | | }; |
| | | conn.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(conn, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(conn, LDAPProfile.getInstance()); |
| | | try { |
| | | TestParentCfgClient parent = createTestParent(ctx, "test parent new"); |
| | | parent.setMandatoryBooleanProperty(true); |
| | | parent.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | parent.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | parent.commit(); |
| | | } catch (Exception e) { |
| | | if (expectedExceptionClass.equals(ErrorResultException.class)) { |
| | |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = createTestParent(ctx, "test parent new"); |
| | | parent.setMandatoryBooleanProperty(true); |
| | | parent.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | parent.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | parent.commit(); |
| | | c.assertEntryIsCreated(); |
| | | } |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 3"); |
| | | Assert.assertEquals(child.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | | Assert.assertEquals(child.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | Assert.assertEquals(child.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | DirectoryServer.getAttributeType("description")); |
| | | getAttributeType("description")); |
| | | assertDNSetEquals(child.getOptionalMultiValuedDNProperty1(), "dc=default value c3v1,dc=com", |
| | | "dc=default value c3v2,dc=com"); |
| | | assertDNSetEquals(child.getOptionalMultiValuedDNProperty2(), "dc=default value c3v3,dc=com", |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 1"); |
| | | Assert.assertEquals(child.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | | Assert.assertEquals(child.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | Assert.assertEquals(child.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | DirectoryServer.getAttributeType("description")); |
| | | getAttributeType("description")); |
| | | assertDNSetEquals(child.getOptionalMultiValuedDNProperty1(), "dc=domain1,dc=com", "dc=domain2,dc=com", |
| | | "dc=domain3,dc=com"); |
| | | assertDNSetEquals(child.getOptionalMultiValuedDNProperty2(), "dc=domain1,dc=com", "dc=domain2,dc=com", |
| | |
| | | }; |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | try { |
| | | getTestParent(ctx, "test parent 2"); |
| | | } catch (Exception e) { |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 2"); |
| | | Assert.assertEquals(parent.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | | Assert.assertEquals(parent.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | Assert.assertEquals(parent.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | DirectoryServer.getAttributeType("description")); |
| | | getAttributeType("description")); |
| | | assertDNSetEquals(parent.getOptionalMultiValuedDNProperty(), "dc=default value p2v1,dc=com", |
| | | "dc=default value p2v2,dc=com"); |
| | | } |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | Assert.assertEquals(parent.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | | Assert.assertEquals(parent.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | Assert.assertEquals(parent.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | DirectoryServer.getAttributeType("description")); |
| | | getAttributeType("description")); |
| | | assertDNSetEquals(parent.getOptionalMultiValuedDNProperty(), "dc=domain1,dc=com", "dc=domain2,dc=com", |
| | | "dc=domain3,dc=com"); |
| | | } |
| | |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | |
| | |
| | | |
| | | // Check that the default values are not committed. |
| | | child.setMandatoryBooleanProperty(true); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | child.commit(); |
| | | |
| | | c.assertEntryIsCreated(); |
| | |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 2"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | |
| | |
| | | |
| | | // Check that the default values are not committed. |
| | | child.setMandatoryBooleanProperty(true); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | child.commit(); |
| | | |
| | | c.assertEntryIsCreated(); |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | String[] actual = parent.listTestChildren(); |
| | | String[] expected = new String[] { "test child 1", "test child 2", "test child 3" }; |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 3"); |
| | | String[] actual = parent.listTestChildren(); |
| | | String[] expected = new String[] {}; |
| | |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | String[] actual = listTestParents(ctx); |
| | | String[] expected = new String[] { "test parent 1", "test parent 2", "test parent 3" }; |
| | | Assert.assertEqualsNoOrder(actual, expected); |
| | |
| | | public void testListTopLevelManagedObjectsEmpty() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | String[] actual = listTestParents(ctx); |
| | | String[] expected = new String[] {}; |
| | | Assert.assertEqualsNoOrder(actual, expected); |
| | |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-base-dn"); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet()); |
| | |
| | | new ModifyEntryMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.commit(); |
| | | Assert.assertFalse(c.isEntryModified()); |
| | |
| | | c.addExpectedModification("ds-cfg-enabled", "false"); |
| | | c.addExpectedModification("ds-cfg-base-dn", "dc=mod1,dc=com", "dc=mod2,dc=com"); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.setMandatoryBooleanProperty(false); |
| | | parent.setOptionalMultiValuedDNProperty(Arrays.asList(DN.valueOf("dc=mod1,dc=com"), |
| | |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.removeTestChild("test child 1"); |
| | | c.assertSubtreeIsDeleted(); |
| | |
| | | new DeleteSubtreeMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | removeTestParent(ctx, "test parent 1"); |
| | | c.assertSubtreeIsDeleted(); |
| | | } |
| | |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | child.commit(); |
| | | |
| | | c.assertEntryIsCreated(); |
| | |
| | | conn.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(conn, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(conn, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | | child.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | child.commit(); |
| | | Assert.fail("The add constraint failed to prevent creation of the managed object"); |
| | | } finally { |
| | |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.removeTestChild("test child 1"); |
| | | c.assertSubtreeIsDeleted(); |
| | |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.removeTestChild("test child 1"); |
| | | Assert.fail("The remove constraint failed to prevent removal of the managed object"); |
| | |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-base-dn"); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet()); |
| | |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-base-dn"); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance()); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet()); |
| | |
| | | ManagedObject<RootCfgClient> root = context.getRootConfigurationManagedObject(); |
| | | root.removeChild(TestCfg.getTestOneToManyParentRelationDefinition(), name); |
| | | } |
| | | |
| | | private AttributeType getAttributeType(String type) { |
| | | return Schema.getDefaultSchema().getAttributeType(type); |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.config.AdministratorAction; |
| | | import org.forgerock.opendj.config.AggregationPropertyDefinition; |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.PropertyOption; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfg; |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_3, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | try { |
| | | parentCfg.getTestChild(entryName(TEST_CHILD_3)); |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_5, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | |
| | | try { |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_6, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_7, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_6, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | |
| | | registerAggregationDefinitionWithTargetAndSourceEnabled(); |
| | | |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_7, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | |
| | | registerAggregationDefinitionWithTargetAndSourceEnabled(); |
| | | |
| | |
| | | public void testAggregationEmpty() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_1)); |
| | | |
| | |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_4, LDAP_CONN_HANDLER_ENTRY, |
| | | LDAPS_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_4)); |
| | | |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_2, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_2)); |
| | | |
| | |
| | | createConfigRepositoryWithEntries(TEST_PARENTS, TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_7, |
| | | CONN_HANDLER_ENTRY, TEST_CONNECTION_HANDLER_ENTRY_ENABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | createConfigRepositoryWithEntries(TEST_PARENTS, TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_7, |
| | | CONN_HANDLER_ENTRY, TEST_CONNECTION_HANDLER_ENTRY_ENABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.config.AdminTestCase; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfg; |
| | | import org.forgerock.opendj.config.TestChildCfgDefn; |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | MockConstraint constraint = new MockConstraint(true, false, configRepository); |
| | | try { |
| | | TestCfg.addConstraint(constraint); |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | MockConstraint constraint = new MockConstraint(false, true, configRepository); |
| | | try { |
| | | TestCfg.addConstraint(constraint); |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | parentCfg.addTestChildAddListener(new AddListener()); |
| | | MockConstraint constraint = new MockConstraint(isUsableConstraint, false, configRepository); |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | parentCfg.addTestChildDeleteListener(new DeleteListener()); |
| | | MockConstraint constraint = new MockConstraint(false, isDeleteAllowedConstraint, configRepository); |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | MockConstraint constraint = new MockConstraint(isUsableConstraint, false, configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg childCfg = parentCfg.getTestChild(entryName(TEST_CHILD_1)); |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.config.AdminTestCase; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestChildCfg; |
| | | import org.forgerock.opendj.config.TestParentCfg; |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(testParent, testBaseChild, testChild); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(testParent, context); |
| | | |
| | | // assert |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(testParent, testBaseChild, testChild); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(testParent, context); |
| | | TestConfigurationAddListener addListener = new TestConfigurationAddListener(); |
| | | parentCfg.addTestChildAddListener(addListener); |
| | |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_BASE_1, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg childCfg = parentCfg.getTestChild(entryName(TEST_CHILD_1)); |
| | | TestConfigurationChangeListener changeListener = new TestConfigurationChangeListener(); |
| | |
| | | public void testParentValues(Entry parentEntry, List<String> valuesForOptionalDNProperty) throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(parentEntry); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | TestParentCfg parent = getParentCfg(parentEntry, context); |
| | | |
| | | assertThat(parent.getMandatoryClassProperty()).isEqualTo( |
| | |
| | | import java.util.Arrays; |
| | | |
| | | import org.forgerock.opendj.config.AdminTestCase; |
| | | import org.forgerock.opendj.config.PropertyDefinitionsOptions; |
| | | import org.forgerock.opendj.config.TestCfg; |
| | | import org.forgerock.opendj.config.TestParentCfg; |
| | | import org.forgerock.opendj.config.server.spi.ConfigAddListener; |
| | |
| | | public void testRegisterAddListenerWithInstantiableRelationImmediate() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN, TEST_PARENTS_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerAddListener(TestCfg.getTestOneToManyParentRelationDefinition(), |
| | |
| | | public void testRegisterAddListenerWithInstantiableRelationDelayed() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationAddListener<TestParentCfg> parentListener = mock(ConfigurationAddListener.class); |
| | |
| | | public void testRegisterAddListenerWithInstantiableRelationDelayedThenActualized() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | // register a listener to root |
| | |
| | | public void testRegisterAddListenerWithOptionalRelation() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerAddListener(TestCfg.getTestOneToZeroOrOneParentRelationDefinition(), |
| | |
| | | public void testRegisterDeleteListenerWithInstantiableRelationImmediate() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN, TEST_PARENTS_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerDeleteListener(TestCfg.getTestOneToManyParentRelationDefinition(), |
| | |
| | | public void testRegisterDeleteListenerWithInstantiableRelationDelayed() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationDeleteListener<TestParentCfg> parentListener = mock(ConfigurationDeleteListener.class); |
| | |
| | | public void testRegisterDeleteListenerWithOptionalRelation() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerDeleteListener(TestCfg.getTestOneToZeroOrOneParentRelationDefinition(), |
| | |
| | | public void testRegisterChangeListener() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | root.setConfigDN(ROOT_CONFIG_DN); |
| | | |
| | |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN, TEST_PARENTS_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationAddListener<TestParentCfg> parentListener = mock(ConfigurationAddListener.class); |
| | |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | new ServerManagementContext(configRepository); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationAddListener<TestParentCfg> parentListener = mock(ConfigurationAddListener.class); |