Skip to content

Commit 82cb109

Browse files
author
Sheng Yang
committed
CS-16188: S2S VPN: Limit VPN customer gateway name duplicate checking within account
Reviewed-by: Anthony Xu Conflicts: server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
1 parent fef8f6d commit 82cb109

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323

2424
public interface Site2SiteCustomerGatewayDao extends GenericDao<Site2SiteCustomerGatewayVO, Long> {
2525
Site2SiteCustomerGatewayVO findByGatewayIp(String ip);
26-
Site2SiteCustomerGatewayVO findByName(String name);
26+
Site2SiteCustomerGatewayVO findByNameAndAccountId(String name, long accountId);
2727
List<Site2SiteCustomerGatewayVO> listByAccountId(long accountId);
2828
}

‎server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ public Site2SiteCustomerGatewayVO findByGatewayIp(String ip) {
4949
}
5050

5151
@Override
52-
public Site2SiteCustomerGatewayVO findByName(String name) {
52+
public Site2SiteCustomerGatewayVO findByNameAndAccountId(String name, long accountId) {
5353
SearchCriteria<Site2SiteCustomerGatewayVO> sc = AllFieldsSearch.create();
5454
sc.setParameters("name", name);
55+
sc.setParameters("accountId", accountId);
5556
return findOneBy(sc);
5657
}
5758

‎server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCm
210210
}
211211
Long espLifetime = cmd.getEspLifetime();
212212
if (espLifetime == null) {
213-
// Default value of lifetime is 1 day
213+
// Default value of lifetime is 1 hour
214214
espLifetime = (long) 3600;
215215
}
216216
if (espLifetime > 86400) {
@@ -222,16 +222,17 @@ public Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCm
222222
dpd = false;
223223
}
224224

225+
long accountId = owner.getAccountId();
225226
if (_customerGatewayDao.findByGatewayIp(gatewayIp) != null) {
226-
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed!");
227+
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed in the system!");
227228
}
228-
if (_customerGatewayDao.findByName(name) != null) {
229+
if (_customerGatewayDao.findByNameAndAccountId(name, accountId) != null) {
229230
throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!");
230231
}
231232

232233
checkCustomerGatewayCidrList(guestCidrList);
233234

234-
Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(name, owner.getAccountId(), owner.getDomainId(), gatewayIp, guestCidrList, ipsecPsk,
235+
Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(name, accountId, owner.getDomainId(), gatewayIp, guestCidrList, ipsecPsk,
235236
ikePolicy, espPolicy, ikeLifetime, espLifetime, dpd);
236237
_customerGatewayDao.persist(gw);
237238
return gw;
@@ -454,7 +455,7 @@ public Site2SiteCustomerGateway updateCustomerGateway(UpdateVpnCustomerGatewayCm
454455
}
455456
Long espLifetime = cmd.getEspLifetime();
456457
if (espLifetime == null) {
457-
// Default value of lifetime is 1 day
458+
// Default value of lifetime is 1 hour
458459
espLifetime = (long) 3600;
459460
}
460461
if (espLifetime > 86400) {
@@ -467,6 +468,14 @@ public Site2SiteCustomerGateway updateCustomerGateway(UpdateVpnCustomerGatewayCm
467468
}
468469

469470
checkCustomerGatewayCidrList(guestCidrList);
471+
472+
long accountId = gw.getAccountId();
473+
if (_customerGatewayDao.findByGatewayIp(gatewayIp) != null) {
474+
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed in the system!");
475+
}
476+
if (_customerGatewayDao.findByNameAndAccountId(name, accountId) != null) {
477+
throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!");
478+
}
470479

471480
gw.setName(name);
472481
gw.setGatewayIp(gatewayIp);

0 commit comments

Comments
 (0)