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

Jean-Noel Rouvignac
18.17.2015 10013982073031602d1af2ecffd30110a21870f5
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
@@ -30,18 +30,15 @@
import static org.opends.messages.QuickSetupMessages.*;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
import javax.naming.NameAlreadyBoundException;
@@ -50,26 +47,27 @@
import javax.naming.NamingException;
import javax.naming.NoPermissionException;
import javax.naming.NotContextException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchResult;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.Control;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.naming.ldap.Control;
import javax.naming.ldap.LdapContext;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.admin.ads.ADSContextException.ErrorType;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.quicksetup.Constants;
import org.opends.server.schema.SchemaConstants;
/**
 * Class used to update and read the contents of the Administration Data.
 */
/** Class used to update and read the contents of the Administration Data. */
public class ADSContext
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -82,13 +80,10 @@
  {
    /** String syntax. */
    STRING,
    /** Integer syntax. */
    INTEGER,
    /** Boolean syntax. */
    BOOLEAN,
    /** Certificate;binary syntax. */
    CERTIFICATE_BINARY
  }
@@ -97,65 +92,45 @@
  public enum ServerProperty
  {
    /** The ID used to identify the server. */
    ID("id", ADSPropertySyntax.STRING),
    ID("id",ADSPropertySyntax.STRING),
    /** The host name of the server. */
    HOST_NAME("hostname", ADSPropertySyntax.STRING),
    HOST_NAME("hostname",ADSPropertySyntax.STRING),
    /** The LDAP port of the server. */
    LDAP_PORT("ldapport", ADSPropertySyntax.INTEGER),
    LDAP_PORT("ldapport",ADSPropertySyntax.INTEGER),
    /** The JMX port of the server. */
    JMX_PORT("jmxport", ADSPropertySyntax.INTEGER),
    JMX_PORT("jmxport",ADSPropertySyntax.INTEGER),
    /** The JMX secure port of the server. */
    JMXS_PORT("jmxsport", ADSPropertySyntax.INTEGER),
    JMXS_PORT("jmxsport",ADSPropertySyntax.INTEGER),
    /** The LDAPS port of the server. */
    LDAPS_PORT("ldapsport", ADSPropertySyntax.INTEGER),
    LDAPS_PORT("ldapsport",ADSPropertySyntax.INTEGER),
    /** The administration connector port of the server. */
    ADMIN_PORT("adminport", ADSPropertySyntax.INTEGER),
    ADMIN_PORT("adminport",ADSPropertySyntax.INTEGER),
    /** The certificate used by the server. */
    CERTIFICATE("certificate", ADSPropertySyntax.STRING),
    CERTIFICATE("certificate",ADSPropertySyntax.STRING),
    /** The path where the server is installed. */
    INSTANCE_PATH("instancepath", ADSPropertySyntax.STRING),
    INSTANCE_PATH("instancepath",ADSPropertySyntax.STRING),
    /** The description of the server. */
    DESCRIPTION("description", ADSPropertySyntax.STRING),
    DESCRIPTION("description",ADSPropertySyntax.STRING),
    /** The OS of the machine where the server is installed. */
    HOST_OS("os", ADSPropertySyntax.STRING),
    HOST_OS("os",ADSPropertySyntax.STRING),
    /** Whether LDAP is enabled or not. */
    LDAP_ENABLED("ldapEnabled", ADSPropertySyntax.BOOLEAN),
    LDAP_ENABLED("ldapEnabled",ADSPropertySyntax.BOOLEAN),
    /** Whether LDAPS is enabled or not. */
    LDAPS_ENABLED("ldapsEnabled", ADSPropertySyntax.BOOLEAN),
    LDAPS_ENABLED("ldapsEnabled",ADSPropertySyntax.BOOLEAN),
    /** Whether ADMIN is enabled or not. */
    ADMIN_ENABLED("adminEnabled", ADSPropertySyntax.BOOLEAN),
    ADMIN_ENABLED("adminEnabled",ADSPropertySyntax.BOOLEAN),
    /** Whether StartTLS is enabled or not. */
    STARTTLS_ENABLED("startTLSEnabled", ADSPropertySyntax.BOOLEAN),
    STARTTLS_ENABLED("startTLSEnabled",ADSPropertySyntax.BOOLEAN),
    /** Whether JMX is enabled or not. */
    JMX_ENABLED("jmxEnabled", ADSPropertySyntax.BOOLEAN),
    JMX_ENABLED("jmxEnabled",ADSPropertySyntax.BOOLEAN),
    /** Whether JMX is enabled or not. */
    JMXS_ENABLED("jmxsEnabled", ADSPropertySyntax.BOOLEAN),
    JMXS_ENABLED("jmxsEnabled",ADSPropertySyntax.BOOLEAN),
    /** The location of the server. */
    LOCATION("location", ADSPropertySyntax.STRING),
    LOCATION("location",ADSPropertySyntax.STRING),
    /** The groups to which this server belongs. */
    GROUPS("memberofgroups", ADSPropertySyntax.STRING),
    GROUPS("memberofgroups",ADSPropertySyntax.STRING),
    /** The unique name of the instance key public-key certificate. */
    INSTANCE_KEY_ID("ds-cfg-key-id", ADSPropertySyntax.STRING),
    INSTANCE_KEY_ID("ds-cfg-key-id",ADSPropertySyntax.STRING),
    /**
     * The instance key-pair public-key certificate. Note: This attribute
     * belongs to an instance key entry, separate from the server entry and
@@ -227,37 +202,24 @@
    return NAME_TO_SERVER_PROPERTY.get(name);
  }
  /**
   * The list of server properties that are multivalued.
   */
  /** The list of server properties that are multivalued. */
  private static final Set<ServerProperty> MULTIVALUED_SERVER_PROPERTIES = new HashSet<>();
  static
  {
    MULTIVALUED_SERVER_PROPERTIES.add(ServerProperty.GROUPS);
  }
  /**
   * The default server group which will contain all registered servers.
   */
  /** The default server group which will contain all registered servers. */
  public static final String ALL_SERVERGROUP_NAME = "all-servers";
  /**
   * Enumeration containing the different server group properties that are
   * stored in the ADS.
   */
  /** Enumeration containing the different server group properties that are stored in the ADS. */
  public enum ServerGroupProperty
  {
    /**
     * The UID of the server group.
     */
    /** The UID of the server group. */
    UID("cn"),
    /**
     * The description of the server group.
     */
    /** The description of the server group. */
    DESCRIPTION("description"),
    /**
     * The members of the server group.
     */
    /** The members of the server group. */
    MEMBERS("uniqueMember");
    private String attrName;
@@ -284,39 +246,25 @@
    }
  }
  /**
   * The list of server group properties that are multivalued.
   */
  /** The list of server group properties that are multivalued. */
  private static final Set<ServerGroupProperty> MULTIVALUED_SERVER_GROUP_PROPERTIES = new HashSet<>();
  static
  {
    MULTIVALUED_SERVER_GROUP_PROPERTIES.add(ServerGroupProperty.MEMBERS);
  }
  /**
   * The enumeration containing the different Administrator properties.
   */
  /** The enumeration containing the different Administrator properties. */
  public enum AdministratorProperty
  {
    /**
     * The UID of the administrator.
     */
    /** The UID of the administrator. */
    UID("id", ADSPropertySyntax.STRING),
    /**
     * The password of the administrator.
     */
    /** The password of the administrator. */
    PASSWORD("password", ADSPropertySyntax.STRING),
    /**
     * The description of the administrator.
     */
    /** The description of the administrator. */
    DESCRIPTION("description", ADSPropertySyntax.STRING),
    /**
     * The DN of the administrator.
     */
    /** The DN of the administrator. */
    ADMINISTRATOR_DN("administrator dn", ADSPropertySyntax.STRING),
    /**
     * The administrator privilege.
     */
    /** The administrator privilege. */
    PRIVILEGE("privilege", ADSPropertySyntax.STRING);
    private String attrName;
@@ -449,7 +397,7 @@
      Set<String> groupList = new HashSet<>();
      if (rawGroupList != null)
      {
        for (Object elm : rawGroupList.toArray())
        for (Object elm : rawGroupList)
        {
          groupList.add(elm.toString());
        }
@@ -457,7 +405,6 @@
      groupList.add(ALL_SERVERGROUP_NAME);
      serverProperties.put(ServerProperty.GROUPS, groupList);
      updateServer(serverProperties, null);
    }
    catch (ADSContextException ace)
    {
@@ -465,11 +412,11 @@
    }
    catch (NameAlreadyBoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED);
      throw new ADSContextException(ErrorType.ALREADY_REGISTERED);
    }
    catch (Exception x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -511,11 +458,11 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED);
      throw new ADSContextException(ErrorType.NOT_YET_REGISTERED);
    }
    catch (Exception x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -553,11 +500,11 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED);
      throw new ADSContextException(ErrorType.NOT_YET_REGISTERED);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    // Unregister the server in server groups
@@ -626,15 +573,15 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL);
      throw new ADSContextException(ErrorType.BROKEN_INSTALL);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -693,7 +640,7 @@
    }
    catch (ADSContextException x)
    {
      if (x.getError() == ADSContextException.ErrorType.ALREADY_REGISTERED)
      if (x.getError() == ErrorType.ALREADY_REGISTERED)
      {
        updateServer(serverProperties, null);
        return 1;
@@ -763,11 +710,11 @@
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -837,15 +784,15 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL);
      throw new ADSContextException(ErrorType.BROKEN_INSTALL);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -879,11 +826,11 @@
    }
    catch (NameAlreadyBoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED);
      throw new ADSContextException(ErrorType.ALREADY_REGISTERED);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL, x);
      throw new ADSContextException(ErrorType.BROKEN_INSTALL, x);
    }
  }
@@ -929,15 +876,15 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED);
      throw new ADSContextException(ErrorType.NOT_YET_REGISTERED);
    }
    catch (NameAlreadyBoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED);
      throw new ADSContextException(ErrorType.ALREADY_REGISTERED);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -954,7 +901,6 @@
  public void removeServerGroupProp(String groupID, Set<ServerGroupProperty> serverGroupProperties)
      throws ADSContextException
  {
    LdapName dn = nameFromDN("cn=" + Rdn.escapeValue(groupID) + "," + getServerGroupContainerDN());
    BasicAttributes attrs = makeAttrsFromServerGroupProperties(serverGroupProperties);
    try
@@ -963,11 +909,11 @@
    }
    catch (NameAlreadyBoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED);
      throw new ADSContextException(ErrorType.ALREADY_REGISTERED);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -988,7 +934,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -1018,15 +964,15 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL);
      throw new ADSContextException(ErrorType.BROKEN_INSTALL);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -1064,15 +1010,15 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL);
      throw new ADSContextException(ErrorType.BROKEN_INSTALL);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -1192,7 +1138,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -1249,15 +1195,15 @@
    }
    catch (NameAlreadyBoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED);
      throw new ADSContextException(ErrorType.ALREADY_REGISTERED);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -1271,28 +1217,23 @@
   */
  public void deleteAdministrator(Map<AdministratorProperty, Object> adminProperties) throws ADSContextException
  {
    LdapName dnCentralAdmin = makeDNFromAdministratorProperties(adminProperties);
    try
    {
      dirContext.destroySubcontext(dnCentralAdmin);
    }
    catch (NameNotFoundException x)
    catch (NameNotFoundException | NotContextException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED);
    }
    catch (NotContextException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED);
      throw new ADSContextException(ErrorType.NOT_YET_REGISTERED);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -1309,7 +1250,6 @@
  public void updateAdministrator(Map<AdministratorProperty, Object> adminProperties, String newAdminUserId)
      throws ADSContextException
  {
    LdapName dnCentralAdmin = makeDNFromAdministratorProperties(adminProperties);
    boolean updatePassword = adminProperties.containsKey(AdministratorProperty.PASSWORD);
@@ -1360,15 +1300,15 @@
    }
    catch (NameNotFoundException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED);
      throw new ADSContextException(ErrorType.NOT_YET_REGISTERED);
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -1437,7 +1377,7 @@
    String serverGroupId = (String) serverGroupProperties.get(ServerGroupProperty.UID);
    if (serverGroupId == null)
    {
      throw new ADSContextException(ADSContextException.ErrorType.MISSING_NAME);
      throw new ADSContextException(ErrorType.MISSING_NAME);
    }
    return nameFromDN("cn=" + Rdn.escapeValue(serverGroupId) + "," + getServerGroupContainerDN());
  }
@@ -1819,7 +1759,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    return result;
  }
@@ -1894,7 +1834,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    return result;
  }
@@ -1959,7 +1899,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    finally
    {
@@ -2023,11 +1963,11 @@
    String result = (String) serverProperties.get(ServerProperty.HOST_NAME);
    if (result == null)
    {
      throw new ADSContextException(ADSContextException.ErrorType.MISSING_HOSTNAME);
      throw new ADSContextException(ErrorType.MISSING_HOSTNAME);
    }
    else if (result.length() == 0)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOVALID_HOSTNAME);
      throw new ADSContextException(ErrorType.NOVALID_HOSTNAME);
    }
    return result;
  }
@@ -2063,11 +2003,11 @@
    String result = (String) serverProperties.get(ServerProperty.INSTANCE_PATH);
    if (result == null)
    {
      throw new ADSContextException(ADSContextException.ErrorType.MISSING_IPATH);
      throw new ADSContextException(ErrorType.MISSING_IPATH);
    }
    else if (result.length() == 0)
    {
      throw new ADSContextException(ADSContextException.ErrorType.NOVALID_IPATH);
      throw new ADSContextException(ErrorType.NOVALID_IPATH);
    }
    return result;
  }
@@ -2087,7 +2027,7 @@
    String result = (String) adminProperties.get(AdministratorProperty.UID);
    if (result == null)
    {
      throw new ADSContextException(ADSContextException.ErrorType.MISSING_ADMIN_UID);
      throw new ADSContextException(ErrorType.MISSING_ADMIN_UID);
    }
    return result;
  }
@@ -2107,7 +2047,7 @@
    String result = (String) adminProperties.get(AdministratorProperty.PASSWORD);
    if (result == null)
    {
      throw new ADSContextException(ADSContextException.ErrorType.MISSING_ADMIN_PASSWORD);
      throw new ADSContextException(ErrorType.MISSING_ADMIN_PASSWORD);
    }
    return result;
  }
@@ -2131,7 +2071,7 @@
    catch (InvalidNameException x)
    {
      logger.error(LocalizableMessage.raw("Error parsing dn " + dn, x));
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -2155,7 +2095,7 @@
    catch (InvalidNameException x)
    {
      logger.error(LocalizableMessage.raw("Error parsing rdn " + rdnName, x));
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -2171,8 +2111,6 @@
   */
  private boolean isExistingEntry(LdapName dn) throws ADSContextException
  {
    boolean result;
    try
    {
      SearchControls sc = new SearchControls();
@@ -2180,7 +2118,7 @@
      sc.setSearchScope(SearchControls.OBJECT_SCOPE);
      sc.setReturningAttributes(new String[] { SchemaConstants.NO_ATTRIBUTES });
      NamingEnumeration<SearchResult> sr = getDirContext().search(dn, "(objectclass=*)", sc);
      result = false;
      boolean result = false;
      try
      {
        while (sr.hasMore())
@@ -2193,21 +2131,20 @@
      {
        sr.close();
      }
      return result;
    }
    catch (NameNotFoundException x)
    {
      result = false;
      return false;
    }
    catch (NoPermissionException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION);
      throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
    }
    catch (javax.naming.NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    return result;
  }
  /**
@@ -2280,7 +2217,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
  }
@@ -2306,19 +2243,6 @@
  }
  /**
   * Removes the administration suffix.
   *
   * @throws ADSContextException
   *           if something goes wrong.
   */
  //private void removeAdministrationSuffix() throws ADSContextException
  //{
  //ADSContextHelper helper = new ADSContextHelper();
  //helper.removeAdministrationSuffix(getDirContext(),
  //getDefaultBackendName());
  //}
  /**
   * Returns the default backend name of the administration data.
   *
   * @return the default backend name of the administration data.
@@ -2372,17 +2296,15 @@
   */
  public static boolean isRegistered(ServerDescriptor server, Set<Map<ADSContext.ServerProperty, Object>> registry)
  {
    boolean isRegistered = false;
    for (Map<ADSContext.ServerProperty, Object> s : registry)
    {
      ServerDescriptor servInRegistry = ServerDescriptor.createStandalone(s);
      if (servInRegistry.getId().equals(server.getId()))
      {
        isRegistered = true;
        break;
        return true;
      }
    }
    return isRegistered;
    return false;
  }
  /**
@@ -2411,26 +2333,6 @@
  }
  /**
   * Unregister instance key-pair public-key certificate provided in
   * serverProperties..
   *
   * @param serverProperties
   *          Properties of the server being unregistered to which the instance
   *          key entry belongs.
   * @param serverEntryDn
   *          The server's ADS entry DN.
   * @throws NamingException
   *           In case some JNDI operation fails.
   */
  @SuppressWarnings("unused")
  private void unregisterInstanceKeyCertificate(Map<ServerProperty, Object> serverProperties, LdapName serverEntryDn)
      throws ADSContextException
  {
    ADSContextHelper helper = new ADSContextHelper();
    helper.unregisterInstanceKeyCertificate(dirContext, serverProperties, serverEntryDn);
  }
  /**
   * Return the set of valid (i.e., not tagged as compromised) instance key-pair
   * public-key certificate entries in ADS. NOTE: calling this method assumes
   * that all the jar files are present in the classpath.
@@ -2490,7 +2392,7 @@
    }
    catch (NamingException x)
    {
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
    }
    return certificateMap;
  }
@@ -2508,20 +2410,15 @@
  {
    try
    {
      // Merge administrators.
      mergeAdministrators(adsCtx);
      // Merge groups.
      mergeServerGroups(adsCtx);
      // Merge servers.
      mergeServers(adsCtx);
    }
    catch (ADSContextException adce)
    {
      LocalizableMessage msg = ERR_ADS_MERGE.get(ConnectionUtils.getHostPort(getDirContext()),
          ConnectionUtils.getHostPort(adsCtx.getDirContext()), adce.getMessageObject());
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_MERGING, msg, adce);
      throw new ADSContextException(ErrorType.ERROR_MERGING, msg, adce);
    }
  }
@@ -2552,7 +2449,7 @@
      LocalizableMessage msg = ERR_ADS_ADMINISTRATOR_MERGE.get(
          ConnectionUtils.getHostPort(adsCtx.getDirContext()), ConnectionUtils.getHostPort(getDirContext()),
          joinAsString(Constants.LINE_SEPARATOR, notDefinedAdmins), ConnectionUtils.getHostPort(getDirContext()));
      throw new ADSContextException(ADSContextException.ErrorType.ERROR_MERGING, msg, null);
      throw new ADSContextException(ErrorType.ERROR_MERGING, msg, null);
    }
  }
@@ -2621,8 +2518,7 @@
   */
  private void mergeServers(ADSContext adsCtx) throws ADSContextException
  {
    Set<Map<ServerProperty, Object>> servers2 = adsCtx.readServerRegistry();
    for (Map<ServerProperty, Object> server2 : servers2)
    for (Map<ServerProperty, Object> server2 : adsCtx.readServerRegistry())
    {
      if (!isServerAlreadyRegistered(server2))
      {
@@ -2641,7 +2537,7 @@
      }
      catch (NamingException ex)
      {
        throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, ex);
        throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, ex);
      }
    }
  }
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextException.java
@@ -24,7 +24,6 @@
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014-2015 ForgeRock AS
 */
package org.opends.admin.ads;
import static org.opends.messages.QuickSetupMessages.*;
@@ -32,99 +31,58 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.types.OpenDsException;
/**
 * This is the exception that is thrown in ADSContext.
 * @see org.opends.admin.ads.ADSContext
 *
 */
public class ADSContextException extends OpenDsException {
  private static final long serialVersionUID = 1984039711031042813L;
  private String toString;
  /**
   * The enumeration containing the different error types.
   *
   */
  /** The enumeration containing the different error types. */
  public enum ErrorType
  {
    /**
     * The host name is missing.
     */
    MISSING_HOSTNAME(),
    /**
     * The host name is not valid.
     */
    NOVALID_HOSTNAME(),
    /**
     * The installation path is missing.
     */
    MISSING_IPATH(),
    /**
     * The installation path is not valid.
     */
    NOVALID_IPATH(),
    /**
     * An access permission error.
     */
    ACCESS_PERMISSION(),
    /**
     * The entity is already registered.
     */
    ALREADY_REGISTERED(),
    /**
     * The installation is broken.
     */
    BROKEN_INSTALL(),
    /**
     * The entity is not yet registered.
     */
    NOT_YET_REGISTERED(),
    /**
     * The port is missing.
     */
    MISSING_PORT(),
    /**
     * The port is not valid.
     */
    NOVALID_PORT(),
    /**
     * The name is missing.
     */
    MISSING_NAME(),
    /**
     * The administration UID is missing.
     */
    MISSING_ADMIN_UID(),
    /**
     * The administrator password is missing.
     */
    MISSING_ADMIN_PASSWORD(),
    /**
     * There is already a backend with the name of the ADS backend but not
     * of the expected type.
     */
    UNEXPECTED_ADS_BACKEND_TYPE(),
    /**
     * Error merging with another ADSContext.
     */
    /** The host name is missing. */
    MISSING_HOSTNAME,
    /** The host name is not valid. */
    NOVALID_HOSTNAME,
    /** The installation path is missing. */
    MISSING_IPATH,
    /** The installation path is not valid. */
    NOVALID_IPATH,
    /** An access permission error. */
    ACCESS_PERMISSION,
    /** The entity is already registered. */
    ALREADY_REGISTERED,
    /** The installation is broken. */
    BROKEN_INSTALL,
    /** The entity is not yet registered. */
    NOT_YET_REGISTERED,
    /** The port is missing. */
    MISSING_PORT,
    /** The port is not valid. */
    NOVALID_PORT,
    /** The name is missing. */
    MISSING_NAME,
    /** The administration UID is missing. */
    MISSING_ADMIN_UID,
    /** The administrator password is missing. */
    MISSING_ADMIN_PASSWORD,
    /** There is already a backend with the name of the ADS backend but not of the expected type. */
    UNEXPECTED_ADS_BACKEND_TYPE,
    /** Error merging with another ADSContext. */
    ERROR_MERGING,
    /**
     * Unexpected error (potential bug).
     */
    ERROR_UNEXPECTED();
  };
    /** Unexpected error (potential bug). */
    ERROR_UNEXPECTED;
  }
  ErrorType error;
  Throwable embeddedException;
  private final ErrorType error;
  private final String toString;
  /**
   * Creates an ADSContextException of the given error type.
   * @param error the error type.
   */
  public ADSContextException(ErrorType error)
  ADSContextException(ErrorType error)
  {
    this(error, null);
  }
@@ -135,28 +93,27 @@
   * @param error the error type.
   * @param x the throwable that generated this exception.
   */
  public ADSContextException(ErrorType error, Throwable x)
  ADSContextException(ErrorType error, Throwable x)
  {
    this(error, getMessage(error, x), x);
  }
  /**
   * Creates an ADSContextException of the given error type with the provided
   * error cause and message.
   * @param error the error type.
   * @param msg the message describing the error.
   * @param x the throwable that generated this exception.
   * Creates an ADSContextException of the given error type with the provided error cause and
   * message.
   *
   * @param error
   *          the error type.
   * @param msg
   *          the message describing the error.
   * @param cause
   *          the throwable that generated this exception.
   */
  public ADSContextException(ErrorType error, LocalizableMessage msg, Throwable x)
  ADSContextException(ErrorType error, LocalizableMessage msg, Throwable cause)
  {
    super(msg);
    super(msg, cause);
    this.error = error;
    this.embeddedException = x;
    toString = "ADSContextException: error type "+error+".";
    if (getCause() != null)
    {
      toString += "  Root cause: " + getCause();
    }
    toString = "ADSContextException: error type " + error + "." + (cause != null ? "  Root cause: " + cause : "");
  }
  /**
@@ -168,28 +125,21 @@
    return error;
  }
  /**
   * Returns the throwable that caused this exception.  It might be null.
   * @return the throwable that caused this exception.
   */
  public Throwable getCause()
  {
    return embeddedException;
  }
  /** {@inheritDoc} */
  @Override
  public void printStackTrace()
  {
    super.printStackTrace();
    if (embeddedException != null)
    if (getCause() != null)
    {
      System.out.println("embeddedException = {");
      embeddedException.printStackTrace();
      getCause().printStackTrace();
      System.out.println("}");
    }
  }
  /** {@inheritDoc} */
  @Override
  public String toString()
  {
    return toString;
@@ -197,19 +147,17 @@
  private static LocalizableMessage getMessage(ErrorType error, Throwable x)
  {
    LocalizableMessage msg;
    if (x instanceof OpenDsException)
    {
      msg = INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error,
      return INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error,
          ((OpenDsException)x).getMessageObject());
    } else if (x != null)
    {
      msg = INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error, x);
      return INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error, x);
    }
    else
    {
      msg = INFO_ADS_CONTEXT_EXCEPTION_MSG.get(error);
      return INFO_ADS_CONTEXT_EXCEPTION_MSG.get(error);
    }
    return msg;
  }
}
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextHelper.java
@@ -24,14 +24,12 @@
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2014-2015 ForgeRock AS
 */
package org.opends.admin.ads;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
@@ -43,11 +41,13 @@
import javax.naming.ldap.Rdn;
import org.opends.admin.ads.ADSContext.ServerProperty;
import org.opends.admin.ads.ADSContextException.ErrorType;
import org.opends.server.admin.ManagedObjectNotFoundException;
import org.opends.server.admin.client.ManagementContext;
import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
import org.opends.server.admin.client.ldap.LDAPManagementContext;
import org.opends.server.admin.std.client.*;
import org.opends.server.admin.std.client.LDIFBackendCfgClient;
import org.opends.server.admin.std.client.RootCfgClient;
import org.opends.server.admin.std.meta.BackendCfgDefn;
import org.opends.server.admin.std.meta.LDIFBackendCfgDefn;
import org.opends.server.config.ConfigConstants;
@@ -64,63 +64,12 @@
 * QuickSetup code to be able to use some of the functionalities provided
 * by the ADSContext classes before OpenDS.jar is downloaded.
 */
public class ADSContextHelper
class ADSContextHelper
{
  /**
   * Default constructor.
   */
  /** Default constructor. */
  public ADSContextHelper()
  {
  }
  /**
   * Removes the administration suffix.
   * @param ctx the DirContext to be used.
   * @param backendName the name of the backend where the administration
   * suffix is stored.
   * @throws ADSContextException if the administration suffix could not be
   * removed.
   */
  public void removeAdministrationSuffix(InitialLdapContext ctx,
      String backendName) throws ADSContextException
  {
    try
    {
      ManagementContext mCtx = LDAPManagementContext.createFromContext(
          JNDIDirContextAdaptor.adapt(ctx));
      RootCfgClient root = mCtx.getRootConfiguration();
      BackendCfgClient backend = null;
      try
      {
        backend = root.getBackend(backendName);
      }
      catch (ManagedObjectNotFoundException monfe)
      {
        // It does not exist.
      }
      if (backend != null)
      {
        SortedSet<DN> suffixes = backend.getBaseDN();
        if (suffixes != null
            && suffixes.remove(DN.valueOf(ADSContext.getAdministrationSuffixDN())))
        {
          if (!suffixes.isEmpty())
          {
            backend.setBaseDN(suffixes);
            backend.commit();
          }
          else
          {
            root.removeBackend(backendName);
          }
        }
      }
    }
    catch (Throwable t)
    {
      throw new ADSContextException(
          ADSContextException.ErrorType.ERROR_UNEXPECTED, t);
    }
  }
  /**
   * Creates the Administration Suffix.
@@ -130,8 +79,7 @@
   * @throws ADSContextException if the administration suffix could not be
   * created.
   */
  public void createAdministrationSuffix(InitialLdapContext ctx,
      String backendName)
  void createAdministrationSuffix(InitialLdapContext ctx, String backendName)
  throws ADSContextException
  {
    try
@@ -149,8 +97,7 @@
      }
      catch (ClassCastException cce)
      {
        throw new ADSContextException(
            ADSContextException.ErrorType.UNEXPECTED_ADS_BACKEND_TYPE, cce);
        throw new ADSContextException(ErrorType.UNEXPECTED_ADS_BACKEND_TYPE, cce);
      }
      if (backend == null)
@@ -166,7 +113,7 @@
      SortedSet<DN> suffixes = backend.getBaseDN();
      if (suffixes == null)
      {
        suffixes = new TreeSet<DN>();
        suffixes = new TreeSet<>();
      }
      DN newDN = DN.valueOf(ADSContext.getAdministrationSuffixDN());
      if (!suffixes.contains(newDN))
@@ -178,8 +125,7 @@
    }
    catch (Throwable t)
    {
      throw new ADSContextException(
          ADSContextException.ErrorType.ERROR_UNEXPECTED, t);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, t);
    }
  }
@@ -196,7 +142,7 @@
  @throws ADSContextException In case some JNDI operation fails or there is a
  problem getting the instance public key certificate ID.
   */
  public void registerInstanceKeyCertificate(
  void registerInstanceKeyCertificate(
      InitialLdapContext ctx, Map<ServerProperty, Object> serverProperties,
      LdapName serverEntryDn)
  throws ADSContextException {
@@ -207,8 +153,7 @@
      return;
    }
    /* the key ID might be supplied in serverProperties (although, I am unaware
   of any such case). */
    // the key ID might be supplied in serverProperties (although, I am unaware of any such case).
    String keyID = (String)serverProperties.get(ServerProperty.INSTANCE_KEY_ID);
    /* these attributes are used both to search for an existing certificate
@@ -273,78 +218,12 @@
        /* associate server entry with certificate entry via key ID attribute */
        ctx.modifyAttributes(serverEntryDn,
          InitialLdapContext.REPLACE_ATTRIBUTE,
          (new BasicAttributes(
              ServerProperty.INSTANCE_KEY_ID.getAttributeName(), keyID)));
          new BasicAttributes(ServerProperty.INSTANCE_KEY_ID.getAttributeName(), keyID));
      }
    }
    catch (NamingException ne)
    catch (NamingException | CryptoManagerException ne)
    {
      throw new ADSContextException(
          ADSContextException.ErrorType.ERROR_UNEXPECTED, ne);
    }
    catch (CryptoManagerException cme)
    {
      throw new ADSContextException(
          ADSContextException.ErrorType.ERROR_UNEXPECTED, cme);
    }
    finally
    {
      handleCloseNamingEnumeration(results);
    }
  }
  /**
  Unregister instance key-pair public-key certificate provided in
  serverProperties.
  @param ctx the connection to the server.
  @param serverProperties Properties of the server being unregistered to which
  the instance key entry belongs.
  @param serverEntryDn The server's ADS entry DN.
  @throws ADSContextException In case some JNDI operation fails.
  */
  public void unregisterInstanceKeyCertificate(
      InitialLdapContext ctx, Map<ServerProperty, Object> serverProperties,
      LdapName serverEntryDn)
  throws ADSContextException {
    assert serverProperties.containsKey(
        ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE);
    if (! serverProperties.containsKey(
        ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) {
      return;
    }
    /* these attributes are used both to search for an existing certificate
     entry and, if one does not exist, add a new certificate entry */
    final BasicAttributes keyAttrs = new BasicAttributes();
    final Attribute oc = new BasicAttribute("objectclass");
    oc.add("top"); oc.add("ds-cfg-instance-key");
    keyAttrs.put(oc);
    keyAttrs.put(new BasicAttribute(
        ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE.getAttributeName()
        + ";binary",
        serverProperties.get(
            ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)));
    /* search for public-key certificate entry in ADS DIT */
    final String attrIDs[] = { "ds-cfg-key-id" };
    NamingEnumeration<SearchResult> results = null;
    try
    {
      results = ctx.search(
          ADSContext.getInstanceKeysContainerDN(), keyAttrs, attrIDs);
      while (results.hasMore()) {
        SearchResult res = results.next();
        ctx.destroySubcontext(res.getNameInNamespace());
      }
    }
    catch (NameNotFoundException nnfe)
    {
    }
    catch (NamingException ne)
    {
      throw new ADSContextException(
          ADSContextException.ErrorType.ERROR_UNEXPECTED, ne);
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, ne);
    }
    finally
    {
@@ -385,8 +264,7 @@
      }
      catch (NamingException ex)
      {
        throw new ADSContextException(
            ADSContextException.ErrorType.ERROR_UNEXPECTED, ex);
        throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, ex);
      }
    }
  }
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -26,6 +26,8 @@
 */
package org.opends.guitools.controlpanel.browser;
import static org.opends.messages.AdminToolMessages.*;
import java.util.ArrayList;
import java.util.Set;
@@ -52,56 +54,32 @@
import org.opends.server.types.OpenDsException;
import org.opends.server.types.RDN;
import static org.opends.messages.AdminToolMessages.*;
/**
 * The class that is in charge of doing the LDAP searches required to update a
 * node: search the local entry, detect if it has children, retrieve the
 * attributes required to render the node, etc.
 */
public class NodeRefresher extends AbstractNodeTask {
  /**
   * The enumeration containing all the states the refresher can have.
   *
   */
  /** The enumeration containing all the states the refresher can have. */
  public enum State
  {
    /**
     * The refresher is queued, but not started.
     */
    /** The refresher is queued, but not started. */
    QUEUED,
    /**
     * The refresher is reading the local entry.
     */
    /** The refresher is reading the local entry. */
    READING_LOCAL_ENTRY,
    /**
     * The refresher is solving a referral.
     */
    /** The refresher is solving a referral. */
    SOLVING_REFERRAL,
    /**
     * The refresher is detecting whether the entry has children or not.
     */
    /** The refresher is detecting whether the entry has children or not. */
    DETECTING_CHILDREN,
    /**
     * The refresher is searching for the children of the entry.
     */
    /** The refresher is searching for the children of the entry. */
    SEARCHING_CHILDREN,
    /**
     * The refresher is finished.
     */
    /** The refresher is finished. */
    FINISHED,
    /**
     * The refresher is cancelled.
     */
    /** The refresher is cancelled. */
    CANCELLED,
    /**
     * The refresher has been interrupted.
     */
    /** The refresher has been interrupted. */
    INTERRUPTED,
    /**
     * The refresher has failed.
     */
    /** The refresher has failed. */
    FAILED
  }
@@ -113,31 +91,28 @@
  SearchResult remoteEntry;
  LDAPURL   remoteUrl;
  boolean isLeafNode;
  ArrayList<SearchResult> childEntries = new ArrayList<SearchResult>();
  boolean differential;
  final ArrayList<SearchResult> childEntries = new ArrayList<>();
  final boolean differential;
  Exception exception;
  Object exceptionArg;
  /**
   * The constructor of the refresher object.
   * @param node the node on the tree to be updated.
   * @param ctlr the BrowserController.
   * @param localEntry the local entry corresponding to the node.
   * @param recursive whether this task is recursive or not (children must be
   * searched).
   * @param recursive whether this task is recursive or not (children must be searched).
   */
  public NodeRefresher(BasicNode node, BrowserController ctlr,
      SearchResult localEntry, boolean recursive) {
  NodeRefresher(BasicNode node, BrowserController ctlr, SearchResult localEntry, boolean recursive) {
    super(node);
    controller = ctlr;
    state = State.QUEUED;
    this.recursive = recursive;
    this.localEntry = localEntry;
    differential = false;
  }
  /**
   * Returns the local entry the refresher is handling.
   * @return the local entry the refresher is handling.
@@ -146,7 +121,6 @@
    return localEntry;
  }
  /**
   * Returns the remote entry for the node.  It will be <CODE>null</CODE> if
   * the entry is not a referral.
@@ -165,7 +139,6 @@
    return remoteUrl;
  }
  /**
   * Tells whether the node is a leaf or not.
   * @return <CODE>true</CODE> if the node is a leaf and <CODE>false</CODE>
@@ -175,7 +148,6 @@
    return isLeafNode;
  }
  /**
   * Returns the child entries of the node.
   * @return the child entries of the node.
@@ -203,7 +175,6 @@
    return exception;
  }
  /**
   * Returns the argument of the exception that occurred during the processing.
   * It returns <CODE>null</CODE> if no exception occurred or if the exception
@@ -214,7 +185,6 @@
    return exceptionArg;
  }
  /**
   * Returns the displayed entry in the browser.  This depends on the
   * visualization options in the BrowserController.
@@ -223,7 +193,8 @@
   */
  public SearchResult getDisplayedEntry() {
    SearchResult result;
    if (controller.getFollowReferrals() && (remoteEntry != null)) {
    if (controller.getFollowReferrals() && remoteEntry != null)
    {
      result = remoteEntry;
    }
    else {
@@ -241,7 +212,8 @@
   */
  public LDAPURL getDisplayedUrl() {
    LDAPURL result;
    if (controller.getFollowReferrals() && (remoteUrl != null)) {
    if (controller.getFollowReferrals() && remoteUrl != null)
    {
      result = remoteUrl;
    }
    else {
@@ -256,17 +228,10 @@
   * otherwise.
   */
  public boolean isInFinalState() {
    return (
      (state == State.FINISHED) ||
        (state == State.CANCELLED) ||
        (state == State.FAILED) ||
        (state == State.INTERRUPTED)
    );
    return state == State.FINISHED || state == State.CANCELLED || state == State.FAILED || state == State.INTERRUPTED;
  }
  /**
   * The method that actually does the refresh.
   */
  /** The method that actually does the refresh. */
  @Override
  public void run() {
    final BasicNode node = getNode();
@@ -289,8 +254,7 @@
        if (controller.nodeIsExpanded(node) && recursive) {
          changeStateTo(State.SEARCHING_CHILDREN);
          runSearchChildren();
          /* If the node is not expanded, we have to refresh its children
            when we expand it */
          /* If the node is not expanded, we have to refresh its children when we expand it */
        } else if (recursive  && (!node.isLeaf() || !isLeafNode)) {
          node.setRefreshNeededOnExpansion(true);
          checkExpand = true;
@@ -336,8 +300,10 @@
  {
    boolean result=false;
    if (controller.getFilter()!=null)
    {
      result =
        !controller.getFilter().equals(BrowserController.ALL_OBJECTS_FILTER);
 !BrowserController.ALL_OBJECTS_FILTER.equals(controller.getFilter());
    }
    return result;
  }
@@ -425,9 +391,7 @@
    }
  }
  /**
   * Read the local entry associated to the current node.
   */
  /** Read the local entry associated to the current node. */
  private void runReadLocalEntry() throws SearchAbandonException {
    BasicNode node = getNode();
    InitialLdapContext ctx = null;
@@ -455,7 +419,6 @@
          {
            localEntry = s.next();
            localEntry.setName(node.getDN());
          }
        }
        finally
@@ -463,8 +426,7 @@
          s.close();
        }
        if (localEntry == null) {
          /* Not enough rights to read the entry or the entry simply does not
           exist */
          /* Not enough rights to read the entry or the entry simply does not exist */
          throw new NameNotFoundException("Can't find entry: "+node.getDN());
        }
        throwAbandonIfNeeded(null);
@@ -496,12 +458,14 @@
  throws SearchAbandonException, NamingException {
    int hopCount = 0;
    String[] referral = getNode().getReferral();
    while ((referral != null) && (hopCount < 10)) {
    while (referral != null && hopCount < 10)
    {
      readRemoteEntry(referral);
      referral = BrowserController.getReferral(remoteEntry);
      hopCount++;
    }
    if (referral != null) { // -> hopCount has reached the max
    if (referral != null)
    {
      throwAbandonIfNeeded(new ReferralLimitExceededException(
          AdminToolMessages.ERR_REFERRAL_LIMIT_EXCEEDED.get(hopCount)));
    }
@@ -522,7 +486,8 @@
    Object lastExceptionArg = null;
    int i = 0;
    while ((i < referral.length) && (entry == null)) {
    while (i < referral.length && entry == null)
    {
      InitialLdapContext ctx = null;
      try {
        url = LDAPURL.decode(referral[i], false);
@@ -536,8 +501,8 @@
        }
        ctx = connectionPool.getConnection(url);
        remoteDn = url.getRawBaseDN();
        if ((remoteDn == null) ||
          remoteDn.equals("")) {
        if (remoteDn == null || "".equals(remoteDn))
        {
          /* The referral has not a target DN specified: we
             have to use the DN of the entry that contains the
             referral... */
@@ -546,8 +511,7 @@
          } else {
            remoteDn = localEntry.getName();
          }
          /* We have to recreate the url including the target DN
             we are using */
          /* We have to recreate the url including the target DN we are using */
          url = new LDAPURL(url.getScheme(), url.getHost(), url.getPort(),
              remoteDn, url.getAttributes(), url.getScope(), url.getRawFilter(),
                 url.getExtensions());
@@ -608,14 +572,10 @@
      catch (InterruptedNamingException x) {
        throwAbandonIfNeeded(x);
      }
      catch (NamingException x) {
      catch (NamingException | DirectoryException x) {
        lastException = x;
        lastExceptionArg = referral[i];
      }
      catch (DirectoryException de) {
        lastException = de;
        lastExceptionArg = referral[i];
      }
      finally {
        if (ctx != null) {
          connectionPool.releaseConnection(ctx);
@@ -685,7 +645,6 @@
    }
  }
  /**
   * Detects whether the entry has children by performing a search using the
   * entry as base DN.
@@ -754,7 +713,6 @@
    }
  }
  /**
   * NUMSUBORDINATE HACK
   * numsubordinates is not usable if the displayed entry
@@ -764,7 +722,8 @@
  private boolean isNumSubOrdinatesUsable() throws NamingException {
    SearchResult entry = getDisplayedEntry();
    boolean hasSubOrdinates = BrowserController.getHasSubOrdinates(entry);
    if (!hasSubOrdinates) { // We must check
    if (!hasSubOrdinates)
    {
      LDAPURL url = getDisplayedUrl();
      return !controller.getNumSubordinateHacker().contains(url);
    }
@@ -772,8 +731,6 @@
    return true;
  }
  /**
   * Searches for the children.
   * @throws SearchAbandonException if an error occurs.
@@ -991,11 +948,7 @@
    return sr;
  }
  /**
   * Utilities
   */
  /** Utilities. */
  /**
   * Change the state of the task and inform the BrowserController.
@@ -1012,7 +965,6 @@
    }
  }
  /**
   * Transform an exception into a TaskAbandonException.
   * If no exception is passed, the routine checks if the task has
@@ -1023,8 +975,8 @@
  private void throwAbandonIfNeeded(Exception x) throws SearchAbandonException {
    SearchAbandonException tax = null;
    if (x != null) {
      if ((x instanceof InterruptedException) ||
          (x instanceof InterruptedNamingException)) {
      if (x instanceof InterruptedException || x instanceof InterruptedNamingException)
      {
        tax = new SearchAbandonException(State.INTERRUPTED, x, null);
      }
      else {
@@ -1048,7 +1000,7 @@
   */
  private String unquoteRelativeName(String name)
  {
    if ((name.length() > 0) && (name.charAt(0) == '"'))
    if (name.length() > 0 && name.charAt(0) == '"')
    {
      if (name.charAt(name.length() - 1) == '"')
      {
@@ -1065,9 +1017,7 @@
    }
  }
  /**
   * DEBUG : Dump the state of the task.
   */
  /** DEBUG : Dump the state of the task. */
  void dump() {
    System.out.println("=============");
    System.out.println("         node: " + getNode().getDN());
@@ -1084,7 +1034,6 @@
    System.out.println("=============");
  }
  /**
   * Checks that the entry's objectClass contains 'referral' and that the
   * attribute 'ref' is present.
@@ -1099,10 +1048,10 @@
    if (ocValues != null) {
      for (String value : ocValues)
      {
        boolean isReferral = value.equalsIgnoreCase("referral");
        boolean isReferral = "referral".equalsIgnoreCase(value);
        if (isReferral) {
          result = (ConnectionUtils.getFirstValue(entry, "ref") != null);
          result = ConnectionUtils.getFirstValue(entry, "ref") != null;
          break;
        }
      }
@@ -1188,7 +1137,7 @@
            controller.getConfigurationConnection());
        int adminPort =
          ConnectionUtils.getPort(controller.getConfigurationConnection());
        checkSucceeded = (port != adminPort) ||
        checkSucceeded = port != adminPort ||
        !adminHost.equalsIgnoreCase(host);
        if (checkSucceeded)
@@ -1197,7 +1146,7 @@
              controller.getUserDataConnection());
          int portUserData =
            ConnectionUtils.getPort(controller.getUserDataConnection());
          checkSucceeded = (port != portUserData) ||
          checkSucceeded = port != portUserData ||
          !hostUserData.equalsIgnoreCase(host);
        }
      }
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/admin/client/spi/Driver.java
@@ -24,11 +24,8 @@
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014-2015 ForgeRock AS
 */
package org.opends.server.admin.client.spi;
import static org.opends.server.admin.PropertyException.*;
import java.util.ArrayList;
@@ -45,22 +42,22 @@
import org.opends.server.admin.Configuration;
import org.opends.server.admin.ConfigurationClient;
import org.opends.server.admin.Constraint;
import org.opends.server.admin.PropertyException;
import org.opends.server.admin.DefaultBehaviorProviderVisitor;
import org.opends.server.admin.DefinedDefaultBehaviorProvider;
import org.opends.server.admin.DefinitionDecodingException;
import org.opends.server.admin.DefinitionDecodingException.Reason;
import org.opends.server.admin.InstantiableRelationDefinition;
import org.opends.server.admin.ManagedObjectNotFoundException;
import org.opends.server.admin.ManagedObjectPath;
import org.opends.server.admin.OptionalRelationDefinition;
import org.opends.server.admin.PropertyDefinition;
import org.opends.server.admin.PropertyException;
import org.opends.server.admin.PropertyNotFoundException;
import org.opends.server.admin.PropertyOption;
import org.opends.server.admin.RelationDefinition;
import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider;
import org.opends.server.admin.SetRelationDefinition;
import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
import org.opends.server.admin.DefinitionDecodingException.Reason;
import org.opends.server.admin.client.AuthorizationException;
import org.opends.server.admin.client.ClientConstraintHandler;
import org.opends.server.admin.client.CommunicationException;
@@ -71,8 +68,6 @@
import org.opends.server.admin.client.OperationRejectedException.OperationType;
import org.opends.server.admin.std.client.RootCfgClient;
/**
 * An abstract management connection context driver which should form
 * the basis of driver implementations.
@@ -104,17 +99,14 @@
    /** The next property whose default values were required. */
    private PropertyDefinition<T> nextProperty;
    /** Private constructor. */
    private DefaultValueFinder(ManagedObjectPath<?, ?> p, boolean isCreate) {
      this.firstPath = p;
      this.isCreate = isCreate;
    }
    /** {@inheritDoc} */
    @Override
    public Collection<T> visitAbsoluteInherited(
        AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) {
      try {
@@ -126,20 +118,18 @@
      }
    }
    /** {@inheritDoc} */
    @Override
    public Collection<T> visitAlias(AliasDefaultBehaviorProvider<T> d, Void p) {
      return Collections.emptySet();
    }
    /** {@inheritDoc} */
    @Override
    public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> d,
        Void p) {
      Collection<String> stringValues = d.getDefaultValues();
      List<T> values = new ArrayList<T>(stringValues.size());
      List<T> values = new ArrayList<>(stringValues.size());
      for (String stringValue : stringValues) {
        try {
@@ -153,9 +143,8 @@
      return values;
    }
    /** {@inheritDoc} */
    @Override
    public Collection<T> visitRelativeInherited(
        RelativeInheritedDefaultBehaviorProvider<T> d, Void p) {
      try {
@@ -167,16 +156,13 @@
      }
    }
    /** {@inheritDoc} */
    @Override
    public Collection<T> visitUndefined(UndefinedDefaultBehaviorProvider<T> d,
        Void p) {
      return Collections.emptySet();
    }
    /** Find the default values for the next path/property. */
    private Collection<T> find(ManagedObjectPath<?, ?> p,
        PropertyDefinition<T> pd) throws PropertyException {
@@ -198,8 +184,6 @@
      return values;
    }
    /** Get an inherited property value. */
    @SuppressWarnings("unchecked")
    private Collection<T> getInheritedProperty(ManagedObjectPath target,
@@ -241,7 +225,7 @@
        if (isCreate && firstPath.equals(target)) {
          // Recursively retrieve this property's default values.
          Collection<T> tmp = find(target, pd2);
          Collection<T> values = new ArrayList<T>(tmp.size());
          Collection<T> values = new ArrayList<>(tmp.size());
          for (T value : tmp) {
            pd1.validateValue(value);
            values.add(value);
@@ -252,44 +236,23 @@
          // inherits its defaults from the newly created managed object.
          return getPropertyValues(target, pd2);
        }
      } catch (PropertyException e) {
        // Wrap any errors due to recursion.
        throw PropertyException.defaultBehaviorException(pd1, e);
      } catch (DefinitionDecodingException e) {
        throw PropertyException.defaultBehaviorException(pd1, e);
      } catch (PropertyNotFoundException e) {
        throw PropertyException.defaultBehaviorException(pd1, e);
      } catch (AuthorizationException e) {
        throw PropertyException.defaultBehaviorException(pd1, e);
      } catch (ManagedObjectNotFoundException e) {
        throw PropertyException.defaultBehaviorException(pd1, e);
      } catch (CommunicationException e) {
      } catch (PropertyException | DefinitionDecodingException | PropertyNotFoundException
          | AuthorizationException | ManagedObjectNotFoundException | CommunicationException e) {
        throw PropertyException.defaultBehaviorException(pd1, e);
      }
    }
  };
  }
  /**
   * Creates a new abstract management context.
   */
  /** Creates a new abstract management context. */
  protected Driver() {
    // No implementation required.
  }
  /**
   * Closes any context associated with this management context
   * driver.
   */
  /** Closes any context associated with this management context driver. */
  public void close() {
    // do nothing by default
  }
  /**
   * Deletes the named instantiable child managed object from the
   * named parent managed object.
@@ -338,8 +301,6 @@
    return doDeleteManagedObject(child);
  }
  /**
   * Deletes the optional child managed object from the named parent
   * managed object.
@@ -386,8 +347,6 @@
    return doDeleteManagedObject(child);
  }
  /**
   * Deletes the named instantiable child managed object from the
   * named parent managed object.
@@ -436,8 +395,6 @@
    return doDeleteManagedObject(child);
  }
  /**
   * Gets the named managed object. The path is guaranteed to be
   * non-empty, so implementations do not need to worry about handling
@@ -475,8 +432,6 @@
      ManagedObjectDecodingException, ManagedObjectNotFoundException,
      AuthorizationException, CommunicationException;
  /**
   * Gets the effective values of a property in the named managed
   * object.
@@ -531,8 +486,6 @@
      AuthorizationException, ManagedObjectNotFoundException,
      CommunicationException, PropertyException;
  /**
   * Gets the root configuration managed object associated with this
   * management context driver.
@@ -543,8 +496,6 @@
  public abstract
  ManagedObject<RootCfgClient> getRootConfigurationManagedObject();
  /**
   * Lists the child managed objects of the named parent managed
   * object which are a sub-type of the specified managed object
@@ -584,8 +535,6 @@
      throws IllegalArgumentException, ManagedObjectNotFoundException,
      AuthorizationException, CommunicationException;
  /**
   * Lists the child managed objects of the named parent managed
   * object which are a sub-type of the specified managed object
@@ -625,8 +574,6 @@
      throws IllegalArgumentException, ManagedObjectNotFoundException,
      AuthorizationException, CommunicationException;
  /**
   * Determines whether or not the named managed object exists.
   * <p>
@@ -650,8 +597,6 @@
      throws ManagedObjectNotFoundException, AuthorizationException,
      CommunicationException;
  /**
   * Deletes the named managed object.
   * <p>
@@ -684,8 +629,6 @@
      ManagedObjectPath<C, S> path) throws OperationRejectedException,
      AuthorizationException, CommunicationException;
  /**
   * Gets the default values for the specified property.
   *
@@ -706,12 +649,10 @@
  protected final <PD> Collection<PD> findDefaultValues(
      ManagedObjectPath<?, ?> p, PropertyDefinition<PD> pd, boolean isCreate)
      throws PropertyException {
    DefaultValueFinder<PD> v = new DefaultValueFinder<PD>(p, isCreate);
    DefaultValueFinder<PD> v = new DefaultValueFinder<>(p, isCreate);
    return v.find(p, pd);
  }
  /**
   * Gets the management context associated with this driver.
   *
@@ -720,8 +661,6 @@
   */
  protected abstract ManagementContext getManagementContext();
  /**
   * Validate that a relation definition belongs to the managed object
   * referenced by the provided path.
@@ -744,8 +683,6 @@
    }
  }
  /**
   * Remove a managed object, first ensuring that the parent exists,
   * then ensuring that the child exists, before ensuring that any
@@ -769,7 +706,7 @@
    // The targeted managed object is guaranteed to exist, so enforce
    // any constraints.
    AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition();
    List<LocalizableMessage> messages = new LinkedList<LocalizableMessage>();
    List<LocalizableMessage> messages = new LinkedList<>();
    boolean isAcceptable = true;
    for (Constraint constraint : d.getAllConstraints()) {
@@ -793,5 +730,4 @@
    deleteManagedObject(path);
    return true;
  }
}