From 1871de30480a6815650954ed1f48e4a03a1f7d65 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 18 Nov 2011 15:48:31 -0800 Subject: [PATCH] bug 11853: better error message when try to add VPN user with duplicated user name status 11853: resolved fixed --- .../com/cloud/api/commands/CreatePodCmd.java | 30 +++++++++---------- .../com/cloud/api/commands/UpdatePodCmd.java | 19 ++++++------ .../api/response/RemoteAccessVpnResponse.java | 2 +- .../configuration/ConfigurationService.java | 13 ++++---- .../ConfigurationManagerImpl.java | 10 +------ .../vpn/RemoteAccessVpnManagerImpl.java | 6 ++++ 6 files changed, 39 insertions(+), 41 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreatePodCmd.java b/api/src/com/cloud/api/commands/CreatePodCmd.java index a0e04a5db0d..4a52dcba60e 100755 --- a/api/src/com/cloud/api/commands/CreatePodCmd.java +++ b/api/src/com/cloud/api/commands/CreatePodCmd.java @@ -26,7 +26,6 @@ import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.PodResponse; import com.cloud.dc.Pod; import com.cloud.user.Account; @@ -40,25 +39,24 @@ public class CreatePodCmd extends BaseCmd { ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - - @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask for the Pod") - private String netmask; - - @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address for the Pod") - private String endIp; - - @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway for the Pod") - private String gateway; - @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the Pod") private String podName; - - @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the starting IP address for the Pod") - private String startIp; - + @IdentityMapper(entityTableName="data_center") @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID in which the Pod will be created ") private Long zoneId; + + @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the starting IP address for the Pod") + private String startIp; + + @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address for the Pod") + private String endIp; + + @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask for the Pod") + private String netmask; + + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway for the Pod") + private String gateway; @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this Pod for allocation of new resources") private String allocationState; @@ -111,7 +109,7 @@ public class CreatePodCmd extends BaseCmd { @Override public void execute(){ - Pod result = _configService.createPod(this); + Pod result = _configService.createPod(getZoneId(), getPodName(), getStartIp(), getEndIp(), getGateway(), getNetmask(), getAllocationState()); if (result != null) { PodResponse response = _responseGenerator.createPodResponse(result, false); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/UpdatePodCmd.java b/api/src/com/cloud/api/commands/UpdatePodCmd.java index cb9813d70af..1631fb48884 100755 --- a/api/src/com/cloud/api/commands/UpdatePodCmd.java +++ b/api/src/com/cloud/api/commands/UpdatePodCmd.java @@ -26,7 +26,6 @@ import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.PodResponse; import com.cloud.dc.Pod; import com.cloud.user.Account; @@ -41,15 +40,6 @@ public class UpdatePodCmd extends BaseCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the Pod") - private String netmask; - - @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address for the Pod") - private String endIp; - - @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway for the Pod") - private String gateway; - @IdentityMapper(entityTableName="host_pod_ref") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the Pod") private Long id; @@ -60,6 +50,15 @@ public class UpdatePodCmd extends BaseCmd { @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the starting IP address for the Pod") private String startIp; + @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address for the Pod") + private String endIp; + + @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the Pod") + private String netmask; + + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway for the Pod") + private String gateway; + @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources") private String allocationState; diff --git a/api/src/com/cloud/api/response/RemoteAccessVpnResponse.java b/api/src/com/cloud/api/response/RemoteAccessVpnResponse.java index 2b6903c9612..0d03cf87313 100644 --- a/api/src/com/cloud/api/response/RemoteAccessVpnResponse.java +++ b/api/src/com/cloud/api/response/RemoteAccessVpnResponse.java @@ -26,7 +26,7 @@ import com.google.gson.annotations.SerializedName; public class RemoteAccessVpnResponse extends BaseResponse implements ControlledEntityResponse{ @SerializedName(ApiConstants.PUBLIC_IP_ID) @Param(description="the public ip address of the vpn server") - private IdentityProxy publicIpId = new IdentityProxy("user_ip_adddress"); + private IdentityProxy publicIpId = new IdentityProxy("user_ip_address"); @SerializedName(ApiConstants.PUBLIC_IP) @Param(description="the public ip address of the vpn server") private String publicIp; diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java index 68559cec79f..007e8d8489d 100644 --- a/api/src/com/cloud/configuration/ConfigurationService.java +++ b/api/src/com/cloud/configuration/ConfigurationService.java @@ -23,7 +23,6 @@ import java.util.List; import com.cloud.api.commands.CreateCfgCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.api.commands.CreateNetworkOfferingCmd; -import com.cloud.api.commands.CreatePodCmd; import com.cloud.api.commands.CreateServiceOfferingCmd; import com.cloud.api.commands.CreateVlanIpRangeCmd; import com.cloud.api.commands.CreateZoneCmd; @@ -136,14 +135,18 @@ public interface ConfigurationService { /** * Creates a new pod based on the parameters specified in the command object - * - * @param cmd - * the command object that specifies the name, zone, gateway, cidr, and ip range for the pod + * @param zoneId TODO + * @param name TODO + * @param startIp TODO + * @param endIp TODO + * @param gateway TODO + * @param netmask TODO + * @param allocationState TODO * @return the new pod if successful, null otherwise * @throws * @throws */ - Pod createPod(CreatePodCmd cmd); + Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState); /** * Edits a pod in the database. Will not allow you to edit pods that are being used anywhere in the system. diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index e688c775bca..7d60a809e3f 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -40,7 +40,6 @@ import com.cloud.alert.AlertManager; import com.cloud.api.commands.CreateCfgCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.api.commands.CreateNetworkOfferingCmd; -import com.cloud.api.commands.CreatePodCmd; import com.cloud.api.commands.CreateServiceOfferingCmd; import com.cloud.api.commands.CreateVlanIpRangeCmd; import com.cloud.api.commands.CreateZoneCmd; @@ -909,16 +908,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } @Override - public Pod createPod(CreatePodCmd cmd) { - String endIp = cmd.getEndIp(); - String gateway = cmd.getGateway(); - String name = cmd.getPodName(); - String startIp = cmd.getStartIp(); - String netmask = cmd.getNetmask(); - Long zoneId = cmd.getZoneId(); + public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState) { String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); Long userId = UserContext.current().getCallerUserId(); - String allocationState = cmd.getAllocationState(); if (allocationState == null) { allocationState = Grouping.AllocationState.Enabled.toString(); diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java index adafdf88d95..bc92318cff9 100755 --- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java @@ -305,6 +305,12 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag throw new InvalidParameterValueException("Unable to add vpn user: Another operation active"); } _accountMgr.checkAccess(caller, null, owner); + + //don't allow duplicated user names for the same account + VpnUserVO vpnUser = _vpnUsersDao.findByAccountAndUsername(owner.getId(), username); + if (vpnUser != null) { + throw new InvalidParameterValueException("VPN User with name " + username + " is already added for account " + owner); + } long userCount = _vpnUsersDao.getVpnUserCount(owner.getId()); if (userCount >= _userLimit) {