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 e8ad5b7d01
commit b410cbff5f
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

@ -205,6 +205,12 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
throw new InvalidParameterValueException("The vpn connection with customer gateway id " + customerGatewayId + " or vpn gateway id "
+ vpnGatewayId + " already existed!");
}
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);