Ejemplo n.º 1
0
  /**
   * This methods updates the ADS properties (the ones that were read from the ADS) with the
   * contents of the server properties (the ones that were read directly from the server).
   */
  public void updateAdsPropertiesWithServerProperties() {
    adsProperties.put(ADSContext.ServerProperty.HOST_NAME, getHostName());
    ServerProperty[][] sProps = {
      {ServerProperty.LDAP_ENABLED, ServerProperty.LDAP_PORT},
      {ServerProperty.LDAPS_ENABLED, ServerProperty.LDAPS_PORT},
      {ServerProperty.ADMIN_ENABLED, ServerProperty.ADMIN_PORT},
      {ServerProperty.JMX_ENABLED, ServerProperty.JMX_PORT},
      {ServerProperty.JMXS_ENABLED, ServerProperty.JMXS_PORT}
    };
    ADSContext.ServerProperty[][] adsProps = {
      {ADSContext.ServerProperty.LDAP_ENABLED, ADSContext.ServerProperty.LDAP_PORT},
      {ADSContext.ServerProperty.LDAPS_ENABLED, ADSContext.ServerProperty.LDAPS_PORT},
      {ADSContext.ServerProperty.ADMIN_ENABLED, ADSContext.ServerProperty.ADMIN_PORT},
      {ADSContext.ServerProperty.JMX_ENABLED, ADSContext.ServerProperty.JMX_PORT},
      {ADSContext.ServerProperty.JMXS_ENABLED, ADSContext.ServerProperty.JMXS_PORT}
    };

    for (int i = 0; i < sProps.length; i++) {
      ArrayList<?> s = (ArrayList<?>) serverProperties.get(sProps[i][0]);
      ArrayList<?> p = (ArrayList<?>) serverProperties.get(sProps[i][1]);
      if (s != null) {
        int port = -1;
        for (int j = 0; j < s.size(); j++) {
          if (Boolean.TRUE.equals(s.get(j))) {
            port = (Integer) p.get(j);
            break;
          }
        }
        if (port == -1) {
          adsProperties.put(adsProps[i][0], "false");
          if (p.size() > 0) {
            port = (Integer) p.iterator().next();
          }
        } else {
          adsProperties.put(adsProps[i][0], "true");
        }
        adsProperties.put(adsProps[i][1], String.valueOf(port));
      }
    }

    ArrayList<?> array = (ArrayList<?>) serverProperties.get(ServerProperty.STARTTLS_ENABLED);
    boolean startTLSEnabled = false;
    if ((array != null) && !array.isEmpty()) {
      startTLSEnabled = Boolean.TRUE.equals(array.get(array.size() - 1));
    }
    adsProperties.put(
        ADSContext.ServerProperty.STARTTLS_ENABLED, startTLSEnabled ? "true" : "false");
    adsProperties.put(ADSContext.ServerProperty.ID, getHostPort(true));
    adsProperties.put(
        ADSContext.ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE,
        getInstancePublicKeyCertificate());
  }
Ejemplo n.º 2
0
 /**
  * Returns whether the communication with the replication port on the server is encrypted or not.
  *
  * @return <CODE>true</CODE> if the communication with the replication port on the server is
  *     encrypted and <CODE>false</CODE> otherwise.
  */
 public boolean isReplicationSecure() {
   boolean isReplicationSecure;
   if (isReplicationServer()) {
     isReplicationSecure =
         Boolean.TRUE.equals(serverProperties.get(ServerProperty.IS_REPLICATION_SECURE));
   } else {
     isReplicationSecure = false;
   }
   return isReplicationSecure;
 }
Ejemplo n.º 3
0
 /**
  * Returns the list of enabled administration ports.
  *
  * @return the list of enabled administration ports.
  */
 public List<Integer> getEnabledAdministrationPorts() {
   List<Integer> ports = new ArrayList<Integer>(1);
   ArrayList<?> s = (ArrayList<?>) serverProperties.get(ServerProperty.ADMIN_ENABLED);
   ArrayList<?> p = (ArrayList<?>) serverProperties.get(ServerProperty.ADMIN_PORT);
   if (s != null) {
     for (int i = 0; i < s.size(); i++) {
       if (Boolean.TRUE.equals(s.get(i))) {
         ports.add((Integer) p.get(i));
       }
     }
   }
   return ports;
 }
Ejemplo n.º 4
0
  /**
   * Returns the URL to access this server using the administration connector. Returns <CODE>null
   * </CODE> if the server cannot get the administration connector.
   *
   * @return the URL to access this server using the administration connector.
   */
  public String getAdminConnectorURL() {
    String adminConnectorUrl = null;
    String host = getHostName();
    int port = -1;

    if (!serverProperties.isEmpty()) {
      ArrayList<?> s = (ArrayList<?>) serverProperties.get(ServerProperty.ADMIN_ENABLED);
      ArrayList<?> p = (ArrayList<?>) serverProperties.get(ServerProperty.ADMIN_PORT);
      if (s != null) {
        for (int i = 0; i < s.size(); i++) {
          if (Boolean.TRUE.equals(s.get(i))) {
            port = (Integer) p.get(i);
            break;
          }
        }
      }
    }
    if (port != -1) {
      adminConnectorUrl = ConnectionUtils.getLDAPUrl(host, port, true);
    }
    return adminConnectorUrl;
  }
Ejemplo n.º 5
0
  /**
   * Returns a String of type host-name:port-number for the server. If the provided securePreferred
   * is set to true the port that will be used will be the administration connector port.
   *
   * @param securePreferred whether to try to use the secure port as part of the returning String or
   *     not.
   * @return a String of type host-name:port-number for the server.
   */
  public String getHostPort(boolean securePreferred) {
    String host = getHostName();
    int port = -1;

    if (!serverProperties.isEmpty()) {
      ArrayList<?> s = (ArrayList<?>) serverProperties.get(ServerProperty.LDAP_ENABLED);
      ArrayList<?> p = (ArrayList<?>) serverProperties.get(ServerProperty.LDAP_PORT);
      if (s != null) {
        for (int i = 0; i < s.size(); i++) {
          if (Boolean.TRUE.equals(s.get(i))) {
            port = (Integer) p.get(i);
            break;
          }
        }
      }
      if (securePreferred) {
        s = (ArrayList<?>) serverProperties.get(ServerProperty.ADMIN_ENABLED);
        p = (ArrayList<?>) serverProperties.get(ServerProperty.ADMIN_PORT);
        if (s != null) {
          for (int i = 0; i < s.size(); i++) {
            if (Boolean.TRUE.equals(s.get(i))) {
              port = (Integer) p.get(i);
              break;
            }
          }
        }
      }
    } else {
      ArrayList<ADSContext.ServerProperty> enabledAttrs =
          new ArrayList<ADSContext.ServerProperty>();

      if (securePreferred) {
        enabledAttrs.add(ADSContext.ServerProperty.ADMIN_ENABLED);
        enabledAttrs.add(ADSContext.ServerProperty.LDAPS_ENABLED);
        enabledAttrs.add(ADSContext.ServerProperty.LDAP_ENABLED);
      } else {
        enabledAttrs.add(ADSContext.ServerProperty.LDAP_ENABLED);
        enabledAttrs.add(ADSContext.ServerProperty.ADMIN_ENABLED);
        enabledAttrs.add(ADSContext.ServerProperty.LDAPS_ENABLED);
      }

      for (ADSContext.ServerProperty prop : enabledAttrs) {
        Object v = adsProperties.get(prop);
        if ((v != null) && "true".equalsIgnoreCase(String.valueOf(v))) {
          ADSContext.ServerProperty portProp;
          if (prop == ADSContext.ServerProperty.ADMIN_ENABLED) {
            portProp = ADSContext.ServerProperty.ADMIN_PORT;
          } else if (prop == ADSContext.ServerProperty.LDAPS_ENABLED) {
            portProp = ADSContext.ServerProperty.LDAPS_PORT;
          } else if (prop == ADSContext.ServerProperty.LDAP_ENABLED) {
            portProp = ADSContext.ServerProperty.LDAP_PORT;
          } else {
            throw new IllegalStateException("Unexpected prop: " + prop);
          }
          Object p = adsProperties.get(portProp);
          if (p != null) {
            try {
              port = Integer.parseInt(String.valueOf(p));
            } catch (Throwable t) {
              LOG.log(
                  Level.WARNING, "Error calculating host port: " + t + " in " + adsProperties, t);
            }
            break;
          } else {
            LOG.log(Level.WARNING, "Value for " + portProp + " is null in " + adsProperties);
          }
        }
      }
    }
    return host + ":" + port;
  }
Ejemplo n.º 6
0
 /**
  * Tells whether replication is enabled on this server or not.
  *
  * @return <CODE>true</CODE> if replication is enabled and <CODE>false</CODE> otherwise.
  */
 public boolean isReplicationEnabled() {
   return Boolean.TRUE.equals(serverProperties.get(ServerProperty.IS_REPLICATION_ENABLED));
 }
Ejemplo n.º 7
0
 /**
  * Tells whether this server is a replication server or not.
  *
  * @return <CODE>true</CODE> if the server is a replication server and <CODE>false</CODE>
  *     otherwise.
  */
 public boolean isReplicationServer() {
   return Boolean.TRUE.equals(serverProperties.get(ServerProperty.IS_REPLICATION_SERVER));
 }