mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
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
This commit is contained in:
parent
fef8f6d4af
commit
82cb1095dc
@ -23,6 +23,6 @@ import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface Site2SiteCustomerGatewayDao extends GenericDao<Site2SiteCustomerGatewayVO, Long> {
|
||||
Site2SiteCustomerGatewayVO findByGatewayIp(String ip);
|
||||
Site2SiteCustomerGatewayVO findByName(String name);
|
||||
Site2SiteCustomerGatewayVO findByNameAndAccountId(String name, long accountId);
|
||||
List<Site2SiteCustomerGatewayVO> listByAccountId(long accountId);
|
||||
}
|
||||
|
||||
@ -49,9 +49,10 @@ public class Site2SiteCustomerGatewayDaoImpl extends GenericDaoBase<Site2SiteCus
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site2SiteCustomerGatewayVO findByName(String name) {
|
||||
public Site2SiteCustomerGatewayVO findByNameAndAccountId(String name, long accountId) {
|
||||
SearchCriteria<Site2SiteCustomerGatewayVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("name", name);
|
||||
sc.setParameters("accountId", accountId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
|
||||
}
|
||||
Long espLifetime = cmd.getEspLifetime();
|
||||
if (espLifetime == null) {
|
||||
// Default value of lifetime is 1 day
|
||||
// Default value of lifetime is 1 hour
|
||||
espLifetime = (long) 3600;
|
||||
}
|
||||
if (espLifetime > 86400) {
|
||||
@ -222,16 +222,17 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
|
||||
dpd = false;
|
||||
}
|
||||
|
||||
long accountId = owner.getAccountId();
|
||||
if (_customerGatewayDao.findByGatewayIp(gatewayIp) != null) {
|
||||
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed!");
|
||||
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed in the system!");
|
||||
}
|
||||
if (_customerGatewayDao.findByName(name) != null) {
|
||||
if (_customerGatewayDao.findByNameAndAccountId(name, accountId) != null) {
|
||||
throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!");
|
||||
}
|
||||
|
||||
checkCustomerGatewayCidrList(guestCidrList);
|
||||
|
||||
Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(name, owner.getAccountId(), owner.getDomainId(), gatewayIp, guestCidrList, ipsecPsk,
|
||||
Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(name, accountId, owner.getDomainId(), gatewayIp, guestCidrList, ipsecPsk,
|
||||
ikePolicy, espPolicy, ikeLifetime, espLifetime, dpd);
|
||||
_customerGatewayDao.persist(gw);
|
||||
return gw;
|
||||
@ -454,7 +455,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
|
||||
}
|
||||
Long espLifetime = cmd.getEspLifetime();
|
||||
if (espLifetime == null) {
|
||||
// Default value of lifetime is 1 day
|
||||
// Default value of lifetime is 1 hour
|
||||
espLifetime = (long) 3600;
|
||||
}
|
||||
if (espLifetime > 86400) {
|
||||
@ -467,6 +468,14 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
|
||||
}
|
||||
|
||||
checkCustomerGatewayCidrList(guestCidrList);
|
||||
|
||||
long accountId = gw.getAccountId();
|
||||
if (_customerGatewayDao.findByGatewayIp(gatewayIp) != null) {
|
||||
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed in the system!");
|
||||
}
|
||||
if (_customerGatewayDao.findByNameAndAccountId(name, accountId) != null) {
|
||||
throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!");
|
||||
}
|
||||
|
||||
gw.setName(name);
|
||||
gw.setGatewayIp(gatewayIp);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user