mirror of https://github.com/apache/cloudstack.git
bug 11853: better error message when try to add VPN user with duplicated user name
status 11853: resolved fixed
This commit is contained in:
parent
dd9465c592
commit
1871de3048
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue