Regular user is allowed to create Guest networks only; throw an error when he tries to use networkOffering with trafficType Public

This commit is contained in:
alena 2011-02-23 11:31:11 -08:00
parent 6cecbdbee9
commit 63cff8de26
2 changed files with 12 additions and 7 deletions

View File

@ -196,7 +196,6 @@ public enum Config {
KvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "kvm.private.network.device", null, "Specify the private bridge on host for private network", null),
// Premium
UsageExecutionTimezone("Premium", ManagementServer.class, String.class, "usage.execution.timezone", null, "The timezone to use for usage job execution time", null),
UsageStatsJobAggregationRange("Premium", ManagementServer.class, Integer.class, "usage.stats.job.aggregation.range", "1440", "The range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly.", null),
UsageStatsJobExecTime("Premium", ManagementServer.class, String.class, "usage.stats.job.exec.time", "00:15", "The time at which the usage statistics aggregation job will run as an HH24:MM time, e.g. 00:30 to run at 12:30am.", null),

View File

@ -1491,17 +1491,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
networkConfigs.add(endIP);
networkConfigs.add(netmask);
boolean defineNetworkConfig = false;
short nullElementsCount = 0;
short configElementsCount = 0;
for (String networkConfig : networkConfigs) {
if (networkConfig == null) {
nullElementsCount++;
if (networkConfig != null) {
configElementsCount++;
}
}
if (nullElementsCount > 0 && nullElementsCount != networkConfigs.size()) {
if (configElementsCount > 0 && configElementsCount != networkConfigs.size()) {
throw new InvalidParameterValueException("startIP/endIP/netmask/gateway must be specified together");
} else if (nullElementsCount == networkConfigs.size()) {
} else if (configElementsCount == networkConfigs.size()) {
defineNetworkConfig = true;
}
@ -1519,13 +1519,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
//Regular user can create guest network only
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && networkOffering.getTrafficType() != TrafficType.Guest) {
throw new InvalidParameterValueException("Regular user can create a network only from the network offering having traffic type " + TrafficType.Guest);
}
//Don't allow to specify cidr/gateway/vlan if the caller is a regular user
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && cidr != null) {
throw new InvalidParameterValueException("Regular user is not allowed to specify gateway/netmask/ipRange");
}
//For non-root admins check cidr limit - if it's allowed by global config value
if (ctxAccount.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) {
//Check cidr limit - if it's allowed by global config value
String[] cidrPair = cidr.split("\\/");
int cidrSize = Integer.valueOf(cidrPair[1]);