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

jvergara
14.24.2009 70df53f05e4cc8615f2ef13a739f085c706a3ccb
Fix for issue 4283 (No way to add operational attribute to an entry)

The problem was that the code had a hardcoded list of editable operational attributes. The code has been modified to calculate this list from the schema contents.

The code has also been updated to use some special Strings ("1.1" and "+") to request no attributes and operational attributes.

Some generics have been used to avoid some warnings reported by my IDE.
12 files modified
146 ■■■■■ changed files
opends/src/ads/org/opends/admin/ads/ServerDescriptor.java 2 ●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java 2 ●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/browser/NodeRefresher.java 4 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java 2 ●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseEntriesPanel.java 3 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java 12 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java 2 ●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java 61 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/util/LDAPEntryReader.java 45 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java 4 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java 4 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/Utilities.java 5 ●●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -1341,7 +1341,7 @@
    {
      SearchControls sc = new SearchControls();
      sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      String[] attList = {"dn"};
      String[] attList = {"1.1"};
      sc.setReturningAttributes(attList);
      NamingEnumeration<SearchResult> ne = ctx.search(TRUSTSTORE_DN,
          "(objectclass=ds-cfg-instance-key)", sc);
opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
@@ -627,7 +627,7 @@
      searchControls.setSearchScope(
          SearchControls. OBJECT_SCOPE);
      searchControls.setReturningAttributes(
          new String[] {"dn"});
          new String[] {"1.1"});
      ctx.search("cn=config", "objectclass=*", searchControls);
      connectedAsAdministrativeUser = true;
opends/src/guitools/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -340,7 +340,7 @@
  {
    SearchControls ctls = controller.getBasicSearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctls.setReturningAttributes(new String[]{"dn"});
    ctls.setReturningAttributes(new String[]{"1.1"});
    ctls.setCountLimit(1);
    NamingEnumeration<SearchResult> s = ctx.search(new LdapName(node.getDN()),
              controller.getFilter(),
@@ -586,7 +586,7 @@
      // It's enough to know if the entry has children or not.
      SearchControls ctls = controller.getBasicSearchControls();
      ctls.setCountLimit(1);
      String[] attrs = {"dn"};
      String[] attrs = {"1.1"};
      ctls.setReturningAttributes(attrs);
      if (useCustomFilter())
      {
opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
@@ -363,7 +363,7 @@
      ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      String filter =
        "(|(objectClass=*)(objectclass=ldapsubentry))";
      ctls.setReturningAttributes(new String[] {"dn"});
      ctls.setReturningAttributes(new String[] {"1.1"});
      NamingEnumeration<SearchResult> entryDNs =
        ctx.search(Utilities.getJNDIName(dnToRemove.toString()), filter, ctls);
opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseEntriesPanel.java
@@ -511,8 +511,7 @@
      {
        InitialLdapContext ctx =
          controller.findConnectionForDisplayedEntry(node);
        Schema schema = getInfo().getServerDescriptor().getSchema();
        LDAPEntryReader reader = new LDAPEntryReader(dn, ctx, schema);
        LDAPEntryReader reader = new LDAPEntryReader(dn, ctx);
        reader.addEntryReadListener(entryPane);
        cleanupReaderQueue();
        // Required to update the browser controller properly if the entry is
opends/src/guitools/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
@@ -1401,9 +1401,9 @@
          }
          values.addAll(ocValue.getAuxiliary());
        }
        else if (value instanceof Collection)
        else if (value instanceof Collection<?>)
        {
          for (Object o : (Collection)value)
          for (Object o : (Collection<?>)value)
          {
            values.add((String)o);
          }
@@ -1559,9 +1559,9 @@
        if (hasValue(comp))
        {
          Object value = comp.getValue();
          if (value instanceof Collection)
          if (value instanceof Collection<?>)
          {
            for (Object o : (Collection)value)
            for (Object o : (Collection<?>)value)
            {
              values.add(o);
            }
@@ -1930,9 +1930,9 @@
      {
        hasValue = ((String)value).trim().length() > 0;
      }
      else if (value instanceof Collection)
      else if (value instanceof Collection<?>)
      {
        hasValue = ((Collection)value).size() > 0;
        hasValue = ((Collection<?>)value).size() > 0;
      }
      else
      {
opends/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -2063,7 +2063,7 @@
      ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
      ctls.setReturningAttributes(
          new String[] {
              "dn"
              "1.1"
          });
      String filter = BrowserController.ALL_OBJECTS_FILTER;
      NamingEnumeration<SearchResult> result =
opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -53,7 +53,6 @@
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.messages.Message;
import org.opends.server.api.AttributeSyntax;
import org.opends.server.config.ConfigConstants;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
@@ -74,6 +73,7 @@
 */
public abstract class ViewEntryPanel extends StatusGenericPanel
{
  private static final long serialVersionUID = -1908757626234678L;
  /**
   * The read-only attributes as they appear on the schema.
   */
@@ -83,6 +83,11 @@
   */
  protected SortedSet<String> schemaReadOnlyAttributesLowerCase =
    new TreeSet<String>();
  /**
   * The editable operational attributes.
   */
  protected SortedSet<String> editableOperationalAttrNames =
    new TreeSet<String>();
  private JLabel title= Utilities.createDefaultLabel();
  private Set<LDAPEntryChangedListener> listeners =
@@ -390,20 +395,21 @@
  public void configurationChanged(ConfigurationChangeEvent ev)
  {
    Schema schema = ev.getNewDescriptor().getSchema();
    if (schema != null)
    if (schema != null && schemaReadOnlyAttributes.isEmpty())
    {
      schemaReadOnlyAttributes.clear();
      schemaReadOnlyAttributesLowerCase.clear();
      for (AttributeType attr : schema.getAttributeTypes().values())
      {
        if (attr.isOperational())
        if (attr.isNoUserModification())
        {
          String attrName = attr.getNameOrOID();
          if (!isEditable(attrName, schema))
          {
            schemaReadOnlyAttributes.add(attrName);
            schemaReadOnlyAttributesLowerCase.add(attrName.toLowerCase());
          }
          schemaReadOnlyAttributes.add(attrName);
          schemaReadOnlyAttributesLowerCase.add(attrName.toLowerCase());
        }
        else if (attr.isOperational())
        {
          editableOperationalAttrNames.add(attr.getNameOrOID());
        }
      }
    }
@@ -535,7 +541,7 @@
          Utilities.getAttributeNameWithoutOptions(attrName).toLowerCase());
      if (attr != null)
      {
        AttributeSyntax syntax = attr.getSyntax();
        AttributeSyntax<?> syntax = attr.getSyntax();
        if (syntax != null)
        {
          isCertificate = syntax.getOID().equals(
@@ -546,37 +552,6 @@
    return isCertificate;
  }
  static String[] editableOperationalAttrNames = {
      ConfigConstants.ATTR_OBJECTCLASSES,
      ConfigConstants.ATTR_ATTRIBUTE_TYPES,
      ConfigConstants.ATTR_MATCHING_RULES,
      ConfigConstants.ATTR_NAME_FORMS,
      ConfigConstants.ATTR_LDAP_SYNTAXES,
      ConfigConstants.ATTR_DIT_STRUCTURE_RULES,
      "aci"
  };
  /**
   * Returns <CODE>true</CODE> if the provided attribute name is an editable
   * operational attribute and <CODE>false</CODE> otherwise.
   * @param attrName the attribute name.
   * @return <CODE>true</CODE> if the provided attribute name is an editable
   * operational attribute and <CODE>false</CODE> otherwise.
   */
  private static boolean isEditableOperationalAttribute(String attrName)
  {
    boolean isEditableOperationalAttribute = false;
    for (String attr : editableOperationalAttrNames)
    {
      if (attr.equalsIgnoreCase(attrName))
      {
        isEditableOperationalAttribute = true;
        break;
      }
    }
    return isEditableOperationalAttribute;
  }
  /**
   * Gets the values associated with a given attribute.  The values are the
   * ones displayed in the panel.
@@ -645,16 +620,16 @@
   */
  public static boolean isEditable(String attrName, Schema schema)
  {
    boolean isOperational = false;
    boolean isEditable = false;
    attrName = Utilities.getAttributeNameWithoutOptions(attrName);
    if (schema != null)
    {
      AttributeType attrType = schema.getAttributeType(attrName.toLowerCase());
      if (attrType != null)
      {
        isOperational = attrType.isOperational();
        isEditable = !attrType.isNoUserModification();
      }
    }
    return !isOperational || isEditableOperationalAttribute(attrName);
    return isEditable;
  }
}
opends/src/guitools/org/opends/guitools/controlpanel/util/LDAPEntryReader.java
@@ -22,13 +22,12 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.util;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.naming.NamingEnumeration;
@@ -40,8 +39,6 @@
import org.opends.guitools.controlpanel.event.EntryReadErrorEvent;
import org.opends.guitools.controlpanel.event.EntryReadEvent;
import org.opends.guitools.controlpanel.event.EntryReadListener;
import org.opends.server.types.AttributeType;
import org.opends.server.types.Schema;
/**
 * A class that reads an entry on the background.  This is used in the LDAP
@@ -53,7 +50,6 @@
{
  private String dn;
  private InitialLdapContext ctx;
  private Schema schema;
  private Set<EntryReadListener> listeners = new HashSet<EntryReadListener>();
  private boolean isOver;
@@ -61,13 +57,11 @@
   * Constructor of the entry reader.
   * @param dn the DN of the entry.
   * @param ctx the connection to the server.
   * @param schema the schema of the server.
   */
  public LDAPEntryReader(String dn, InitialLdapContext ctx, Schema schema)
  public LDAPEntryReader(String dn, InitialLdapContext ctx)
  {
    this.dn = dn;
    this.ctx = ctx;
    this.schema = schema;
  }
  /**
@@ -80,25 +74,16 @@
    {
      SearchControls controls = new SearchControls();
      controls.setCountLimit(1);
      Set<String> operational = getAllOperationalAttributes();
      String[] attrs = new String[operational.size()+1];
      Iterator<String> it = operational.iterator();
      int i = 0;
      while (it.hasNext())
      {
        attrs[i] = it.next();
        i++;
      }
      attrs[attrs.length - 1] = "*";
      String[] attrs = {"*", "+"};
      controls.setReturningAttributes(attrs);
      controls.setSearchScope(SearchControls.OBJECT_SCOPE);
      final String filter = "(|(objectclass=*)(objectclass=ldapsubentry))";
      NamingEnumeration en = ctx.search(Utilities.getJNDIName(dn), filter,
          controls);
      NamingEnumeration<SearchResult> en =
        ctx.search(Utilities.getJNDIName(dn), filter, controls);
      SearchResult sr = (SearchResult)en.next();
      SearchResult sr = en.next();
      return new CustomSearchResult(sr, dn);
    }
@@ -185,22 +170,4 @@
  {
    listeners.remove(listener);
  }
  private Set<String> getAllOperationalAttributes()
  {
    HashSet<String> attrs = new HashSet<String>();
    // Do a best effort if schema could not be retrieved when creating
    // this object.
    if (schema != null)
    {
      for (AttributeType attr : schema.getAttributeTypes().values())
      {
        if (attr.isOperational())
        {
          attrs.add(attr.getNameOrOID());
        }
      }
    }
    return attrs;
  }
}
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -1905,7 +1905,7 @@
   * @param syntax the attribute syntax.
   * @return the string representation of an attribute syntax.
   */
  public static String getSyntaxText(AttributeSyntax syntax)
  public static String getSyntaxText(AttributeSyntax<?> syntax)
  {
    String returnValue;
    String syntaxName = syntax.getSyntaxName();
@@ -2163,7 +2163,7 @@
    searchControls.setSearchScope(
    SearchControls. OBJECT_SCOPE);
    searchControls.setReturningAttributes(
    new String[] {"dn"});
    new String[] {"1.1"});
    ctx.search("cn=config", "objectclass=*", searchControls);
  }
opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 */
package org.opends.quicksetup.ui;
@@ -351,7 +351,7 @@
          searchControls.setSearchScope(
          SearchControls. OBJECT_SCOPE);
          searchControls.setReturningAttributes(
          new String[] {"dn"});
          new String[] {"1.1"});
          ctx.search("cn=config", "objectclass=*", searchControls);
        } catch (NamingException ne)
opends/src/quicksetup/org/opends/quicksetup/ui/Utilities.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 */
package org.opends.quicksetup.ui;
@@ -84,7 +84,8 @@
   *
   * @param frame for which the icon will be set
   */
  static public void setFrameIcon(JFrame frame) {
  static public void setFrameIcon(JFrame frame)
  {
    UIFactory.IconType ic;
    if (Utils.isMacOS()) {
      ic = UIFactory.IconType.MINIMIZED_MAC;