CS-15730: Prohibit create VPN connection from different gateway to same customer gateway

This commit is contained in:
Sheng Yang 2012-07-27 17:40:54 -07:00
parent 4b0f317074
commit 65ef8b24c1
3 changed files with 14 additions and 0 deletions

View File

@ -10,4 +10,5 @@ public interface Site2SiteVpnConnectionDao extends GenericDao<Site2SiteVpnConnec
List<Site2SiteVpnConnectionVO> listByVpnGatewayId(long id);
List<Site2SiteVpnConnectionVO> listByVpcId(long vpcId);
Site2SiteVpnConnectionVO findByVpnGatewayIdAndCustomerGatewayId(long vpnId, long customerId);
Site2SiteVpnConnectionVO findByCustomerGatewayId(long customerId);
}

View File

@ -67,4 +67,11 @@ public class Site2SiteVpnConnectionDaoImpl extends GenericDaoBase<Site2SiteVpnCo
sc.setParameters("customerGatewayId", customerId);
return findOneBy(sc);
}
@Override
public Site2SiteVpnConnectionVO findByCustomerGatewayId(long customerId) {
SearchCriteria<Site2SiteVpnConnectionVO> sc = AllFieldsSearch.create();
sc.setParameters("customerGatewayId", customerId);
return findOneBy(sc);
}
}

View File

@ -211,6 +211,12 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
throw new InvalidParameterValueException("The vpn connection with specified customer gateway id or vpn gateway id " +
" already exists!", idList);
}
if (_vpnConnectionDao.findByCustomerGatewayId(customerGatewayId) != null) {
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
idList.add(new IdentityProxy(customerGateway, customerGatewayId, "customerGatewayId"));
throw new InvalidParameterValueException("The vpn connection with specified customer gateway id " +
" already exists!", idList);
}
Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(owner.getAccountId(), owner.getDomainId(), vpnGatewayId, customerGatewayId);
conn.setState(State.Pending);
_vpnConnectionDao.persist(conn);