Skip to content

Commit 544fa7f

Browse files
author
Alex Huang
committed
remote access vpn, user ip address changes
1 parent 1afb34d commit 544fa7f

134 files changed

Lines changed: 1755 additions & 2462 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
135135
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
136136
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
137-
import com.cloud.agent.api.routing.RoutingCommand;
137+
import com.cloud.agent.api.routing.NetworkElementCommand;
138138
import com.cloud.agent.api.storage.CreateAnswer;
139139
import com.cloud.agent.api.storage.CreateCommand;
140140
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
@@ -1109,7 +1109,7 @@ public Answer executeRequest(Command cmd) {
11091109
return execute((FenceCommand) cmd);
11101110
} else if (cmd instanceof StartCommand ) {
11111111
return execute((StartCommand) cmd);
1112-
} else if (cmd instanceof RoutingCommand) {
1112+
} else if (cmd instanceof NetworkElementCommand) {
11131113
return _virtRouterResource.executeRequest(cmd);
11141114
} else if (cmd instanceof CheckSshCommand) {
11151115
return execute((CheckSshCommand) cmd);

api/src/com/cloud/agent/api/routing/IPAssocCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author alena
2525
*
2626
*/
27-
public class IPAssocCommand extends RoutingCommand {
27+
public class IPAssocCommand extends NetworkElementCommand {
2828

2929
IpAddressTO[] ipAddresses;
3030

api/src/com/cloud/agent/api/routing/LoadBalancerConfigCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* LoadBalancerConfigCommand sends the load balancer configuration
2424
* to the load balancer. Isn't that kinda obvious?
2525
*/
26-
public class LoadBalancerConfigCommand extends RoutingCommand {
26+
public class LoadBalancerConfigCommand extends NetworkElementCommand {
2727
LoadBalancerTO[] loadBalancers;
2828

2929
public LoadBalancerConfigCommand( LoadBalancerTO[] loadBalancers) {

api/src/com/cloud/agent/api/routing/RoutingCommand.java renamed to api/src/com/cloud/agent/api/routing/NetworkElementCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
import com.cloud.agent.api.Command;
2323

24-
public abstract class RoutingCommand extends Command {
24+
public abstract class NetworkElementCommand extends Command {
2525
HashMap<String, String> accessDetails = new HashMap<String, String>(0);
2626

2727
public static final String ROUTER_NAME = "router.name";
2828
public static final String ROUTER_IP = "router.ip";
2929

30-
protected RoutingCommand() {
30+
protected NetworkElementCommand() {
3131
super();
3232
}
3333

api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* AccessDetails allow different components to put in information about
2828
* how to access the components inside the command.
2929
*/
30-
public class SetFirewallRulesCommand extends RoutingCommand {
30+
public class SetFirewallRulesCommand extends NetworkElementCommand {
3131
FirewallRuleTO[] rules;
3232

3333
protected SetFirewallRulesCommand() {

api/src/com/cloud/agent/api/routing/SetPortForwardingRulesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.cloud.agent.api.to.PortForwardingRuleTO;
2323
import com.cloud.network.rules.PortForwardingRule;
2424

25-
public class SetPortForwardingRulesCommand extends RoutingCommand {
25+
public class SetPortForwardingRulesCommand extends NetworkElementCommand {
2626
PortForwardingRuleTO[] rules;
2727

2828
protected SetPortForwardingRulesCommand() {

api/src/com/cloud/api/BaseCmd.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,24 @@
3232
import com.cloud.dao.EntityManager;
3333
import com.cloud.exception.ConcurrentOperationException;
3434
import com.cloud.exception.InsufficientCapacityException;
35+
import com.cloud.exception.InvalidParameterValueException;
36+
import com.cloud.exception.PermissionDeniedException;
3537
import com.cloud.exception.ResourceAllocationException;
3638
import com.cloud.exception.ResourceUnavailableException;
37-
import com.cloud.network.VirtualNetworkApplianceService;
3839
import com.cloud.network.NetworkService;
40+
import com.cloud.network.VirtualNetworkApplianceService;
3941
import com.cloud.network.lb.LoadBalancingRulesService;
4042
import com.cloud.network.rules.RulesService;
4143
import com.cloud.network.security.SecurityGroupService;
44+
import com.cloud.network.vpn.RemoteAccessVpnService;
4245
import com.cloud.resource.ResourceService;
4346
import com.cloud.server.ManagementService;
4447
import com.cloud.storage.StorageService;
4548
import com.cloud.storage.snapshot.SnapshotService;
4649
import com.cloud.template.TemplateService;
4750
import com.cloud.user.Account;
4851
import com.cloud.user.AccountService;
52+
import com.cloud.user.UserContext;
4953
import com.cloud.utils.Pair;
5054
import com.cloud.utils.component.ComponentLocator;
5155
import com.cloud.vm.UserVmService;
@@ -92,18 +96,19 @@ public enum CommandType {
9296
public static AccountService _accountService;
9397
public static UserVmService _userVmService;
9498
public static ManagementService _mgr;
95-
public static StorageService _storageMgr;
99+
public static StorageService _storageService;
96100
public static ResourceService _resourceService;
97101
public static NetworkService _networkService;
98102
public static TemplateService _templateService;
99-
public static SecurityGroupService _securityGroupMgr;
100-
public static SnapshotService _snapshotMgr;
101-
public static ConsoleProxyService _consoleProxyMgr;
103+
public static SecurityGroupService _securityGroupService;
104+
public static SnapshotService _snapshotService;
105+
public static ConsoleProxyService _consoleProxyService;
102106
public static VirtualNetworkApplianceService _routerService;
103107
public static ResponseGenerator _responseGenerator;
104108
public static EntityManager _entityMgr;
105109
public static RulesService _rulesService;
106110
public static LoadBalancingRulesService _lbService;
111+
public static RemoteAccessVpnService _ravService;
107112

108113

109114
static void setComponents(ResponseGenerator generator) {
@@ -112,17 +117,18 @@ static void setComponents(ResponseGenerator generator) {
112117
_accountService = locator.getManager(AccountService.class);
113118
_configService = locator.getManager(ConfigurationService.class);
114119
_userVmService = locator.getManager(UserVmService.class);
115-
_storageMgr = locator.getManager(StorageService.class);
120+
_storageService = locator.getManager(StorageService.class);
116121
_resourceService = locator.getManager(ResourceService.class);
117122
_networkService = locator.getManager(NetworkService.class);
118123
_templateService = locator.getManager(TemplateService.class);
119-
_securityGroupMgr = locator.getManager(SecurityGroupService.class);
120-
_snapshotMgr = locator.getManager(SnapshotService.class);
121-
_consoleProxyMgr = locator.getManager(ConsoleProxyService.class);
124+
_securityGroupService = locator.getManager(SecurityGroupService.class);
125+
_snapshotService = locator.getManager(SnapshotService.class);
126+
_consoleProxyService = locator.getManager(ConsoleProxyService.class);
122127
_routerService = locator.getManager(VirtualNetworkApplianceService.class);
123128
_entityMgr = locator.getManager(EntityManager.class);
124129
_rulesService = locator.getManager(RulesService.class);
125130
_lbService = locator.getManager(LoadBalancingRulesService.class);
131+
_ravService = locator.getManager(RemoteAccessVpnService.class);
126132
_responseGenerator = generator;
127133
}
128134

@@ -160,6 +166,22 @@ public static String getDateString(Date date) {
160166
return formattedString;
161167
}
162168

169+
protected Account getValidOwner(String accountName, Long domainId) {
170+
Account owner = null;
171+
if (accountName != null) {
172+
owner = _responseGenerator.findAccountByNameDomain(accountName, domainId);
173+
} else {
174+
owner = UserContext.current().getCaller();
175+
}
176+
if (owner == null) {
177+
throw new InvalidParameterValueException("Invalid value for owner specified: " + accountName);
178+
}
179+
if (owner.getState() == Account.State.Disabled || owner.getState() == Account.State.Locked) {
180+
throw new PermissionDeniedException("Account disabled.");
181+
}
182+
return owner;
183+
}
184+
163185
public Map<String, Object> validateParams(Map<String, String> params, boolean decode) {
164186
// List<Pair<Enum, Boolean>> properties = getProperties();
165187

@@ -253,7 +275,7 @@ public Map<String, Object> validateParams(Map<String, String> params, boolean de
253275
return validatedParams;
254276
*/
255277
}
256-
278+
257279
private Map<String, Object> lowercaseParams(Map<String, String> params, boolean decode) {
258280
Map<String, Object> lowercaseParams = new HashMap<String, Object>();
259281
for (String key : params.keySet()) {

api/src/com/cloud/api/commands/AddVpnUserCmd.java

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@
2020

2121
import org.apache.log4j.Logger;
2222

23-
import com.cloud.api.BaseAsyncCmd;
23+
import com.cloud.api.BaseAsyncCreateCmd;
2424
import com.cloud.api.BaseCmd;
2525
import com.cloud.api.Implementation;
2626
import com.cloud.api.Parameter;
2727
import com.cloud.api.ServerApiException;
2828
import com.cloud.api.response.VpnUsersResponse;
2929
import com.cloud.domain.Domain;
3030
import com.cloud.event.EventTypes;
31-
import com.cloud.exception.ConcurrentOperationException;
3231
import com.cloud.network.VpnUser;
3332
import com.cloud.user.Account;
3433
import com.cloud.user.UserContext;
3534

3635
@Implementation(description="Adds vpn users", responseObject=VpnUsersResponse.class)
37-
public class AddVpnUserCmd extends BaseAsyncCmd {
36+
public class AddVpnUserCmd extends BaseAsyncCreateCmd {
3837
public static final Logger s_logger = Logger.getLogger(AddVpnUserCmd.class.getName());
3938

4039
private static final String s_name = "addvpnuserresponse";
@@ -94,7 +93,7 @@ public String getCommandName() {
9493

9594
@Override
9695
public long getEntityOwnerId() {
97-
Account account = UserContext.current().getAccount();
96+
Account account = UserContext.current().getCaller();
9897
if ((account == null) || isAdmin(account.getType())) {
9998
if ((domainId != null) && (accountName != null)) {
10099
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
@@ -125,29 +124,38 @@ public String getEventType() {
125124

126125
@Override
127126
public void execute(){
128-
try {
129-
VpnUser vpnUser = _networkService.addVpnUser(this);
130-
if (vpnUser != null) {
131-
VpnUsersResponse vpnResponse = new VpnUsersResponse();
132-
vpnResponse.setId(vpnUser.getId());
133-
vpnResponse.setUserName(vpnUser.getUsername());
134-
vpnResponse.setAccountName(vpnUser.getAccountName());
135-
136-
Account accountTemp = _entityMgr.findById(Account.class, vpnUser.getAccountId());
137-
if (accountTemp != null) {
138-
vpnResponse.setDomainId(accountTemp.getDomainId());
139-
vpnResponse.setDomainName(_entityMgr.findById(Domain.class, accountTemp.getDomainId()).getName());
140-
}
141-
142-
vpnResponse.setResponseName(getCommandName());
143-
vpnResponse.setObjectName("vpnuser");
144-
this.setResponseObject(vpnResponse);
145-
} else {
127+
VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
128+
Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId());
129+
if (!_ravService.applyVpnUsers(vpnUser.getAccountId())) {
146130
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
147131
}
148-
} catch (ConcurrentOperationException ex) {
149-
s_logger.warn("Exception: ", ex);
150-
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
151-
}
132+
133+
VpnUsersResponse vpnResponse = new VpnUsersResponse();
134+
vpnResponse.setId(vpnUser.getId());
135+
vpnResponse.setUserName(vpnUser.getUsername());
136+
vpnResponse.setAccountName(account.getAccountName());
137+
138+
vpnResponse.setDomainId(account.getDomainId());
139+
vpnResponse.setDomainName(_entityMgr.findById(Domain.class, account.getDomainId()).getName());
140+
141+
vpnResponse.setResponseName(getCommandName());
142+
vpnResponse.setObjectName("vpnuser");
143+
this.setResponseObject(vpnResponse);
144+
}
145+
146+
@Override
147+
public void create() {
148+
Account owner = null;
149+
if (accountName != null) {
150+
owner = _responseGenerator.findAccountByNameDomain(accountName, domainId);
151+
} else {
152+
owner = UserContext.current().getCaller();
153+
}
154+
155+
VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password);
156+
if (vpnUser == null) {
157+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
158+
}
159+
setEntityId(vpnUser.getId());
152160
}
153161
}

api/src/com/cloud/api/commands/AssociateIPAddrCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public String getAccountName() {
6767
if (accountName != null) {
6868
return accountName;
6969
}
70-
return UserContext.current().getAccount().getAccountName();
70+
return UserContext.current().getCaller().getAccountName();
7171
}
7272

7373
public long getDomainId() {
7474
if (domainId != null) {
7575
return domainId;
7676
}
77-
return UserContext.current().getAccount().getDomainId();
77+
return UserContext.current().getCaller().getDomainId();
7878
}
7979

8080
public long getZoneId() {

api/src/com/cloud/api/commands/AuthorizeSecurityGroupIngressCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static String getResultObjectName() {
154154

155155
@Override
156156
public long getEntityOwnerId() {
157-
Account account = UserContext.current().getAccount();
157+
Account account = UserContext.current().getCaller();
158158
if ((account == null) || isAdmin(account.getType())) {
159159
if ((domainId != null) && (accountName != null)) {
160160
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
@@ -207,7 +207,7 @@ public String getEventDescription() {
207207

208208
@Override
209209
public void execute(){
210-
List<? extends IngressRule> ingressRules = _securityGroupMgr.authorizeSecurityGroupIngress(this);
210+
List<? extends IngressRule> ingressRules = _securityGroupService.authorizeSecurityGroupIngress(this);
211211
if (ingressRules != null && ! ingressRules.isEmpty()) {
212212
SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponseFromIngressRule(ingressRules);
213213
this.setResponseObject(response);

0 commit comments

Comments
 (0)