code cleanups
SchemaBackend.java:
In getSchemaEntry(DN, boolean), inlined the boolean parameter since it was always called with 'false'.
Removed showAllAttributes field since it is an alias for currentConfig.isShowAllAttributes()
UpgradeUtils.java:
Changed the String CONFIG_FILE_PATH static field into File configFile.
*.java:
Code cleanup
Or consequence of the changes above.
| | |
| | | */ |
| | | package org.forgerock.opendj.rest2ldap.authz; |
| | | |
| | | import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.*; |
| | | import static org.forgerock.opendj.rest2ldap.authz.ConditionalFilters.asConditionalFilter; |
| | | import static org.forgerock.opendj.rest2ldap.authz.ConditionalFilters.newConditionalFilter; |
| | | import static org.forgerock.util.promise.Promises.newResultPromise; |
| | |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.TreeSet; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The fully-qualified name of this class. */ |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.backends.SchemaBackend"; |
| | | private static final String CLASS_NAME = "org.opends.server.backends.SchemaBackend"; |
| | | |
| | | private static final String CONFIG_SCHEMA_ELEMENTS_FILE = "02-config.ldif"; |
| | | private static final String CORE_SCHEMA_ELEMENTS_FILE = "00-core.ldif"; |
| | |
| | | private static final AttributeType nameFormsType = getNameFormsAttributeType(); |
| | | private static final AttributeType objectClassesType = getObjectClassesAttributeType(); |
| | | |
| | | /** The set of user-defined attributes that will be included in the schema entry. */ |
| | | private ArrayList<Attribute> userDefinedAttributes; |
| | | |
| | | /** The value containing DN of the user we'll say created the configuration. */ |
| | | private ByteString creatorsName; |
| | | /** The value containing the DN of the last user to modify the configuration. */ |
| | |
| | | private ByteString createTimestamp; |
| | | /** The timestamp that will be used for the latest schema modification time. */ |
| | | private ByteString modifyTimestamp; |
| | | |
| | | /** |
| | | * Indicates whether the attributes of the schema entry should always be |
| | | * treated as user attributes even if they are defined as operational. |
| | | */ |
| | | private boolean showAllAttributes; |
| | | /** The time that the schema was last modified. */ |
| | | private long modifyTime; |
| | | |
| | | /** The DN of the configuration entry for this backend. */ |
| | | private DN configEntryDN; |
| | | |
| | | /** The current configuration state. */ |
| | | private SchemaBackendCfg currentConfig; |
| | | |
| | | /** The set of base DNs for this backend. */ |
| | | private Set<DN> baseDNs; |
| | | |
| | | /** The set of user-defined attributes that will be included in the schema entry. */ |
| | | private List<Attribute> userDefinedAttributes; |
| | | /** The set of objectclasses that will be used in the schema entry. */ |
| | | private HashMap<ObjectClass,String> schemaObjectClasses; |
| | | |
| | | /** The time that the schema was last modified. */ |
| | | private long modifyTime; |
| | | private Map<ObjectClass, String> schemaObjectClasses; |
| | | |
| | | /** |
| | | * Regular expression used to strip minimum upper bound value from syntax |
| | | * Attribute Type Description. The value looks like: {count}. |
| | | */ |
| | | private String stripMinUpperBoundRegEx = "\\{\\d+\\}"; |
| | | private final Pattern stripMinUpperBoundRegEx = Pattern.compile("\\{\\d+\\}"); |
| | | |
| | | private ServerContext serverContext; |
| | | |
| | |
| | | ByteString newBaseDN = ByteString.valueOfUtf8(baseDNs.iterator().next().toString()); |
| | | creatorsName = newBaseDN; |
| | | modifiersName = newBaseDN; |
| | | |
| | | createTimestamp = createGeneralizedTimeValue(getSchema().getOldestModificationTime()); |
| | | modifyTimestamp = createGeneralizedTimeValue(getSchema().getYoungestModificationTime()); |
| | | |
| | |
| | | addAllNonSchemaConfigAttributes(userDefinedAttributes, configEntry.getUserAttributes().values()); |
| | | addAllNonSchemaConfigAttributes(userDefinedAttributes, configEntry.getOperationalAttributes().values()); |
| | | |
| | | showAllAttributes = cfg.isShowAllAttributes(); |
| | | |
| | | currentConfig = cfg; |
| | | } |
| | | |
| | |
| | | * Generates and returns a schema entry for the Directory Server. |
| | | * |
| | | * @param entryDN The DN to use for the generated entry. |
| | | * @param includeSchemaFile A boolean indicating if the X-SCHEMA-FILE |
| | | * extension should be used when generating |
| | | * the entry. |
| | | * |
| | | * @return The schema entry that was generated. |
| | | */ |
| | | public Entry getSchemaEntry(DN entryDN, boolean includeSchemaFile) |
| | | public Entry getSchemaEntry(DN entryDN) |
| | | { |
| | | return getSchemaEntry(entryDN, includeSchemaFile, false); |
| | | return getSchemaEntry(entryDN, false, false); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (stripSyntaxMinimumUpperBound && value.indexOf('{') != -1) |
| | | { |
| | | // Strip the minimum upper bound value from the attribute value. |
| | | value = value.replaceFirst(stripMinUpperBoundRegEx, ""); |
| | | value = stripMinUpperBoundRegEx.matcher(value).replaceFirst(""); |
| | | } |
| | | builder.add(value); |
| | | } |
| | |
| | | Attribute attribute = builder.toAttribute(); |
| | | AttributeType attrType = attribute.getAttributeDescription().getAttributeType(); |
| | | if (attrType.isOperational() |
| | | && (ignoreShowAllOption || !showAllAttributes)) |
| | | && (ignoreShowAllOption || !showAllAttributes())) |
| | | { |
| | | operationalAttrs.put(attrType, newArrayList(attribute)); |
| | | } |
| | |
| | | |
| | | // Get the schema entry and see if it matches the filter. If so, then send |
| | | // it to the client. |
| | | Entry schemaEntry = getSchemaEntry(baseDN, false); |
| | | Entry schemaEntry = getSchemaEntry(baseDN); |
| | | SearchFilter filter = searchOperation.getFilter(); |
| | | if (filter.matchesEntry(schemaEntry)) |
| | | { |
| | |
| | | newBaseDNs = null; |
| | | } |
| | | |
| | | // Check to see if we should change the behavior regarding whether to show |
| | | // all schema attributes. |
| | | boolean newShowAllAttributes = backendCfg.isShowAllAttributes(); |
| | | |
| | | // Check to see if there is a new set of user-defined attributes. |
| | | ArrayList<Attribute> newUserAttrs = new ArrayList<>(); |
| | | List<Attribute> newUserAttrs = new ArrayList<>(); |
| | | try |
| | | { |
| | | Entry configEntry = DirectoryServer.getConfigEntry(configEntryDN); |
| | |
| | | } |
| | | } |
| | | |
| | | showAllAttributes = newShowAllAttributes; |
| | | |
| | | userDefinedAttributes = newUserAttrs; |
| | | LocalizableMessage message = INFO_SCHEMA_USING_NEW_USER_ATTRS.get(); |
| | | ccr.addMessage(message); |
| | | ccr.addMessage(INFO_SCHEMA_USING_NEW_USER_ATTRS.get()); |
| | | } |
| | | |
| | | currentConfig = backendCfg; |
| | |
| | | */ |
| | | boolean showAllAttributes() |
| | | { |
| | | return showAllAttributes; |
| | | } |
| | | |
| | | /** |
| | | * Specifies whether to treat common schema attributes like user attributes |
| | | * rather than operational attributes. |
| | | * |
| | | * @param showAllAttributes Specifies whether to treat common schema |
| | | * attributes like user attributes rather than |
| | | * operational attributes. |
| | | */ |
| | | void setShowAllAttributes(boolean showAllAttributes) |
| | | { |
| | | this.showAllAttributes = showAllAttributes; |
| | | return this.currentConfig.isShowAllAttributes(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Map.Entry; |
| | | import java.util.Set; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.util.Utils; |
| | | import org.forgerock.opendj.server.config.server.MonitorProviderCfg; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.api.AlertGenerator; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.DirectoryServerMBean; |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** |
| | | * The fully-qualified name of this class. |
| | | */ |
| | | /** The fully-qualified name of this class. */ |
| | | private static final String CLASS_NAME = "org.opends.server.config.JMXMBean"; |
| | | |
| | | |
| | | |
| | | /** The set of alert generators for this MBean. */ |
| | | private List<AlertGenerator> alertGenerators; |
| | | |
| | | /** The set of monitor providers for this MBean. */ |
| | | private List<MonitorProvider<? extends MonitorProviderCfg>> monitorProviders; |
| | | |
| | | /** The DN of the configuration entry with which this MBean is associated. */ |
| | | private DN configEntryDN; |
| | | |
| | | /** The object name for this MBean. */ |
| | | private ObjectName objectName; |
| | | |
| | |
| | | * @param generator The alert generator to remove from the set of alert |
| | | * generators for this JMX MBean. |
| | | * |
| | | * @return <CODE>true</CODE> if the alert generator was removed, or |
| | | * <CODE>false</CODE> if it was not associated with this MBean. |
| | | * @return {@code true} if the alert generator was removed, |
| | | * or {@code false} if it was not associated with this MBean. |
| | | */ |
| | | public boolean removeAlertGenerator(AlertGenerator generator) |
| | | { |
| | |
| | | * @param component The component to add to the set of monitor providers |
| | | * for this JMX MBean. |
| | | */ |
| | | public void addMonitorProvider(MonitorProvider<? extends MonitorProviderCfg> |
| | | component) |
| | | public void addMonitorProvider(MonitorProvider<? extends MonitorProviderCfg> component) |
| | | { |
| | | synchronized (monitorProviders) |
| | | { |
| | |
| | | * @param component The component to remove from the set of monitor |
| | | * providers for this JMX MBean. |
| | | * |
| | | * @return <CODE>true</CODE> if the specified component was successfully |
| | | * removed, or <CODE>false</CODE> if not. |
| | | * @return {@code true} if the specified component was successfully removed, |
| | | * or {@code false} if not. |
| | | */ |
| | | public boolean removeMonitorProvider(MonitorProvider<?> component) |
| | | { |
| | |
| | | * |
| | | * @param name The name of the configuration attribute to retrieve. |
| | | * |
| | | * @return The specified configuration attribute, or <CODE>null</CODE> if |
| | | * @return The specified configuration attribute, or {@code null} if |
| | | * there is no such attribute. |
| | | */ |
| | | private Attribute getJmxAttribute(String name) |
| | |
| | | } |
| | | |
| | | Iterator<ByteString> iterator = a.iterator(); |
| | | ByteString value = iterator.next(); |
| | | ByteString firstValue = iterator.next(); |
| | | |
| | | if (iterator.hasNext()) |
| | | { |
| | | List<String> stringValues = newArrayList(value.toString()); |
| | | List<String> stringValues = newArrayList(firstValue.toString()); |
| | | while (iterator.hasNext()) |
| | | { |
| | | value = iterator.next(); |
| | | ByteString value = iterator.next(); |
| | | stringValues.add(value.toString()); |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | return new Attribute(name, value.toString()); |
| | | return new Attribute(name, firstValue.toString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append(actionName); |
| | | buffer.append("("); |
| | | Utils.joinAsString(", ", (Object[]) signature); |
| | | Utils.joinAsString(buffer, ", ", (Object[]) signature); |
| | | buffer.append(")"); |
| | | |
| | | LocalizableMessage message = ERR_CONFIG_JMX_NO_METHOD.get(buffer, configEntryDN); |
| | |
| | | * Provides the exposed attributes and actions of the Dynamic MBean using an |
| | | * MBeanInfo object. |
| | | * |
| | | * @return An instance of <CODE>MBeanInfo</CODE> allowing all attributes and |
| | | * @return An instance of {@code MBeanInfo} allowing all attributes and |
| | | * actions exposed by this Dynamic MBean to be retrieved. |
| | | */ |
| | | @Override |
| | |
| | | String className = generator.getClassName(); |
| | | |
| | | Map<String, String> alerts = generator.getAlerts(); |
| | | for (String type : alerts.keySet()) |
| | | for (Entry<String, String> mapEntry : alerts.entrySet()) |
| | | { |
| | | String[] types = { type }; |
| | | String description = alerts.get(type); |
| | | String[] types = { mapEntry.getKey() }; |
| | | String description = mapEntry.getValue(); |
| | | notifications.add(new MBeanNotificationInfo(types, className, description)); |
| | | } |
| | | } |
| | |
| | | */ |
| | | private ClientConnection getClientConnection() |
| | | { |
| | | ClientConnection clientConnection = null; |
| | | java.security.AccessControlContext acc = java.security.AccessController |
| | | .getContext(); |
| | | java.security.AccessControlContext acc = java.security.AccessController.getContext(); |
| | | try |
| | | { |
| | | javax.security.auth.Subject subject = javax.security.auth.Subject |
| | | .getSubject(acc); |
| | | javax.security.auth.Subject subject = javax.security.auth.Subject.getSubject(acc); |
| | | if (subject != null) |
| | | { |
| | | Set<?> privateCreds = subject.getPrivateCredentials(Credential.class); |
| | | clientConnection = ((Credential) privateCreds.iterator().next()) |
| | | .getClientConnection(); |
| | | return ((Credential) privateCreds.iterator().next()).getClientConnection(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | } |
| | | return clientConnection; |
| | | return null; |
| | | } |
| | | } |
| | |
| | | final ProgressNotificationCallback pnc = new ProgressNotificationCallback(INFORMATION, summary, 20); |
| | | context.notifyProgress(pnc); |
| | | |
| | | final File schemaFileTemplate = |
| | | new File(templateConfigSchemaDirectory, fileName); |
| | | |
| | | final File schemaFileTemplate = new File(templateConfigSchemaDirectory, fileName); |
| | | final File pathDestination = new File(configSchemaDirectory, fileName); |
| | | try |
| | | { |
| | | final int changeCount = |
| | | updateSchemaFile(schemaFileTemplate, pathDestination, |
| | | attributeOids, null); |
| | | final int changeCount = updateSchemaFile(schemaFileTemplate, pathDestination, attributeOids, null); |
| | | |
| | | displayChangeCount(pathDestination.getPath(), changeCount); |
| | | |
| | | displayChangeCount(pathDestination, changeCount); |
| | | context.notifyProgress(pnc.setProgress(100)); |
| | | } |
| | | catch (final IOException | IllegalStateException e) |
| | |
| | | final ProgressNotificationCallback pnc = new ProgressNotificationCallback(INFORMATION, summary, 20); |
| | | context.notifyProgress(pnc); |
| | | |
| | | final File schemaFileTemplate = |
| | | new File(templateConfigSchemaDirectory, fileName); |
| | | |
| | | final File schemaFileTemplate = new File(templateConfigSchemaDirectory, fileName); |
| | | final File pathDestination = new File(configSchemaDirectory, fileName); |
| | | |
| | | context.notifyProgress(pnc.setProgress(20)); |
| | | |
| | | try |
| | | { |
| | | final int changeCount = |
| | | updateSchemaFile(schemaFileTemplate, pathDestination, |
| | | null, objectClassesOids); |
| | | final int changeCount = updateSchemaFile(schemaFileTemplate, pathDestination, null, objectClassesOids); |
| | | |
| | | displayChangeCount(pathDestination.getPath(), changeCount); |
| | | |
| | | displayChangeCount(pathDestination, changeCount); |
| | | context.notifyProgress(pnc.setProgress(100)); |
| | | } |
| | | catch (final IOException e) |
| | |
| | | |
| | | List<String> args = new ArrayList<>(baseArgs); |
| | | args.add("--configFile"); |
| | | args.add(CONFIG_FILE_PATH); |
| | | args.add(configFile.getAbsolutePath()); |
| | | for (final String be : baseDNs) |
| | | { |
| | | args.add("--baseDN"); |
| | |
| | | } |
| | | } |
| | | |
| | | private static void displayChangeCount(final String fileName, |
| | | final int changeCount) |
| | | private static void displayChangeCount(final File configfile, final int changeCount) |
| | | { |
| | | String fileName = configfile.getAbsolutePath(); |
| | | if (changeCount != 0) |
| | | { |
| | | logger.debug(INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE, fileName, changeCount); |
| | |
| | | try |
| | | { |
| | | final Filter filterVal = filter != null ? Filter.valueOf(filter) : null; |
| | | final int changeCount = updateConfigFile(CONFIG_FILE_PATH, filterVal, changeOperationType, ldif); |
| | | displayChangeCount(CONFIG_FILE_PATH, changeCount); |
| | | final int changeCount = updateConfigFile(configFile, filterVal, changeOperationType, ldif); |
| | | displayChangeCount(configFile, changeCount); |
| | | |
| | | context.notifyProgress(pnc.setProgress(100)); |
| | | } |
| | |
| | | import java.io.FileReader; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.Matcher; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The config folder of the current instance. */ |
| | | /** The {@code config} folder of the current instance. */ |
| | | static final File configDirectory = new File(getInstancePath(), CONFIG_PATH_RELATIVE); |
| | | /** The config/schema folder of the current instance. */ |
| | | /** The {@code config/schema} folder of the current instance. */ |
| | | static final File configSchemaDirectory = new File(configDirectory, SCHEMA_PATH_RELATIVE); |
| | | /** The template folder of the current installation. */ |
| | | /** The {@code template} folder of the current installation. */ |
| | | private static final File templateDirectory = new File(getInstallationPath(), TEMPLATE_RELATIVE_PATH); |
| | | /** The template/config folder of the current installation. */ |
| | | /** The {@code template/config} folder of the current installation. */ |
| | | static final File templateConfigDirectory = new File(templateDirectory, CONFIG_PATH_RELATIVE); |
| | | /** The template/config/schema folder of the current installation. */ |
| | | /** The {@code template/config/schema} folder of the current installation. */ |
| | | static final File templateConfigSchemaDirectory = new File(templateConfigDirectory, SCHEMA_PATH_RELATIVE); |
| | | /** The config/snmp/security folder of the current instance. */ |
| | | /** The {@code config/snmp/security} folder of the current instance. */ |
| | | static final File configSnmpSecurityDirectory = new File( |
| | | configDirectory + File.separator + SNMP_PATH_RELATIVE + File.separator + SECURITY_PATH_RELATIVE); |
| | | /** The lib folder of the current installation. */ |
| | | /** The {@code lib} folder of the current installation. */ |
| | | static final File libDirectory = new File(getInstallationPath(), LIB_RELATIVE_PATH); |
| | | /** The bin folder of the current installation. */ |
| | | /** The {@code bin} folder of the current installation. */ |
| | | static final File binDirectory = new File(getInstallationPath(), UNIX_BINARIES_PATH_RELATIVE); |
| | | /** The bat folder of the current installation. */ |
| | | /** The {@code bat} folder of the current installation. */ |
| | | static final File batDirectory = new File(getInstallationPath(), WINDOWS_BINARIES_PATH_RELATIVE); |
| | | /** The server configuration file path. */ |
| | | static final String CONFIG_FILE_PATH = |
| | | Paths.get(configDirectory.getAbsolutePath(), CURRENT_CONFIG_FILE_NAME).toString(); |
| | | static final File configFile = new File(configDirectory, CURRENT_CONFIG_FILE_NAME); |
| | | |
| | | /** |
| | | * Returns the path of the installation of the directory server. Note that |
| | |
| | | return baseDNs; |
| | | } |
| | | |
| | | static EntryReader searchConfigFile(final SearchRequest sr) throws FileNotFoundException |
| | | static EntryReader searchConfigFile(final SearchRequest searchRequest) throws FileNotFoundException |
| | | { |
| | | final Schema schema = getUpgradeSchema(); |
| | | final File configFile = new File(configDirectory, CURRENT_CONFIG_FILE_NAME); |
| | | final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)).setSchema(schema); |
| | | return LDIF.search(entryReader, sr, schema); |
| | | return LDIF.search(entryReader, searchRequest, schema); |
| | | } |
| | | |
| | | /** |
| | | * Updates the config file during the upgrade process. |
| | | * |
| | | * @param configPath |
| | | * @param configFile |
| | | * The original path to the file. |
| | | * @param filter |
| | | * The filter to select entries. Only useful for modify change type. |
| | | * @param changeType |
| | | * The change type which must be applied to ldif lines. |
| | | * @param ldifLines |
| | | * The change record ldif lines. |
| | | * For ADD change type, the first line must be the dn. |
| | | * For DELETE change type, the first and only line must be the dn. |
| | | * The change record ldif lines. For ADD change type, the first line must be the dn. For |
| | | * DELETE change type, the first and only line must be the dn. |
| | | * @throws IOException |
| | | * If an Exception occurs during the input output methods. |
| | | * @return The changes number that have occurred. |
| | | */ |
| | | static int updateConfigFile(final String configPath, |
| | | static int updateConfigFile(final File configFile, |
| | | final Filter filter, final ChangeOperationType changeType, |
| | | final String... ldifLines) throws IOException |
| | | { |
| | | final File original = new File(configPath); |
| | | final File original = configFile; |
| | | final File copyConfig = |
| | | File.createTempFile("copyConfig", ".tmp", original.getParentFile()); |
| | | |
| | | int changeCount = 0; |
| | | final Schema schema = getUpgradeSchema(); |
| | | try (LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configPath)).setSchema(schema); |
| | | try (LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)).setSchema(schema); |
| | | LDIFEntryWriter writer = new LDIFEntryWriter(new FileOutputStream(copyConfig))) |
| | | { |
| | | writer.setWrapColumn(80); |
| | |
| | | |
| | | if (changeType == ADD && !entryAlreadyExist) |
| | | { |
| | | final AddRequest ar = Requests.newAddRequest(ldifLines); |
| | | writer.writeEntry(ar); |
| | | writer.writeEntry(Requests.newAddRequest(ldifLines)); |
| | | logger.debug(LocalizableMessage.raw("Entry successfully added %s in %s", ldifDN, original.getAbsolutePath())); |
| | | changeCount++; |
| | | } |
| | |
| | | try |
| | | { |
| | | // Renaming the file, overwriting previous one. |
| | | rename(copyConfig, new File(configPath)); |
| | | rename(copyConfig, configFile); |
| | | return changeCount; |
| | | } |
| | | catch (IOException e) |
| | | { |
| | |
| | | deleteRecursively(original); |
| | | throw e; |
| | | } |
| | | |
| | | return changeCount; |
| | | } |
| | | |
| | | private static String removeDnPrefix(String dnLine) |
| | |
| | | { |
| | | throw new IllegalStateException(e); |
| | | } |
| | | throw new IllegalStateException(ERR_UPGRADE_UNKNOWN_OC_ATT.get(type, oid) |
| | | .toString()); |
| | | throw new IllegalStateException(ERR_UPGRADE_UNKNOWN_OC_ATT.get(type, oid).toString()); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new file in the config/upgrade folder. The new file is a |
| | | * concatenation of entries of all files contained in the config/schema |
| | | * folder. |
| | | * Creates a new file in The {@code config/upgrade} folder. |
| | | * The new file is a concatenation of entries of all files contained in the |
| | | * {@code config/schema} folder. |
| | | * |
| | | * @param folder |
| | | * The folder containing the schema files. |
| | |
| | | static List<String> filterExistingIndexes(final Set<String> candidateIndexes, final String backendID) |
| | | { |
| | | final List<String> indexesToRebuild = new ArrayList<>(); |
| | | try (final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(CONFIG_FILE_PATH))) |
| | | try (final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile))) |
| | | { |
| | | while (entryReader.hasNext()) |
| | | { |
| | |
| | | File configDirectory = configFile.getParentFile(); |
| | | File upgradeDirectory = new File(configDirectory, "upgrade"); |
| | | upgradeDirectory.mkdir(); |
| | | File concatFile = new File(upgradeDirectory, |
| | | SCHEMA_CONCAT_FILE_NAME); |
| | | File concatFile = new File(upgradeDirectory, SCHEMA_CONCAT_FILE_NAME); |
| | | concatFilePath = concatFile.getAbsolutePath(); |
| | | |
| | | File tempFile = new File(concatFilePath + ".tmp"); |
| | | try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile, false))) |
| | | { |
| | | writer.write("dn: " + DirectoryServer.getSchemaDN()); |
| | | writer.newLine(); |
| | | writer.write("objectClass: top"); |
| | | writer.newLine(); |
| | | writer.write("objectClass: ldapSubentry"); |
| | | writer.newLine(); |
| | | writer.write("objectClass: subschema"); |
| | | writer.newLine(); |
| | | writeLines(writer, |
| | | "dn: " + DirectoryServer.getSchemaDN(), |
| | | "objectClass: top", |
| | | "objectClass: ldapSubentry", |
| | | "objectClass: subschema"); |
| | | |
| | | writeLines(writer, ATTR_ATTRIBUTE_TYPES, attributeTypes); |
| | | writeLines(writer, ATTR_OBJECTCLASSES, objectClasses); |
| | |
| | | } |
| | | } |
| | | |
| | | private static void writeLines(BufferedWriter writer, String... lines) throws IOException |
| | | { |
| | | for (String line : lines) |
| | | { |
| | | writer.write(line); |
| | | writer.newLine(); |
| | | } |
| | | } |
| | | |
| | | private static void writeLines(BufferedWriter writer, String beforeColumn, Set<String> lines) throws IOException |
| | | { |
| | | for (String line : lines) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Reads the files contained in the schema directory and generates a |
| | | * concatenated view of their contents in the provided sets. |
| | |
| | | { |
| | | if (definition.startsWith("::")) |
| | | { |
| | | // See OPENDJ-2792: the definition of the ds-cfg-csv-delimiter-char attribute type |
| | | // had a space accidentally added after the closing parenthesis. |
| | | // This was unfortunately interpreted as base64 |
| | | definition = ByteString.wrap(Base64.decode(definition.substring(2).trim())).toString(); |
| | | } |
| | | else if (definition.startsWith(":")) |
| | |
| | | |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.*; |
| | | import static org.mockito.Mockito.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.ldap.schema.SchemaBuilder; |
| | | import org.forgerock.opendj.server.config.server.SchemaBackendCfg; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.AddOperation; |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGetSchemaEntry() |
| | | throws Exception |
| | | public void testGetSchemaEntry() throws Exception |
| | | { |
| | | DN schemaDN = DN.valueOf("cn=schema"); |
| | | Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false); |
| | | Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN); |
| | | assertNotNull(schemaEntry); |
| | | assertEquals(schemaEntry.getName(), schemaDN); |
| | | |
| | |
| | | assertTrue(schemaEntry.hasAttribute(getMatchingRulesAttributeType())); |
| | | |
| | | schemaDN = DN.valueOf("cn=subschema"); |
| | | schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false); |
| | | schemaEntry = schemaBackend.getSchemaEntry(schemaDN); |
| | | assertNotNull(schemaEntry); |
| | | assertEquals(schemaEntry.getName(), schemaDN); |
| | | |
| | |
| | | { |
| | | DN schemaDN = DN.valueOf("cn=schema"); |
| | | |
| | | DeleteOperationBasis deleteOperation = |
| | | new DeleteOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(), |
| | | DeleteOperationBasis deleteOperation = new DeleteOperationBasis( |
| | | getRootConnection(), nextOperationID(), nextMessageID(), |
| | | null, schemaDN); |
| | | |
| | | schemaBackend.deleteEntry(schemaDN, deleteOperation); |
| | |
| | | DN currentSchemaDN = DN.valueOf("cn=schema"); |
| | | DN newSchemaDN = DN.valueOf("cn=newschema"); |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyDNOperationBasis modifyDNOperation = |
| | | new ModifyDNOperationBasis(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), null, |
| | | currentSchemaDN, newSchemaDN.rdn(), |
| | | true, null); |
| | | ModifyDNOperationBasis modifyDNOperation = new ModifyDNOperationBasis( |
| | | getRootConnection(), nextOperationID(), nextMessageID(), |
| | | null, currentSchemaDN, newSchemaDN.rdn(), true, null); |
| | | |
| | | schemaBackend.renameEntry(currentSchemaDN, |
| | | schemaBackend.getSchemaEntry(newSchemaDN, false), |
| | | modifyDNOperation); |
| | | Entry newSchemaEntry = schemaBackend.getSchemaEntry(newSchemaDN); |
| | | schemaBackend.renameEntry(currentSchemaDN, newSchemaEntry, modifyDNOperation); |
| | | } |
| | | |
| | | /** |
| | |
| | | AttributeType s = getLDAPSyntaxesAttributeType(); |
| | | |
| | | assertFalse(schemaBackend.showAllAttributes()); |
| | | Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false); |
| | | Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(a)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(o)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(m)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(s)); |
| | | |
| | | schemaBackend.setShowAllAttributes(true); |
| | | assertTrue(schemaBackend.showAllAttributes()); |
| | | schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false); |
| | | setShowAllAttributes(schemaBackend, true); |
| | | schemaEntry = schemaBackend.getSchemaEntry(schemaDN); |
| | | assertFalse(schemaEntry.hasOperationalAttribute(a)); |
| | | assertFalse(schemaEntry.hasOperationalAttribute(o)); |
| | | assertFalse(schemaEntry.hasOperationalAttribute(m)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(s)); |
| | | |
| | | schemaBackend.setShowAllAttributes(false); |
| | | setShowAllAttributes(schemaBackend, false); |
| | | assertFalse(schemaBackend.showAllAttributes()); |
| | | schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false); |
| | | schemaEntry = schemaBackend.getSchemaEntry(schemaDN); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(a)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(o)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(m)); |
| | | assertTrue(schemaEntry.hasOperationalAttribute(s)); |
| | | } |
| | | |
| | | private void setShowAllAttributes(SchemaBackend schemaBackend, boolean showAllAttributes) |
| | | { |
| | | SchemaBackendCfg cfg = spy(SchemaBackendCfg.class); |
| | | when(cfg.isShowAllAttributes()).thenReturn(showAllAttributes); |
| | | schemaBackend.applyConfigurationChange(cfg); |
| | | } |
| | | |
| | | /** |
| | | * Tests the behavior of the schema backend when attempting to add a new |
| | | * attribute type that is not allowed to be altered. |