diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java index 47579207630..5503d24d837 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java @@ -23,10 +23,6 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - import com.cloud.agent.api.BumpUpPriorityCommand; import com.cloud.agent.api.SetupGuestNetworkCommand; import com.cloud.agent.api.routing.CreateIpAliasCommand; @@ -72,11 +68,16 @@ import com.cloud.agent.resource.virtualnetwork.model.UdpAclRule; import com.cloud.agent.resource.virtualnetwork.model.VmData; import com.cloud.agent.resource.virtualnetwork.model.VmDhcpConfig; import com.cloud.agent.resource.virtualnetwork.model.VmPassword; +import com.cloud.agent.resource.virtualnetwork.model.VpnUser; +import com.cloud.agent.resource.virtualnetwork.model.VpnUserList; import com.cloud.network.HAProxyConfigurator; import com.cloud.network.LoadBalancerConfigurator; import com.cloud.network.rules.FirewallRule; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; public class ConfigHelper { private final static Gson gson; @@ -116,7 +117,7 @@ public class ConfigHelper { } else if (cmd instanceof RemoteAccessVpnCfgCommand) { cfg = generateConfig((RemoteAccessVpnCfgCommand)cmd); } else if (cmd instanceof VpnUsersCfgCommand) { - cfg = generateConfig((VpnUsersCfgCommand)cmd); + cfg = generateConfig((VpnUsersCfgCommand)cmd); // Migrated } else if (cmd instanceof Site2SiteVpnCfgCommand) { cfg = generateConfig((Site2SiteVpnCfgCommand)cmd); } else if (cmd instanceof SetMonitorServiceCommand) { @@ -135,20 +136,16 @@ public class ConfigHelper { return cfg; } + private static List generateConfig(VpnUsersCfgCommand cmd) { - LinkedList cfg = new LinkedList<>(); + + List vpnUsers = new LinkedList(); for (VpnUsersCfgCommand.UsernamePassword userpwd : cmd.getUserpwds()) { - String args = ""; - if (!userpwd.isAdd()) { - args += "-U "; - args += userpwd.getUsername(); - } else { - args += "-u "; - args += userpwd.getUsernamePassword(); - } - cfg.add(new ScriptConfigItem(VRScripts.VPN_L2TP, args)); + vpnUsers.add(new VpnUser(userpwd.getUsername(), userpwd.getPassword(), userpwd.isAdd())); } - return cfg; + + VpnUserList vpnUserList = new VpnUserList(vpnUsers); + return generateConfigItems(vpnUserList); } private static List generateConfig(RemoteAccessVpnCfgCommand cmd) { @@ -615,6 +612,9 @@ public class ConfigHelper { case ConfigBase.VM_PASSWORD: destinationFile = VRScripts.VM_PASSWORD_CONFIG; break; + case ConfigBase.VPN_USER_LIST: + destinationFile = VRScripts.VPN_USER_LIST_CONFIG; + break; default: throw new CloudRuntimeException("Unable to process the configuration for " + configuration.getType()); } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java index 1a93efaf409..65c52e990ee 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java @@ -28,6 +28,7 @@ public class VRScripts { protected final static String VM_DHCP_CONFIG = "vm_dhcp_entry.json"; protected final static String VM_PASSWORD_CONFIG = "vm_password.json"; protected static final String FORWARDING_RULES_CONFIG = "forwarding_rules.json"; + protected static final String VPN_USER_LIST_CONFIG = "vpn_user_list.json"; protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/"; protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds @@ -66,4 +67,5 @@ public class VRScripts { protected static final String VPN_L2TP = "vpn_l2tp.sh"; protected static final String VR_CFG = "vr_cfg.sh"; + } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java index 3f93eee5a67..171261ad309 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java @@ -28,6 +28,7 @@ public abstract class ConfigBase { public static final String VM_METADATA = "vmdata"; public static final String VM_PASSWORD = "vmpassword"; public static final String FORWARDING_RULES = "forwardrules"; + public static final String VPN_USER_LIST = "vpnuserlist"; private String type = UNKNOWN; diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/VpnUser.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/VpnUser.java new file mode 100644 index 00000000000..be50e7b18d2 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/VpnUser.java @@ -0,0 +1,62 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.resource.virtualnetwork.model; + +public class VpnUser { + private String user; + private String password; + private boolean add; + + public VpnUser() { + // Empty constructor for serialization + } + + public VpnUser(String user, String password, boolean add) { + super(); + this.user = user; + this.password = password; + this.add = add; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean isAdd() { + return add; + } + + public void setAdd(boolean add) { + this.add = add; + } + +} diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/VpnUserList.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/VpnUserList.java new file mode 100644 index 00000000000..115fcc9bd1e --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/VpnUserList.java @@ -0,0 +1,44 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.resource.virtualnetwork.model; + +import java.util.List; + +public class VpnUserList extends ConfigBase { + private List vpnUsers; + + public VpnUserList() { + super(ConfigBase.VPN_USER_LIST); + } + + public VpnUserList(List vpnUsers) { + super(ConfigBase.VPN_USER_LIST); + this.vpnUsers = vpnUsers; + } + + public List getVpnUsers() { + return vpnUsers; + } + + public void setVpnUsers(List vpnUsers) { + this.vpnUsers = vpnUsers; + } + +}