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

neil_a_wilson
20.04.2007 8f731063c3a73ae2585abd4f949611f153be9421
opends/src/server/org/opends/server/core/CoreConfigManager.java
@@ -30,6 +30,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.std.server.GlobalCfg;
@@ -46,6 +48,7 @@
import static org.opends.server.messages.ConfigMessages.*;
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.server.util.ServerConstants.*;
@@ -88,10 +91,50 @@
         managementContext.getRootConfiguration();
    // Get the global configuration, register with it as a change listener, and
    // apply the configuration to the server.
    // Get the global configuration and register with it as a change listener.
    GlobalCfg globalConfig = rootConfiguration.getGlobalConfiguration();
    globalConfig.addChangeListener(this);
    // If there are any STMP servers specified, then make sure that if the value
    // contains a colon that the portion after it is an integer between 1 and
    // 65535.
    Set<String> smtpServers = globalConfig.getSMTPServer();
    if (smtpServers != null)
    {
      for (String server : smtpServers)
      {
        int colonPos = server.indexOf(':');
        if ((colonPos == 0) || (colonPos == (server.length()-1)))
        {
          int    msgID   = MSGID_CONFIG_CORE_INVALID_SMTP_SERVER;
          String message = getMessage(msgID, server);
          throw new ConfigException(msgID, message);
        }
        else if (colonPos > 0)
        {
          try
          {
            int port = Integer.parseInt(server.substring(colonPos+1));
            if ((port < 1) || (port > 65535))
            {
              int    msgID   = MSGID_CONFIG_CORE_INVALID_SMTP_SERVER;
              String message = getMessage(msgID, server);
              throw new ConfigException(msgID, message);
            }
          }
          catch (Exception e)
          {
            int    msgID   = MSGID_CONFIG_CORE_INVALID_SMTP_SERVER;
            String message = getMessage(msgID, server);
            throw new ConfigException(msgID, message, e);
          }
        }
      }
    }
    // Apply the configuration to the server.
    applyGlobalConfiguration(globalConfig);
  }
@@ -180,6 +223,34 @@
         globalConfig.isBindWithDNRequiresPassword());
    DirectoryServer.setLookthroughLimit(globalConfig.getLookthroughLimit());
    ArrayList<Properties> mailServerProperties = new ArrayList<Properties>();
    Set<String> smtpServers = globalConfig.getSMTPServer();
    if ((smtpServers != null) && (! smtpServers.isEmpty()))
    {
      for (String smtpServer : smtpServers)
      {
        int colonPos = smtpServer.indexOf(':');
        if (colonPos > 0)
        {
          String smtpHost = smtpServer.substring(0, colonPos);
          String smtpPort = smtpServer.substring(colonPos+1);
          Properties properties = new Properties();
          properties.setProperty(SMTP_PROPERTY_HOST, smtpHost);
          properties.setProperty(SMTP_PROPERTY_PORT, smtpPort);
          mailServerProperties.add(properties);
        }
        else
        {
          Properties properties = new Properties();
          properties.setProperty(SMTP_PROPERTY_HOST, smtpServer);
          mailServerProperties.add(properties);
        }
      }
    }
    DirectoryServer.setMailServerPropertySets(mailServerProperties);
  }
@@ -217,6 +288,43 @@
      configAcceptable = false;
    }
    Set<String> smtpServers = configuration.getSMTPServer();
    if (smtpServers != null)
    {
      for (String server : smtpServers)
      {
        int colonPos = server.indexOf(':');
        if ((colonPos == 0) || (colonPos == (server.length()-1)))
        {
          int    msgID   = MSGID_CONFIG_CORE_INVALID_SMTP_SERVER;
          String message = getMessage(msgID, server);
          unacceptableReasons.add(message);
          configAcceptable = false;
        }
        else if (colonPos > 0)
        {
          try
          {
            int port = Integer.parseInt(server.substring(colonPos+1));
            if ((port < 1) || (port > 65535))
            {
              int    msgID   = MSGID_CONFIG_CORE_INVALID_SMTP_SERVER;
              String message = getMessage(msgID, server);
              unacceptableReasons.add(message);
              configAcceptable = false;
            }
          }
          catch (Exception e)
          {
            int    msgID   = MSGID_CONFIG_CORE_INVALID_SMTP_SERVER;
            String message = getMessage(msgID, server);
            unacceptableReasons.add(message);
            configAcceptable = false;
          }
        }
      }
    }
    return configAcceptable;
  }