Search in sources :

Example 51 with ConfigurationException

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;
}
Also used : ActionListener(java.awt.event.ActionListener) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ActionEvent(java.awt.event.ActionEvent)

Example 52 with ConfigurationException

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;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) IOException(java.io.IOException) File(java.io.File)

Example 53 with ConfigurationException

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;
}
Also used : ActionListener(java.awt.event.ActionListener) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 54 with ConfigurationException

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;
}
Also used : ActionListener(java.awt.event.ActionListener) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 55 with ConfigurationException

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;
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ArrayList(java.util.ArrayList) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)66 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)31 File (java.io.File)20 IOException (java.io.IOException)19 ActionEvent (java.awt.event.ActionEvent)6 Configuration (org.apache.commons.configuration.Configuration)6 ActionListener (java.awt.event.ActionListener)5 FileInputStream (java.io.FileInputStream)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileNotFoundException (java.io.FileNotFoundException)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)2 BufferedWriter (java.io.BufferedWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2