opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/SomeSchemaElement.java
@@ -15,8 +15,6 @@ */ package org.opends.guitools.controlpanel.datamodel; import static org.opends.server.util.ServerConstants.*; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -98,7 +96,7 @@ return attributeType != null; } private ServerSchemaElement asSchemaElement() private ServerSchemaElement asServerSchemaElement() { if (element == null) { @@ -140,19 +138,19 @@ @Override public String getDescription() { return asSchemaElement().getDescription(); return asServerSchemaElement().getDescription(); } @Override public Map<String, List<String>> getExtraProperties() { return asSchemaElement().getExtraProperties(); return asServerSchemaElement().getExtraProperties(); } @Override public String toString() { return asSchemaElement().toString(); return asServerSchemaElement().toString(); } /** @@ -164,7 +162,7 @@ */ public String getDefinitionWithFileName() { return asSchemaElement().getDefinitionWithFileName(); return asServerSchemaElement().getDefinitionWithFileName(); } /** @@ -174,20 +172,7 @@ */ public String getSchemaFile() { return asSchemaElement().getSchemaFile(); } /** * Sets the name of the schema file that contains the definition of the wrapped element. * * @param serverContext * the server context * @param schemaFile * the name of the schema file that contains the definition of the wrapped element. */ public void setSchemaFile(ServerContext serverContext, String schemaFile) { setExtraPropertySingleValue(serverContext, SCHEMA_PROPERTY_FILENAME, schemaFile); return asServerSchemaElement().getSchemaFile(); } /** @@ -196,11 +181,15 @@ */ public String getOrigin() { return asSchemaElement().getOrigin(); return asServerSchemaElement().getOrigin(); } /** * Returns the attribute name of the wrapped element. * <p> * This corresponds to the attribute name in the schema entry that corresponds to the provided * schema element. * * @return the attribute name of the wrapped element. */ public String getAttributeName() opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -17,6 +17,7 @@ package org.opends.guitools.controlpanel.task; import static org.opends.messages.AdminToolMessages.*; import static org.opends.server.types.ExistingFileBehavior.*; import static org.opends.server.util.SchemaUtils.*; import java.io.File; @@ -53,7 +54,6 @@ import org.opends.server.core.DirectoryServer; import org.opends.server.types.Attributes; import org.opends.server.types.Entry; import org.opends.server.types.ExistingFileBehavior; import org.opends.server.types.LDIFExportConfig; import org.opends.server.types.LDIFImportConfig; import org.opends.server.types.Modification; @@ -61,7 +61,6 @@ import org.opends.server.types.Schema; import org.opends.server.util.LDIFReader; import org.opends.server.util.LDIFWriter; import org.opends.server.util.StaticUtils; /** The task that is launched when a schema element must be deleted. */ public class DeleteSchemaElementsTask extends Task @@ -280,7 +279,7 @@ { try { BasicAttribute attr = new BasicAttribute(getSchemaFileAttributeName(element)); BasicAttribute attr = new BasicAttribute(element.getAttributeName()); attr.add(getSchemaFileAttributeValue(element)); ModificationItem mod = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr); getInfo().getConnection().getLdapContext().modifyAttributes( @@ -316,38 +315,31 @@ * @param schemaElement the schema element to be deleted. * @throws OpenDsException if an error occurs. */ private void updateSchemaFile(SomeSchemaElement schemaElement) throws OpenDsException private void updateSchemaFile(SomeSchemaElement schemaElement) throws OpenDsException { String schemaFile = getSchemaFile(schemaElement); LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, ExistingFileBehavior.OVERWRITE); LDIFReader reader = null; LDIFWriter writer = null; try try (LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, OVERWRITE); LDIFReader reader = new LDIFReader(new LDIFImportConfig(schemaFile))) { reader = new LDIFReader(new LDIFImportConfig(schemaFile)); Entry schemaEntry = reader.readEntry(); Modification mod = new Modification(ModificationType.DELETE, Attributes.create( getSchemaFileAttributeName(schemaElement).toLowerCase(), schemaElement.getAttributeName(), getSchemaFileAttributeValue(schemaElement))); schemaEntry.applyModification(mod); writer = new LDIFWriter(exportConfig); try (LDIFWriter writer = new LDIFWriter(exportConfig)) { writer.writeEntry(schemaEntry); exportConfig.getWriter().newLine(); } } catch (IOException e) { throw new OfflineUpdateException( ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(e), e); } finally { StaticUtils.close(reader, exportConfig, writer); } } /** @@ -373,25 +365,6 @@ } /** * Returns the attribute name in the schema entry that corresponds to the * provided schema element. * @param element the schema element. * @return the attribute name in the schema entry that corresponds to the * provided schema element. */ private String getSchemaFileAttributeName(SomeSchemaElement element) { if (element.isAttributeType()) { return "attributeTypes"; } else { return "objectClasses"; } } /** * Returns the value in the schema file for the provided element. * @param element the schema element. * @return the value in the schema file for the provided element. @@ -409,25 +382,14 @@ private void printEquivalentCommandToDelete(SomeSchemaElement element) { String schemaFile = getSchemaFile(element); String attrName = getSchemaFileAttributeName(element); String attrName = element.getAttributeName(); String attrValue = getSchemaFileAttributeValue(element); String msg; if (!isServerRunning()) { LocalizableMessage msg; if (element.isAttributeType()) { msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_OFFLINE.get( element.getNameOrOID(), schemaFile); } else { msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_OFFLINE.get( element.getNameOrOID(), schemaFile); } getProgressDialog().appendProgressHtml(Utilities.applyFont( msg+"<br><b>"+ attrName+": "+attrValue+"</b><br><br>", ColorAndFontConstants.progressFont)); msg = getEquivalentCommandOfflineMsg(element, schemaFile) + "<br><b>" + attrName + ": " + attrValue + "</b><br><br>"; } else { @@ -436,33 +398,36 @@ args.addAll(getObfuscatedCommandLineArguments( getConnectionCommandLineArguments(true, true))); args.add(getNoPropertiesFileArgument()); String equiv = getEquivalentCommandLine(getCommandLinePath("ldapmodify"), args); String equiv = getEquivalentCommandLine(getCommandLinePath("ldapmodify"), args); LocalizableMessage msg; msg = getEquivalentCommandOnlineMsg(element) + "<br><b>" + equiv + "<br>" + "dn: cn=schema<br>" + "changetype: modify<br>" + "delete: " + attrName + "<br>" + attrName + ": " + attrValue + "</b>" + "<br><br>"; } getProgressDialog().appendProgressHtml(Utilities.applyFont(msg, ColorAndFontConstants.progressFont)); } private LocalizableMessage getEquivalentCommandOfflineMsg(SomeSchemaElement element, String schemaFile) { if (element.isAttributeType()) { msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_ONLINE.get( element.getNameOrOID()); return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_OFFLINE.get(element.getNameOrOID(), schemaFile); } else { msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_ONLINE.get( element.getNameOrOID()); return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_OFFLINE.get(element.getNameOrOID(), schemaFile); } StringBuilder sb = new StringBuilder(); sb.append(msg).append("<br><b>"); sb.append(equiv); sb.append("<br>"); sb.append("dn: cn=schema<br>"); sb.append("changetype: modify<br>"); sb.append("delete: ").append(attrName).append("<br>"); sb.append(attrName).append(": ").append(attrValue); sb.append("</b><br><br>"); getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), ColorAndFontConstants.progressFont)); private LocalizableMessage getEquivalentCommandOnlineMsg(SomeSchemaElement element) { if (element.isAttributeType()) { return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_ONLINE.get(element.getNameOrOID()); } return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_ONLINE.get(element.getNameOrOID()); } private AttributeType getAttributeToAdd(AttributeType attrToDelete) opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
@@ -16,6 +16,7 @@ */ package org.opends.guitools.controlpanel.task; import static org.forgerock.opendj.ldap.ModificationType.*; import static org.forgerock.util.Utils.*; import static org.opends.messages.AdminToolMessages.*; @@ -38,9 +39,9 @@ import javax.swing.SwingUtilities; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.ldap.ModificationType; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; @@ -48,6 +49,7 @@ import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.config.ConfigConstants; import org.opends.server.core.DirectoryServer; import org.opends.server.types.Attribute; import org.opends.server.types.Attributes; import org.opends.server.types.DirectoryException; import org.opends.server.types.Entry; @@ -55,7 +57,6 @@ import org.opends.server.types.LDIFExportConfig; import org.opends.server.types.LDIFImportConfig; import org.opends.server.types.Modification; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.opends.server.types.OpenDsException; import org.opends.server.util.LDIFReader; import org.opends.server.util.LDIFWriter; @@ -266,11 +267,7 @@ private List<SomeSchemaElement> get(Map<String, List<SomeSchemaElement>> hmElems, String fileName) { List<SomeSchemaElement> elems = hmElems.get(fileName); if (elems != null) { return elems; } return Collections.emptyList(); return elems != null ? elems : Collections.<SomeSchemaElement> emptyList(); } private Map<String, List<SomeSchemaElement>> copy(Set<SomeSchemaElement> elemsToAdd) @@ -746,9 +743,8 @@ { for (SomeSchemaElement schemaElement : schemaElements) { final Modification mod = new Modification(ModificationType.ADD, Attributes.create(schemaElement.getAttributeName().toLowerCase(), getValueOffline(schemaElement))); schemaEntry.applyModification(mod); Attribute attr = Attributes.create(schemaElement.getAttributeName(), getValueOffline(schemaElement)); schemaEntry.applyModification(new Modification(ADD, attr)); } } opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomAttributePanel.java
@@ -527,7 +527,7 @@ this.aliases.setText(Utilities.getStringFromCollection(someAliases, ", ")); SomeSchemaElement element = new SomeSchemaElement(attr); String sOrigin = Utilities.getOrigin(element); String sOrigin = element.getOrigin(); if (sOrigin == null) { sOrigin = ""; opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomObjectClassPanel.java
@@ -500,7 +500,7 @@ lastAliases.addAll(aliases); this.aliases.setText(Utilities.getStringFromCollection(aliases, ", ")); String sOrigin = Utilities.getOrigin(new SomeSchemaElement(oc)); String sOrigin = new SomeSchemaElement(oc).getOrigin(); if (sOrigin == null) { sOrigin = ""; opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java
@@ -243,7 +243,7 @@ { LocalizableMessageBuilder returnValue = new LocalizableMessageBuilder(); String fileName = element.getSchemaFile(); String xOrigin = Utilities.getOrigin(element); String xOrigin = element.getOrigin(); if (xOrigin != null) { returnValue.append(xOrigin); opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -41,6 +41,7 @@ import java.text.CharacterIterator; import java.text.StringCharacterIterator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Date; @@ -137,12 +138,12 @@ private static final String HTML_SPACE = " "; private static final String[] attrsToObfuscate = { ServerConstants.ATTR_USER_PASSWORD }; private static final String[] binarySyntaxOIDs = { private static final List<String> binarySyntaxOIDs = Arrays.asList( SchemaConstants.SYNTAX_BINARY_OID, SchemaConstants.SYNTAX_JPEG_OID, SchemaConstants.SYNTAX_CERTIFICATE_OID, SchemaConstants.SYNTAX_OCTET_STRING_OID }; ); private static ImageIcon warningIcon; private static ImageIcon requiredIcon; @@ -181,13 +182,13 @@ } /** * Returns <CODE>true</CODE> if an attribute value must be obfuscated because * it contains sensitive information (like passwords) and <CODE>false</CODE> * otherwise. * Returns whether an attribute value must be obfuscated because * it contains sensitive information (like passwords). * * @param attrName the attribute name. * @param schema the schema of the server. * @return <CODE>true</CODE> if an attribute value must be obfuscated because * it contains sensitive information (like passwords) and <CODE>false</CODE> * @return {@code true} if an attribute value must be obfuscated because * it contains sensitive information (like passwords) and {@code false} * otherwise. */ public static boolean mustObfuscate(String attrName, Schema schema) @@ -263,14 +264,13 @@ } /** * Displays a confirmation dialog. Returns <CODE>true</CODE> if the user * accepts the message and <CODE>false</CODE> otherwise. * Displays a confirmation dialog. * * @param parentComponent the parent component relative to which the dialog * will be displayed. * @param title the title of the dialog. * @param msg the message to be displayed. * @return <CODE>true</CODE> if the user accepts the message and * <CODE>false</CODE> otherwise. * @return {@code true} if the user accepts the message, {@code false} otherwise. */ public static boolean displayConfirmationDialog(Component parentComponent, LocalizableMessage title, LocalizableMessage msg) @@ -1445,12 +1445,11 @@ } /** * Returns <CODE>true</CODE> if the the provided strings represent the same * DN and <CODE>false</CODE> otherwise. * Returns whether the provided strings represent the same DN. * * @param dn1 the first dn to compare. * @param dn2 the second dn to compare. * @return <CODE>true</CODE> if the the provided strings represent the same * DN and <CODE>false</CODE> otherwise. * @return {@code true} if the provided strings represent the same DN, {@code false} otherwise. */ public static boolean areDnsEqual(String dn1, String dn2) { @@ -1866,11 +1865,11 @@ } /** * Returns <CODE>true</CODE> if the server located in the provided path * is running and <CODE>false</CODE> otherwise. * Returns whether the server located in the provided path is running. * * @param serverRootDirectory the path where the server is installed. * @return <CODE>true</CODE> if the server located in the provided path * is running and <CODE>false</CODE> otherwise. * @return {@code true} if the server located in the provided path is running, * {@code false} otherwise. */ public static boolean isServerRunning(File serverRootDirectory) { @@ -1898,11 +1897,11 @@ "abcdefghijklmnopqrstuvwxyz0123456789-"; /** * Returns <CODE>true</CODE> if the provided string can be used as objectclass * name and <CODE>false</CODE> otherwise. * Returns whether the provided string can be used as objectclass name. * * @param s the string to be analyzed. * @return <CODE>true</CODE> if the provided string can be used as objectclass * name and <CODE>false</CODE> otherwise. * @return {@code true} if the provided string can be used as objectclass name, * {@code false} otherwise. */ private static boolean isValidObjectclassName(String s) { @@ -1925,11 +1924,11 @@ } /** * Returns <CODE>true</CODE> if the provided string can be used as attribute * name and <CODE>false</CODE> otherwise. * Returns whether the provided string can be used as attribute name. * * @param s the string to be analyzed. * @return <CODE>true</CODE> if the provided string can be used as attribute * name and <CODE>false</CODE> otherwise. * @return {@code true} if the provided string can be used as attribute name, * {@code false} otherwise. */ public static boolean isValidAttributeName(String s) { @@ -1958,94 +1957,68 @@ return INFO_CTRL_PANEL_VLV_INDEX_CELL.get(index.getName()).toString(); } private static final String[] standardSchemaFileNames = { private static final List<String> standardSchemaFileNames = Arrays.asList( "00-core.ldif", "01-pwpolicy.ldif", "03-changelog.ldif", "03-uddiv3.ldif", "05-solaris.ldif" }; ); private static final String[] configurationSchemaOrigins = { private static final List<String> configurationSchemaOrigins = Arrays.asList( "OpenDJ Directory Server", "OpenDS Directory Server", "Sun Directory Server", "Microsoft Active Directory" }; ); private static final String[] standardSchemaOrigins = { private static final List<String> standardSchemaOrigins = Arrays.asList( "Sun Java System Directory Server", "Solaris Specific", "X.501" }; ); private static final String[] configurationSchemaFileNames = { private static final List<String> configurationSchemaFileNames = Arrays.asList( "02-config.ldif", "06-compat.ldif" }; ); /** * Returns <CODE>true</CODE> if the provided schema element is part of the * standard and <CODE>false</CODE> otherwise. * Returns whether the provided schema element is part of the standard. * * @param fileElement the schema element. * @return <CODE>true</CODE> if the provided schema element is part of the * standard and <CODE>false</CODE> otherwise. * @return {@code true} if the provided schema element is part of the standard, * {@code false} otherwise. */ public static boolean isStandard(SomeSchemaElement fileElement) { final String fileName = fileElement.getSchemaFile(); if (fileName != null) { return contains(standardSchemaFileNames, fileName) || fileName.toLowerCase().contains("-rfc"); return standardSchemaFileNames.contains(fileName) || fileName.toLowerCase().contains("-rfc"); } String xOrigin = getOrigin(fileElement); String xOrigin = fileElement.getOrigin(); if (xOrigin != null) { return contains(standardSchemaOrigins, xOrigin) || xOrigin.startsWith("RFC ") || xOrigin.startsWith("draft-"); return standardSchemaOrigins.contains(xOrigin) || xOrigin.startsWith("RFC ") || xOrigin.startsWith("draft-"); } return false; } /** * Returns <CODE>true</CODE> if the provided schema element is part of the * configuration and <CODE>false</CODE> otherwise. * Returns whether the provided schema element is part of the configuration. * * @param fileElement the schema element. * @return <CODE>true</CODE> if the provided schema element is part of the * configuration and <CODE>false</CODE> otherwise. * @return {@code true} if the provided schema element is part of the configuration, * {@code false} otherwise. */ public static boolean isConfiguration(SomeSchemaElement fileElement) { String fileName = fileElement.getSchemaFile(); if (fileName != null) { return contains(configurationSchemaFileNames, fileName); return configurationSchemaFileNames.contains(fileName); } String xOrigin = getOrigin(fileElement); String xOrigin = fileElement.getOrigin(); if (xOrigin != null) { return contains(configurationSchemaOrigins, xOrigin); return configurationSchemaOrigins.contains(xOrigin); } return false; } private static boolean contains(String[] names, String toFind) { for (String name : names) { if (toFind.equals(name)) { return true; } } return false; } /** * Returns the origin of the provided schema element. * @param element the schema element. * @return the origin of the provided schema element. */ public static String getOrigin(SomeSchemaElement element) { return element.getOrigin(); } /** * Returns the string representation of an attribute syntax. * @param syntax the attribute syntax. @@ -2063,12 +2036,11 @@ } /** * Returns <CODE>true</CODE> if the provided attribute has image syntax and * <CODE>false</CODE> otherwise. * Returns whether the provided attribute has image syntax. * * @param attrName the name of the attribute. * @param schema the schema. * @return <CODE>true</CODE> if the provided attribute has image syntax and * <CODE>false</CODE> otherwise. * @return {@code true} if the provided attribute has image syntax, {@code false} otherwise. */ public static boolean hasImageSyntax(String attrName, Schema schema) { @@ -2090,12 +2062,11 @@ } /** * Returns <CODE>true</CODE> if the provided attribute has binary syntax and * <CODE>false</CODE> otherwise. * Returns whether the provided attribute has binary syntax. * * @param attrName the name of the attribute. * @param schema the schema. * @return <CODE>true</CODE> if the provided attribute has binary syntax and * <CODE>false</CODE> otherwise. * @return {@code true} if the provided attribute has binary syntax, {@code false} otherwise. */ public static boolean hasBinarySyntax(String attrName, Schema schema) { @@ -2104,12 +2075,11 @@ } /** * Returns <CODE>true</CODE> if the provided attribute has password syntax and * <CODE>false</CODE> otherwise. * Returns whether the provided attribute has password syntax. * * @param attrName the name of the attribute. * @param schema the schema. * @return <CODE>true</CODE> if the provided attribute has password syntax and * <CODE>false</CODE> otherwise. * @return {@code true} if the provided attribute has password syntax, {@code false} otherwise. */ public static boolean hasPasswordSyntax(String attrName, Schema schema) { @@ -2125,14 +2095,14 @@ return false; } private static boolean hasAnySyntax(String attrName, Schema schema, String[] oids) private static boolean hasAnySyntax(String attrName, Schema schema, List<String> oids) { if (schema != null) { AttributeType attrType = AttributeDescription.valueOf(attrName, schema.getSchemaNG()).getAttributeType(); if (!attrType.isPlaceHolder()) { return contains(oids, attrType.getSyntax().getOID()); return oids.contains(attrType.getSyntax().getOID()); } } return false; @@ -2537,12 +2507,12 @@ } /** * Returns <CODE>true</CODE> if the provided monitoring value represents the * non implemented label and <CODE>false</CODE> otherwise. * Returns whether the provided monitoring value represents the non implemented label. * * @param attr the attribute to analyze. * @param monitoringEntry the monitoring entry. * @return <CODE>true</CODE> if the provided monitoring value represents the * non implemented label and <CODE>false</CODE> otherwise. * @return {@code true} if the provided monitoring value represents the non implemented label, * {@code false} otherwise. */ private static boolean isNotImplemented(MonitoringAttributes attr, CustomSearchResult monitoringEntry)