Add validation for domain names passed via global pamaremets

This commit is contained in:
amoghvk 2014-11-26 14:45:50 -08:00
parent 3d6635a537
commit 86895ec13c
2 changed files with 20 additions and 10 deletions

View File

@ -16,6 +16,15 @@
// under the License.
package com.cloud.configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
import org.apache.cloudstack.framework.config.ConfigKey;
import com.cloud.agent.AgentManager;
import com.cloud.consoleproxy.ConsoleProxyManager;
import com.cloud.ha.HighAvailabilityManager;
@ -29,14 +38,6 @@ import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.template.TemplateManager;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.snapshot.VMSnapshotManager;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
import org.apache.cloudstack.framework.config.ConfigKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;
public enum Config {
@ -438,7 +439,7 @@ public enum Config {
"Console proxy command port that is used to communicate with management server",
null),
ConsoleProxyRestart("Console Proxy", AgentManager.class, Boolean.class, "consoleproxy.restart", "true", "Console proxy restart flag, defaulted to true", null),
ConsoleProxyUrlDomain("Console Proxy", AgentManager.class, String.class, "consoleproxy.url.domain", "", "Console proxy url domain", null),
ConsoleProxyUrlDomain("Console Proxy", AgentManager.class, String.class, "consoleproxy.url.domain", "", "Console proxy url domain", "domainName"),
ConsoleProxyLoadscanInterval(
"Console Proxy",
AgentManager.class,
@ -774,7 +775,7 @@ public enum Config {
"secstorage.ssl.cert.domain",
"",
"SSL certificate used to encrypt copy traffic between zones",
null),
"domainName"),
SecStorageCapacityStandby(
"Advanced",
AgentManager.class,

View File

@ -327,6 +327,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
private int _maxVolumeSizeInGb = Integer.parseInt(Config.MaxVolumeSize.getDefaultValue());
private long _defaultPageSize = Long.parseLong(Config.DefaultPageSize.getDefaultValue());
private static final String DOMAIN_NAME_PATTERN = "^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$";
protected Set<String> configValuesForValidation;
private Set<String> weightBasedParametersForValidation;
private Set<String> overprovisioningFactorsForValidation;
@ -838,6 +839,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (!NetUtils.verifyInstanceName(value)) {
return "Instance name can not contain hyphen, space or plus sign";
}
} else if (range.equalsIgnoreCase("domainName")) {
String domainName = value;
if (value.startsWith("*")) {
domainName = value.substring(2); //skip the "*."
}
if (!domainName.matches(DOMAIN_NAME_PATTERN)) {
return "Please enter a valid string for domain name, prefixed with '*.' if applicable";
}
} else if (range.equals("routes")) {
String[] routes = value.split(",");
for (String route : routes) {