Search in sources :

Example 11 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class PolicyManagerDialog method getParamsTable.

private JTable getParamsTable() {
    if (paramsTable == null) {
        paramsTable = new JTable();
        paramsTable.setModel(getParamsModel());
        paramsTable.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getClickCount() >= 2) {
                    int row = paramsTable.rowAtPoint(e.getPoint());
                    if (row >= 0) {
                        String name = (String) getParamsModel().getValueAt(row, 0);
                        if (name != null) {
                            try {
                                extension.showPolicyDialog(PolicyManagerDialog.this, name);
                            } catch (ConfigurationException e1) {
                                logger.error(e1.getMessage(), e1);
                            }
                        }
                    }
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }
        });
        paramsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (getParamsTable().getSelectedRowCount() == 0) {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                } else if (getParamsTable().getSelectedRowCount() == 1) {
                    getModifyButton().setEnabled(true);
                    // Dont let the last policy be removed
                    getRemoveButton().setEnabled(getParamsModel().getRowCount() > 1);
                    getExportButton().setEnabled(true);
                } else {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                }
            }
        });
    }
    return paramsTable;
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) ConfigurationException(org.apache.commons.configuration.ConfigurationException) JTable(javax.swing.JTable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 12 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class CustomScanDialog method init.

public void init(Target target) {
    if (target != null) {
        // If one isnt specified then leave the previously selected one
        this.target = target;
    }
    logger.debug("init " + this.target);
    this.removeAllFields();
    this.injectionPointModel.clear();
    this.headerLength = -1;
    this.urlPathStart = -1;
    if (scanPolicyName != null && PolicyManager.policyExists(scanPolicyName)) {
        try {
            scanPolicy = extension.getPolicyManager().getPolicy(scanPolicyName);
        } catch (ConfigurationException e) {
            logger.warn("Failed to load scan policy (" + scanPolicyName + "):", e);
        }
    }
    if (scanPolicy == null) {
        scanPolicy = extension.getPolicyManager().getDefaultScanPolicy();
        scanPolicyName = scanPolicy.getName();
    }
    this.addTargetSelectField(0, FIELD_START, this.target, false, false);
    this.addComboField(0, FIELD_POLICY, extension.getPolicyManager().getAllPolicyNames(), scanPolicy.getName());
    this.addComboField(0, FIELD_CONTEXT, new String[] {}, "");
    this.addComboField(0, FIELD_USER, new String[] {}, "");
    this.addCheckBoxField(0, FIELD_RECURSE, true);
    // This option is always read from the 'global' options
    this.addCheckBoxField(0, FIELD_ADVANCED, extension.getScannerParam().isShowAdvancedDialog());
    this.addFieldListener(FIELD_POLICY, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            policySelected();
        }
    });
    this.addPadding(0);
    // Default to Recurse, so always set the warning
    customPanelStatus.setText(Constant.messages.getString("ascan.custom.status.recurse"));
    this.addFieldListener(FIELD_CONTEXT, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setUsers();
            setTech();
        }
    });
    this.addFieldListener(FIELD_RECURSE, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setFieldStates();
        }
    });
    this.addFieldListener(FIELD_ADVANCED, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Save the adv option permanently for next time
            setAdvancedOptions(getBoolValue(FIELD_ADVANCED));
        }
    });
    this.getVariantPanel().initParam(scannerParam);
    this.setCustomTabPanel(1, getVariantPanel());
    // Custom vectors panel
    this.setCustomTabPanel(2, getCustomPanel());
    // Technology panel
    this.setCustomTabPanel(3, getTechPanel());
    // Policy panel
    policyPanel.resetAndSetPolicy(scanPolicy.getName());
    this.setCustomTabPanel(4, policyPanel);
    // add custom panels
    int cIndex = 5;
    if (this.customPanels != null) {
        for (CustomScanPanel customPanel : this.customPanels) {
            this.setCustomTabPanel(cIndex, customPanel.getPanel(true));
            cIndex++;
        }
    }
    if (target != null) {
        // Set up the fields if a node has been specified, otherwise leave as previously set
        this.populateRequestField(this.target.getStartNode());
        this.targetSelected(FIELD_START, this.target);
        this.setUsers();
        this.setTech();
    }
    this.setAdvancedOptions(extension.getScannerParam().isShowAdvancedDialog());
    this.pack();
}
Also used : ActionListener(java.awt.event.ActionListener) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ActionEvent(java.awt.event.ActionEvent)

Example 13 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class AddOnLoader method saveAddOnsRunState.

private static void saveAddOnsRunState(Map<AddOn, List<String>> runnableAddOns) {
    HierarchicalConfiguration config = (HierarchicalConfiguration) Model.getSingleton().getOptionsParam().getConfig();
    config.clearTree(ADDONS_RUNNABLE_BASE_KEY);
    int i = 0;
    for (Map.Entry<AddOn, List<String>> runnableAddOnEntry : runnableAddOns.entrySet()) {
        String elementBaseKey = ADDONS_RUNNABLE_KEY + "(" + i + ").";
        AddOn addOn = runnableAddOnEntry.getKey();
        config.setProperty(elementBaseKey + ADDON_RUNNABLE_ID_KEY, addOn.getId());
        config.setProperty(elementBaseKey + ADDON_RUNNABLE_VERSION_KEY, Integer.valueOf(addOn.getFileVersion()));
        String extensionBaseKey = elementBaseKey + ADDON_RUNNABLE_ALL_EXTENSIONS_KEY;
        for (String extension : runnableAddOnEntry.getValue()) {
            config.addProperty(extensionBaseKey, extension);
        }
        i++;
    }
    try {
        Model.getSingleton().getOptionsParam().getConfig().save();
    } catch (ConfigurationException e) {
        logger.error("Failed to save state of runnable add-ons:", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class GuiBootstrap method setupLocale.

/**
     * Setups ZAP's and GUI {@code Locale}, if not previously defined. Otherwise it's determined automatically or, if not
     * possible, by asking the user to choose one of the supported locales.
     *
     * @param options ZAP's options, used to check if a locale was already defined and save it if not.
     * @see #setDefaultViewLocale(Locale)
     * @see Constant#setLocale(String)
     */
private void setupLocale(OptionsParam options) {
    // Prompt for language if not set
    String locale = options.getViewParam().getConfigLocale();
    if (locale == null || locale.length() == 0) {
        // Dont use a parent of the MainFrame - that will initialise it
        // with English!
        final Locale userloc = determineUsersSystemLocale();
        if (userloc == null) {
            // Only show the dialog, when the user's language can't be
            // guessed.
            setDefaultViewLocale(Constant.getSystemsLocale());
            final LocaleDialog dialog = new LocaleDialog(null, true);
            dialog.init(options);
            dialog.setVisible(true);
        } else {
            options.getViewParam().setLocale(userloc);
        }
        setDefaultViewLocale(createLocale(options.getViewParam().getLocale().split("_")));
        Constant.setLocale(Model.getSingleton().getOptionsParam().getViewParam().getLocale());
        try {
            options.getViewParam().getConfig().save();
        } catch (ConfigurationException e) {
            logger.warn("Failed to save locale: ", e);
        }
    }
}
Also used : Locale(java.util.Locale) ConfigurationException(org.apache.commons.configuration.ConfigurationException) LocaleDialog(org.zaproxy.zap.view.LocaleDialog)

Example 15 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class Session method importContext.

/**
	 * Imports a context from the specified (XML) file.
	 * 
	 * @param file the (XML) file that contains the context data
	 * @return the imported {@code Context}, already added to the session.
	 * @throws ConfigurationException
	 * @throws ClassNotFoundException
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 * @throws SecurityException
	 * @throws IllegalContextNameException (since TODO add version) if context's name is not provided or it's empty or if a
	 *             context with the same name already exists.
	 */
public Context importContext(File file) throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    ZapXmlConfiguration config = new ZapXmlConfiguration(file);
    String name = config.getString(Context.CONTEXT_CONFIG_NAME);
    validateContextName(name);
    Context c = createContext(name);
    c.setDescription(config.getString(Context.CONTEXT_CONFIG_DESC));
    c.setInScope(config.getBoolean(Context.CONTEXT_CONFIG_INSCOPE));
    for (Object obj : config.getList(Context.CONTEXT_CONFIG_INC_REGEXES)) {
        c.addIncludeInContextRegex(obj.toString());
    }
    for (Object obj : config.getList(Context.CONTEXT_CONFIG_EXC_REGEXES)) {
        c.addExcludeFromContextRegex(obj.toString());
    }
    TechSet techSet = new TechSet();
    for (Object obj : config.getList(Context.CONTEXT_CONFIG_TECH_INCLUDE)) {
        techSet.include(new Tech(obj.toString()));
    }
    for (Object obj : config.getList(Context.CONTEXT_CONFIG_TECH_EXCLUDE)) {
        techSet.exclude(new Tech(obj.toString()));
    }
    c.setTechSet(techSet);
    String urlParserClass = config.getString(Context.CONTEXT_CONFIG_URLPARSER_CLASS);
    if (urlParserClass == null) {
        // Can happen due to a bug in 2.4.0 where is was saved using the wrong name :(
        urlParserClass = config.getString(Context.CONTEXT_CONFIG_URLPARSER);
    }
    Class<?> cl = ExtensionFactory.getAddOnLoader().loadClass(urlParserClass);
    if (cl == null) {
        throw new ConfigurationException("Failed to load URL parser for context " + urlParserClass);
    } else {
        ParameterParser parser = (ParameterParser) cl.getConstructor().newInstance();
        parser.init(config.getString(Context.CONTEXT_CONFIG_URLPARSER_CONFIG));
        parser.setContext(c);
        c.setUrlParamParser(parser);
    }
    String postParserClass = config.getString(Context.CONTEXT_CONFIG_POSTPARSER_CLASS);
    String postParserConfig = config.getString(Context.CONTEXT_CONFIG_POSTPARSER_CONFIG);
    if (postParserClass == null) {
        // Can happen due to a bug in 2.4.0 where is was saved using the wrong name :(
        postParserClass = config.getString(urlParserClass);
        postParserConfig = config.getString(Context.CONTEXT_CONFIG_URLPARSER_CONFIG);
    }
    cl = ExtensionFactory.getAddOnLoader().loadClass(postParserClass);
    if (cl == null) {
        throw new ConfigurationException("Failed to load POST parser for context " + postParserClass);
    } else {
        ParameterParser parser = (ParameterParser) cl.getConstructor().newInstance();
        parser.init(postParserConfig);
        parser.setContext(c);
        c.setPostParamParser(parser);
    }
    for (Object obj : config.getList(Context.CONTEXT_CONFIG_DATA_DRIVEN_NODES)) {
        c.addDataDrivenNodes(new StructuralNodeModifier(obj.toString()));
    }
    model.importContext(c, config);
    c.restructureSiteTree();
    addContext(c);
    saveContext(c);
    return c;
}
Also used : Context(org.zaproxy.zap.model.Context) RecordContext(org.parosproxy.paros.db.RecordContext) Tech(org.zaproxy.zap.model.Tech) TechSet(org.zaproxy.zap.model.TechSet) StandardParameterParser(org.zaproxy.zap.model.StandardParameterParser) ParameterParser(org.zaproxy.zap.model.ParameterParser) StructuralNodeModifier(org.zaproxy.zap.model.StructuralNodeModifier) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)58 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)24 File (java.io.File)18 IOException (java.io.IOException)18 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileInputStream (java.io.FileInputStream)4 FileWriter (java.io.FileWriter)4 Configuration (org.apache.commons.configuration.Configuration)4 FileNotFoundException (java.io.FileNotFoundException)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 SQLException (java.sql.SQLException)2