Program: 106041
Project: 106041
Buggy source:
private boolean manageSecurityPolicy(SecurityPolicyType type,SrxCommand command,Long accountId,String username,String privateIp,List<String> applicationNames,List<String> cidrs,String ipsecVpnName,boolean defaultEgressAction) throws ExecutionException {
  String fromZone=_publicZone;
  String toZone=_privateZone;
  String securityPolicyName;
  String addressBookEntryName=null;
  if (type.equals(SecurityPolicyType.VPN) && ipsecVpnName != null) {
    securityPolicyName=ipsecVpnName;
    addressBookEntryName=ipsecVpnName;
  }
 else   if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
    fromZone=_privateZone;
    toZone=_publicZone;
    securityPolicyName=genSecurityPolicyName(type,accountId,username,fromZone,toZone,privateIp);
  }
 else {
    securityPolicyName=genSecurityPolicyName(type,accountId,username,fromZone,toZone,privateIp);
    addressBookEntryName=genAddressBookEntryName(privateIp);
  }
  String xml;
switch (command) {
case CHECK_IF_EXISTS:
    xml=SrxXml.SECURITY_POLICY_GETONE.getXml();
  xml=setDelete(xml,false);
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
xml=replaceXmlValue(xml,"String_Node_Str",securityPolicyName);
return sendRequestAndCheckResponse(command,xml,"String_Node_Str",securityPolicyName);
case CHECK_IF_IN_USE:
List<String[]> rulesToCheck=null;
if (type.equals(SecurityPolicyType.STATIC_NAT)) {
rulesToCheck=getStaticNatRules(RuleMatchCondition.ALL,null,null);
}
 else if (type.equals(SecurityPolicyType.DESTINATION_NAT)) {
rulesToCheck=getDestNatRules(RuleMatchCondition.ALL,null,null,null,null);
}
 else {
return false;
}
for (String[] rule : rulesToCheck) {
String rulePrivateIp=rule[1];
if (privateIp.equals(rulePrivateIp)) {
return true;
}
}
return false;
case ADD:
if (!(type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT))) {
if (!manageAddressBookEntry(SrxCommand.CHECK_IF_EXISTS,toZone,privateIp,addressBookEntryName)) {
throw new ExecutionException("String_Node_Str" + securityPolicyName);
}
}
String srcAddrs="String_Node_Str";
String dstAddrs="String_Node_Str";
String action="String_Node_Str";
xml=SrxXml.SECURITY_POLICY_ADD.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",securityPolicyName);
if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
xml=replaceXmlValue(xml,"String_Node_Str",_privateZone);
xml=replaceXmlValue(xml,"String_Node_Str",_publicZone);
if (cidrs == null) {
srcAddrs="String_Node_Str";
}
 else {
for (String cidr : cidrs) {
srcAddrs+="String_Node_Str" + genAddressBookEntryName(cidr) + "String_Node_Str";
}
}
xml=replaceXmlValue(xml,"String_Node_Str",srcAddrs);
dstAddrs="String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",dstAddrs);
if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
if (defaultEgressAction == false) {
action="String_Node_Str";
}
 else {
action="String_Node_Str";
}
}
 else {
if (defaultEgressAction == true) {
action="String_Node_Str";
}
 else {
action="String_Node_Str";
}
xml=replaceXmlValue(xml,"String_Node_Str",action);
}
}
 else {
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
srcAddrs="String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",srcAddrs);
dstAddrs="String_Node_Str" + addressBookEntryName + "String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",dstAddrs);
}
if (type.equals(SecurityPolicyType.VPN) && ipsecVpnName != null) {
xml=replaceXmlValue(xml,"String_Node_Str","String_Node_Str" + ipsecVpnName + "String_Node_Str");
}
 else {
xml=replaceXmlValue(xml,"String_Node_Str","String_Node_Str");
if (!(type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS))) {
action="String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",action);
}
}
String applications;
if (applicationNames == null || applicationNames.size() == 0) {
applications="String_Node_Str";
}
 else {
applications="String_Node_Str";
for (String applicationName : applicationNames) {
applications+="String_Node_Str" + applicationName + "String_Node_Str";
}
}
xml=replaceXmlValue(xml,"String_Node_Str",applications);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str" + privateIp + "String_Node_Str"+ applicationNames);
}
 else {
return true;
}
case DELETE:
if (!manageSecurityPolicy(type,SrxCommand.CHECK_IF_EXISTS,null,null,privateIp,applicationNames,cidrs,ipsecVpnName,defaultEgressAction)) {
return true;
}
if (manageSecurityPolicy(type,SrxCommand.CHECK_IF_IN_USE,null,null,privateIp,applicationNames,cidrs,ipsecVpnName,defaultEgressAction)) {
return true;
}
xml=SrxXml.SECURITY_POLICY_GETONE.getXml();
xml=setDelete(xml,true);
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
xml=replaceXmlValue(xml,"String_Node_Str",securityPolicyName);
boolean success=sendRequestAndCheckResponse(command,xml);
if (success) {
xml=SrxXml.SECURITY_POLICY_GETALL.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
String getAllResponseXml=sendRequest(xml);
if (getAllResponseXml == null) {
throw new ExecutionException("String_Node_Str");
}
if (!getAllResponseXml.contains(fromZone) || !getAllResponseXml.contains(toZone)) {
return true;
}
 else if (!getAllResponseXml.contains("String_Node_Str") && !getAllResponseXml.contains("String_Node_Str")) {
xml=SrxXml.SECURITY_POLICY_GROUP.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
xml=setDelete(xml,true);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str");
}
 else {
return true;
}
}
 else {
return true;
}
}
 else {
throw new ExecutionException("String_Node_Str" + privateIp + "String_Node_Str"+ applicationNames);
}
default :
s_logger.debug("String_Node_Str");
return false;
}
}

Fixed version (ground truth):
private boolean manageSecurityPolicy(SecurityPolicyType type,SrxCommand command,Long accountId,String username,String privateIp,List<String> applicationNames,List<String> cidrs,String ipsecVpnName,boolean defaultEgressAction) throws ExecutionException {
  String fromZone=_publicZone;
  String toZone=_privateZone;
  String securityPolicyName;
  String addressBookEntryName=null;
  if (type.equals(SecurityPolicyType.VPN) && ipsecVpnName != null) {
    securityPolicyName=ipsecVpnName;
    addressBookEntryName=ipsecVpnName;
  }
 else   if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
    fromZone=_privateZone;
    toZone=_publicZone;
    securityPolicyName=genSecurityPolicyName(type,accountId,username,fromZone,toZone,privateIp);
  }
 else {
    securityPolicyName=genSecurityPolicyName(type,accountId,username,fromZone,toZone,privateIp);
    addressBookEntryName=genAddressBookEntryName(privateIp);
  }
  String xml;
switch (command) {
case CHECK_IF_EXISTS:
    xml=SrxXml.SECURITY_POLICY_GETONE.getXml();
  xml=setDelete(xml,false);
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
xml=replaceXmlValue(xml,"String_Node_Str",securityPolicyName);
return sendRequestAndCheckResponse(command,xml,"String_Node_Str",securityPolicyName);
case CHECK_IF_IN_USE:
List<String[]> rulesToCheck=null;
if (type.equals(SecurityPolicyType.STATIC_NAT)) {
rulesToCheck=getStaticNatRules(RuleMatchCondition.ALL,null,null);
}
 else if (type.equals(SecurityPolicyType.DESTINATION_NAT)) {
rulesToCheck=getDestNatRules(RuleMatchCondition.ALL,null,null,null,null);
}
 else {
return false;
}
for (String[] rule : rulesToCheck) {
String rulePrivateIp=rule[1];
if (privateIp.equals(rulePrivateIp)) {
return true;
}
}
return false;
case ADD:
if (!(type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT))) {
if (!manageAddressBookEntry(SrxCommand.CHECK_IF_EXISTS,toZone,privateIp,addressBookEntryName)) {
throw new ExecutionException("String_Node_Str" + securityPolicyName);
}
}
String srcAddrs="String_Node_Str";
String dstAddrs="String_Node_Str";
String action="String_Node_Str";
xml=SrxXml.SECURITY_POLICY_ADD.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",securityPolicyName);
if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
xml=replaceXmlValue(xml,"String_Node_Str",_privateZone);
xml=replaceXmlValue(xml,"String_Node_Str",_publicZone);
if (cidrs == null || cidrs.size() == 0) {
srcAddrs="String_Node_Str";
}
 else {
for (String cidr : cidrs) {
srcAddrs+="String_Node_Str" + genAddressBookEntryName(cidr) + "String_Node_Str";
}
}
xml=replaceXmlValue(xml,"String_Node_Str",srcAddrs);
dstAddrs="String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",dstAddrs);
if (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT)) {
if (defaultEgressAction == false) {
action="String_Node_Str";
}
 else {
action="String_Node_Str";
}
}
 else {
if (defaultEgressAction == true) {
action="String_Node_Str";
}
 else {
action="String_Node_Str";
}
xml=replaceXmlValue(xml,"String_Node_Str",action);
}
}
 else {
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
srcAddrs="String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",srcAddrs);
dstAddrs="String_Node_Str" + addressBookEntryName + "String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",dstAddrs);
}
if (type.equals(SecurityPolicyType.VPN) && ipsecVpnName != null) {
xml=replaceXmlValue(xml,"String_Node_Str","String_Node_Str" + ipsecVpnName + "String_Node_Str");
}
 else {
xml=replaceXmlValue(xml,"String_Node_Str","String_Node_Str");
if (!(type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS))) {
action="String_Node_Str";
xml=replaceXmlValue(xml,"String_Node_Str",action);
}
}
String applications;
if (applicationNames == null || applicationNames.size() == 0) {
applications="String_Node_Str";
}
 else {
applications="String_Node_Str";
for (String applicationName : applicationNames) {
applications+="String_Node_Str" + applicationName + "String_Node_Str";
}
}
xml=replaceXmlValue(xml,"String_Node_Str",applications);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str" + privateIp + "String_Node_Str"+ applicationNames);
}
 else {
return true;
}
case DELETE:
if (!manageSecurityPolicy(type,SrxCommand.CHECK_IF_EXISTS,null,null,privateIp,applicationNames,cidrs,ipsecVpnName,defaultEgressAction)) {
return true;
}
if (manageSecurityPolicy(type,SrxCommand.CHECK_IF_IN_USE,null,null,privateIp,applicationNames,cidrs,ipsecVpnName,defaultEgressAction)) {
return true;
}
xml=SrxXml.SECURITY_POLICY_GETONE.getXml();
xml=setDelete(xml,true);
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
xml=replaceXmlValue(xml,"String_Node_Str",securityPolicyName);
boolean success=sendRequestAndCheckResponse(command,xml);
if (success) {
xml=SrxXml.SECURITY_POLICY_GETALL.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
String getAllResponseXml=sendRequest(xml);
if (getAllResponseXml == null) {
throw new ExecutionException("String_Node_Str");
}
if (!getAllResponseXml.contains(fromZone) || !getAllResponseXml.contains(toZone)) {
return true;
}
 else if (!getAllResponseXml.contains("String_Node_Str") && !getAllResponseXml.contains("String_Node_Str")) {
xml=SrxXml.SECURITY_POLICY_GROUP.getXml();
xml=replaceXmlValue(xml,"String_Node_Str",fromZone);
xml=replaceXmlValue(xml,"String_Node_Str",toZone);
xml=setDelete(xml,true);
if (!sendRequestAndCheckResponse(command,xml)) {
throw new ExecutionException("String_Node_Str");
}
 else {
return true;
}
}
 else {
return true;
}
}
 else {
throw new ExecutionException("String_Node_Str" + privateIp + "String_Node_Str"+ applicationNames);
}
default :
s_logger.debug("String_Node_Str");
return false;
}
}