Search in sources :

Example 21 with HierarchicalConfiguration

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

the class AddOnLoader method loadAddOnsRunState.

private static Map<AddOn, List<String>> loadAddOnsRunState(AddOnCollection addOnCollection) {
    List<HierarchicalConfiguration> savedAddOns = ((HierarchicalConfiguration) Model.getSingleton().getOptionsParam().getConfig()).configurationsAt(ADDONS_RUNNABLE_KEY);
    Map<AddOn, List<String>> runnableAddOns = new HashMap<>();
    for (HierarchicalConfiguration savedAddOn : savedAddOns) {
        AddOn addOn = addOnCollection.getAddOn(savedAddOn.getString(ADDON_RUNNABLE_ID_KEY, ""));
        if (addOn == null) {
            // No longer exists, skip it.
            continue;
        }
        int version = savedAddOn.getInt(ADDON_RUNNABLE_VERSION_KEY, -1);
        if (version == -1 || addOn.getFileVersion() != version) {
            // No version or not the same version, skip it.
            continue;
        }
        List<String> runnableExtensions = new ArrayList<>();
        List<String> currentExtensions = addOn.getExtensionsWithDeps();
        for (String savedExtension : savedAddOn.getStringArray(ADDON_RUNNABLE_ALL_EXTENSIONS_KEY)) {
            if (currentExtensions.contains(savedExtension)) {
                runnableExtensions.add(savedExtension);
            }
        }
        runnableAddOns.put(addOn, runnableExtensions);
    }
    return runnableAddOns;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 22 with HierarchicalConfiguration

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

the class BaseZapAddOnXmlData method readDependencies.

private Dependencies readDependencies(HierarchicalConfiguration currentNode, String element) {
    List<HierarchicalConfiguration> dependencies = currentNode.configurationsAt(DEPENDENCIES_ELEMENT);
    if (dependencies.isEmpty()) {
        return null;
    }
    if (dependencies.size() > 1) {
        malformedFile("expected at most one \"dependencies\" element for \"" + element + "\" element, found " + dependencies.size() + ".");
    }
    HierarchicalConfiguration node = dependencies.get(0);
    String javaVersion = node.getString(DEPENDENCIES_JAVA_VERSION_ELEMENT, "");
    List<HierarchicalConfiguration> fields = node.configurationsAt(DEPENDENCIES_ADDONS_ALL_ELEMENTS);
    if (fields.isEmpty()) {
        return new Dependencies(javaVersion, Collections.<AddOnDep>emptyList());
    }
    List<AddOnDep> addOns = readAddOnDependencies(fields);
    return new Dependencies(javaVersion, addOns);
}
Also used : HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 23 with HierarchicalConfiguration

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

the class HttpSessionsParam method parse.

@Override
protected void parse() {
    // Parse the default token names
    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_DEFAULT_TOKENS_KEY);
        this.defaultTokens = new ArrayList<>(fields.size());
        this.defaultTokensEnabled = new ArrayList<>(fields.size());
        List<String> tempTokensNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(TOKEN_NAME_KEY, "");
            if (!"".equals(name) && !tempTokensNames.contains(name)) {
                boolean enabled = sub.getBoolean(TOKEN_ENABLED_KEY, true);
                this.defaultTokens.add(new HttpSessionToken(name, enabled));
                tempTokensNames.add(name);
                if (enabled) {
                    this.defaultTokensEnabled.add(name);
                }
            }
        }
    } catch (ConversionException e) {
        this.defaultTokens = new ArrayList<>(DEFAULT_TOKENS.length);
        log.error("Error while parsing config file: " + e.getMessage(), e);
    }
    if (this.defaultTokens.size() == 0) {
        for (String tokenName : DEFAULT_TOKENS) {
            this.defaultTokens.add(new HttpSessionToken(tokenName));
            this.defaultTokensEnabled.add(tokenName);
        }
    }
    try {
        this.enabledProxyOnly = getConfig().getBoolean(PROXY_ONLY_KEY, false);
    } catch (ConversionException e) {
        log.error("Error while parsing config file: " + e.getMessage(), e);
    }
    try {
        this.confirmRemove = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
    } catch (ConversionException e) {
        log.error("Error while parsing config file: " + e.getMessage(), e);
    }
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 24 with HierarchicalConfiguration

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

the class PassiveScanParam method setAutoTagScanners.

public void setAutoTagScanners(List<RegexAutoTagScanner> scanners) {
    this.autoTagScanners = scanners;
    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_AUTO_TAG_SCANNERS_KEY);
    for (int i = 0, size = scanners.size(); i < size; ++i) {
        String elementBaseKey = ALL_AUTO_TAG_SCANNERS_KEY + "(" + i + ").";
        RegexAutoTagScanner scanner = scanners.get(i);
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_NAME_KEY, scanner.getName());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_TYPE_KEY, scanner.getType().toString());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_CONFIG_KEY, scanner.getConf());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_REQ_URL_REGEX_KEY, scanner.getRequestUrlRegex());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_REQ_HEAD_REGEX_KEY, scanner.getRequestHeaderRegex());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_RES_HEAD_REGEX_KEY, scanner.getResponseHeaderRegex());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_RES_BODY_REGEX_KEY, scanner.getResponseBodyRegex());
        getConfig().setProperty(elementBaseKey + AUTO_TAG_SCANNER_ENABLED_KEY, Boolean.valueOf(scanner.isEnabled()));
    }
}
Also used : RegexAutoTagScanner(org.zaproxy.zap.extension.pscan.scanner.RegexAutoTagScanner) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 25 with HierarchicalConfiguration

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

the class KeyboardParam method parse.

@Override
protected void parse() {
    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_SHORTCUTS_KEY);
        map = new HashMap<String, KeyStroke>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(MENU_ITEM_KEY, "");
            if (name.length() > 0) {
                map.put(name, KeyStroke.getKeyStroke(sub.getInt(KEYCODE_KEY, 0), sub.getInt(MODIFIERS_KEY, 0), false));
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading keyboard shortcuts " + e.getMessage(), e);
    }
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) KeyStroke(javax.swing.KeyStroke) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Aggregations

HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)34 ArrayList (java.util.ArrayList)17 ConversionException (org.apache.commons.configuration.ConversionException)7 SiteContext (org.craftercms.engine.service.context.SiteContext)6 HashMap (java.util.HashMap)4 DomainMatcher (org.zaproxy.zap.network.DomainMatcher)4 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 ConfigurationException (org.apache.commons.configuration.ConfigurationException)3 SubnodeConfiguration (org.apache.commons.configuration.SubnodeConfiguration)3 Callback (org.craftercms.commons.lang.Callback)3 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)3 GraphConfigurationException (com.tinkerpop.rexster.config.GraphConfigurationException)2 Map (java.util.Map)2 SiteContextCreationException (org.craftercms.engine.exception.SiteContextCreationException)2 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 RegexAutoTagScanner (org.zaproxy.zap.extension.pscan.scanner.RegexAutoTagScanner)2 Neo4j2Graph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)1 Neo4j2HaGraph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2HaGraph)1