use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.
the class PolicyAllCategoryPanel method getPolicySelector.
private JComboBox<String> getPolicySelector() {
if (policySelector == null) {
policySelector = new JComboBox<>();
for (String policy : extension.getPolicyManager().getAllPolicyNames()) {
policySelector.addItem(policy);
}
policySelector.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String policyName = (String) policySelector.getSelectedItem();
if (policyName == null) {
return;
}
ScanPolicy policy;
try {
policy = extension.getPolicyManager().getPolicy(policyName);
if (policy != null) {
setScanPolicy(policy);
fireScanPolicyChanged(policy);
}
} catch (ConfigurationException e1) {
logger.error(e1.getMessage(), e1);
}
}
});
}
return policySelector;
}
use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.
the class PolicyManager method loadPolicy.
private ScanPolicy loadPolicy(File file) throws ConfigurationException {
File policyFile;
try {
// Obtain the name of the file in correct case, for DEFAULT_POLICY_NAME it might not be exactly the same if the file
// system is case insensitive, thus not matching with the name read directly from the file system (method
// getAllPolicyNames()).
policyFile = file.toPath().toRealPath().toFile();
} catch (IOException e) {
throw new ConfigurationException("Failed to obtain the real path of the policy file:", e);
}
ScanPolicy policy = new ScanPolicy(new ZapXmlConfiguration(policyFile));
if (!policyFile.getName().equals(policy.getName() + POLICY_EXTENSION)) {
// The file name takes precedence in case theres another policy with the same name
policy.setName(policyFile.getName().substring(0, policyFile.getName().indexOf(POLICY_EXTENSION)));
}
return policy;
}
use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.
the class PolicyManagerDialog method getAddButton.
private JButton getAddButton() {
if (this.addButton == null) {
this.addButton = new JButton(Constant.messages.getString("ascan.policymgr.button.add"));
this.addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
extension.showPolicyDialog(PolicyManagerDialog.this);
} catch (ConfigurationException e1) {
logger.error(e1.getMessage(), e1);
}
}
});
}
return this.addButton;
}
use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.
the class PolicyManagerDialog method getModifyButton.
private JButton getModifyButton() {
if (this.modifyButton == null) {
this.modifyButton = new JButton(Constant.messages.getString("ascan.policymgr.button.modify"));
this.modifyButton.setEnabled(false);
this.modifyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = (String) getParamsModel().getValueAt(getParamsTable().getSelectedRow(), 0);
if (name != null) {
try {
extension.showPolicyDialog(PolicyManagerDialog.this, name);
} catch (ConfigurationException e1) {
logger.error(e1.getMessage(), e1);
}
}
}
});
}
return this.modifyButton;
}
use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.
the class VulnerabilitiesLoader method loadVulnerabilitiesFile.
private List<Vulnerability> loadVulnerabilitiesFile(Path file) {
ZapXmlConfiguration config;
try {
config = new ZapXmlConfiguration(file.toFile());
} catch (ConfigurationException e) {
logger.error(e.getMessage(), e);
return null;
}
String[] test;
try {
test = config.getStringArray("vuln_items");
} catch (ConversionException e) {
logger.error(e.getMessage(), e);
return null;
}
final int numberOfVulns = test.length;
List<Vulnerability> tempVulns = new ArrayList<>(numberOfVulns);
String name;
List<String> references;
for (String item : test) {
name = "vuln_item_" + item;
try {
references = new ArrayList<>(Arrays.asList(config.getStringArray(name + ".reference")));
} catch (ConversionException e) {
logger.error(e.getMessage(), e);
references = new ArrayList<>(0);
}
Vulnerability v = new Vulnerability(item, config.getString(name + ".alert"), config.getString(name + ".desc"), config.getString(name + ".solution"), references);
tempVulns.add(v);
}
return tempVulns;
}
Aggregations