CS-16188: S2S VPN: Limit VPN customer gateway name duplicate checking within account

Reviewed-by: Anthony Xu
This commit is contained in:
Sheng Yang 2012-08-27 14:32:41 -07:00
parent 4ee91fcccf
commit 4783139426
3 changed files with 17 additions and 7 deletions

View File

@ -7,6 +7,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);
}

View File

@ -33,9 +33,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);
}

View File

@ -206,7 +206,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) {
@ -218,16 +218,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!", null);
throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed in the system!", null);
}
if (_customerGatewayDao.findByName(name) != null) {
if (_customerGatewayDao.findByNameAndAccountId(name, accountId) != null) {
throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!", null);
}
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;
@ -466,7 +467,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) {
@ -480,6 +481,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!", null);
}
if (_customerGatewayDao.findByNameAndAccountId(name, accountId) != null) {
throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!", null);
}
gw.setName(name);
gw.setGatewayIp(gatewayIp);
gw.setGuestCidrList(guestCidrList);