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

Ludovic Poitou
03.00.2013 f703254518fa8d365be170145e07721aaf9815e4
opendj-sdk/opends/src/server/org/opends/server/protocols/jmx/JmxConnectionHandler.java
@@ -122,6 +122,10 @@
      portChanged = true;
    }
    if (currentConfig.getRmiPort() != config.getRmiPort())
    {
      rmiConnectorRestart = true;
    }
    if (currentConfig.isUseSSL() != config.isUseSSL()) {
      rmiConnectorRestart = true;
    }
@@ -205,9 +209,7 @@
  @Override
  public Map<String, String> getAlerts()
  {
    Map<String, String> alerts = new LinkedHashMap<String, String>();
    return alerts;
    return new LinkedHashMap<String, String>();
  }
@@ -280,6 +282,14 @@
    return currentConfig.getListenPort();
  }
  /**
   * Get the JMX connection handler's rmi port.
   *
   * @return Returns the JMX connection handler's rmi port.
   */
  public int getRmiPort() {
    return currentConfig.getRmiPort();
  }
  /**
@@ -326,22 +336,11 @@
    // Configuration is ok.
    currentConfig = config;
    // Attempt to bind to the listen port to verify whether the connection
    // handler will be able to start.
    try
    List<Message> reasons = new LinkedList<Message>();
    if (!isPortConfigurationAcceptable(String.valueOf(config.dn()),
        config.getListenPort(), reasons))
    {
      if (StaticUtils.isAddressInUse(
        new InetSocketAddress(config.getListenPort()).getAddress(),
        config.getListenPort(), true)) {
        throw new IOException(
          ERR_CONNHANDLER_ADDRESS_INUSE.get().toString());
      }
    }
    catch (Exception e)
    {
      Message message =
          ERR_CONNHANDLER_CANNOT_BIND.get("JMX", String.valueOf(config.dn()),
              WILDCARD_ADDRESS, config.getListenPort(), getExceptionMessage(e));
      Message message = reasons.get(0);
      logError(message);
      throw new InitializationException(message);
    }
@@ -399,7 +398,6 @@
  }
  /**
   * {@inheritDoc}
   */
@@ -409,32 +407,48 @@
  {
    JMXConnectionHandlerCfg config = (JMXConnectionHandlerCfg) configuration;
    if ((currentConfig == null) ||
    if (currentConfig == null ||
        (!currentConfig.isEnabled() && config.isEnabled()) ||
        (currentConfig.getListenPort() != config.getListenPort())) {
      // Attempt to bind to the listen port to verify whether the connection
      // handler will be able to start.
      try {
        if (StaticUtils.isAddressInUse(
          new InetSocketAddress(config.getListenPort()).getAddress(),
          config.getListenPort(), true)) {
          throw new IOException(
            ERR_CONNHANDLER_ADDRESS_INUSE.get().toString());
        }
      } catch (Exception e) {
        Message message =
            ERR_CONNHANDLER_CANNOT_BIND.get("JMX", String.valueOf(config.dn()),
                WILDCARD_ADDRESS, config.getListenPort(),
                getExceptionMessage(e));
        unacceptableReasons.add(message);
        return false;
      }
        currentConfig.getListenPort() != config.getListenPort() &&
        !isPortConfigurationAcceptable(String.valueOf(config.dn()),
          config.getListenPort(), unacceptableReasons))
    {
      return false;
    }
    if (config.getRmiPort() != 0 &&
        (currentConfig == null ||
        (!currentConfig.isEnabled() && config.isEnabled()) ||
        currentConfig.getRmiPort() != config.getRmiPort()) &&
        !isPortConfigurationAcceptable(String.valueOf(config.dn()),
          config.getRmiPort(), unacceptableReasons))
    {
      return false;
    }
    return isConfigurationChangeAcceptable(config, unacceptableReasons);
  }
  /**
   * Attempt to bind to the port to verify whether the connection
   * handler will be able to start.
   * @return true is the port is free to use, false otherwise.
   */
  private boolean isPortConfigurationAcceptable(String configDN,
                      int newPort, List<Message> unacceptableReasons) {
    try {
      if (StaticUtils.isAddressInUse(
          new InetSocketAddress(newPort).getAddress(), newPort, true)) {
        throw new IOException(ERR_CONNHANDLER_ADDRESS_INUSE.get().toString());
      }
    } catch (Exception e) {
      Message message = ERR_CONNHANDLER_CANNOT_BIND.get("JMX", configDN,
              WILDCARD_ADDRESS, newPort, getExceptionMessage(e));
      unacceptableReasons.add(message);
      return false;
    }
    return true;
  }
  /**
   * {@inheritDoc}
@@ -453,7 +467,7 @@
   * Determines whether or not clients are allowed to connect over JMX
   * using SSL.
   *
   * @return Returns <code>true</code> if clients are allowed to
   * @return Returns {@code true} if clients are allowed to
   *         connect over JMX using SSL.
   */
  public boolean isUseSSL() {
@@ -494,8 +508,9 @@
    {
      rmiConnector.initialize();
    }
    catch (RuntimeException e)
    catch (RuntimeException ignore)
    {
      // Already caught and logged
    }
  }