Search in sources :

Example 6 with HierarchicalConfiguration

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

the class BaseZapAddOnXmlData method readExtensionsWithDeps.

private List<ExtensionWithDeps> readExtensionsWithDeps(HierarchicalConfiguration currentNode) {
    List<HierarchicalConfiguration> extensions = currentNode.configurationsAt(EXTENSIONS_V1_ALL_ELEMENTS);
    if (extensions.isEmpty()) {
        return Collections.emptyList();
    }
    List<ExtensionWithDeps> extensionsWithDeps = new ArrayList<>(extensions.size());
    for (HierarchicalConfiguration extensionNode : extensions) {
        String classname = extensionNode.getString(EXTENSION_CLASS_NAME, "");
        if (classname.isEmpty()) {
            malformedFile("a v1 extension has empty \"" + EXTENSION_CLASS_NAME + "\".");
        }
        List<HierarchicalConfiguration> fields = extensionNode.configurationsAt(EXTENSION_DEPENDENCIES);
        if (fields.isEmpty()) {
            // Extension v1 without dependencies, handle as normal extension.
            if (this.extensions.isEmpty()) {
                // Empty thus Collections.emptyList(), create and use a mutable list.
                this.extensions = new ArrayList<>(5);
            }
            this.extensions.add(classname);
            continue;
        }
        List<AddOnDep> addOnDeps = readAddOnDependencies(fields);
        AddOnClassnames classnames = readAddOnClassnames(extensionNode);
        extensionsWithDeps.add(new ExtensionWithDeps(classname, addOnDeps, classnames));
    }
    return extensionsWithDeps;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 7 with HierarchicalConfiguration

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

the class BaseZapAddOnXmlData method readAddOnDependencies.

private List<AddOnDep> readAddOnDependencies(List<HierarchicalConfiguration> fields) {
    List<AddOnDep> addOns = new ArrayList<>(fields.size());
    for (HierarchicalConfiguration sub : fields) {
        String id = sub.getString(ZAPADDON_ID_ELEMENT, "");
        if (id.isEmpty()) {
            malformedFile("an add-on dependency has empty \"" + ZAPADDON_ID_ELEMENT + "\".");
        }
        AddOnDep addOnDep = new AddOnDep(id, sub.getString(ZAPADDON_NOT_BEFORE_VERSION_ELEMENT, ""), sub.getString(ZAPADDON_NOT_FROM_VERSION_ELEMENT, ""), sub.getString(ZAPADDON_SEMVER_ELEMENT, ""));
        addOns.add(addOnDep);
    }
    return addOns;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 8 with HierarchicalConfiguration

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

the class ConnectionParam method setProxyExcludedDomains.

/**
     * Sets the domains that will be excluded from the outgoing proxy.
     * 
     * @param proxyExcludedDomains the domains that will be excluded.
     * @since 2.3.0
     * @see #getProxyExcludedDomains()
     * @see #getProxyExcludedDomainsEnabled()
     */
public void setProxyExcludedDomains(List<DomainMatcher> proxyExcludedDomains) {
    if (proxyExcludedDomains == null || proxyExcludedDomains.isEmpty()) {
        ((HierarchicalConfiguration) getConfig()).clearTree(ALL_PROXY_EXCLUDED_DOMAINS_KEY);
        this.proxyExcludedDomains = Collections.emptyList();
        this.proxyExcludedDomainsEnabled = Collections.emptyList();
        return;
    }
    this.proxyExcludedDomains = new ArrayList<>(proxyExcludedDomains);
    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_PROXY_EXCLUDED_DOMAINS_KEY);
    int size = proxyExcludedDomains.size();
    ArrayList<DomainMatcher> enabledExcludedDomains = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        String elementBaseKey = ALL_PROXY_EXCLUDED_DOMAINS_KEY + "(" + i + ").";
        DomainMatcher excludedDomain = proxyExcludedDomains.get(i);
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_VALUE_KEY, excludedDomain.getValue());
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_REGEX_KEY, Boolean.valueOf(excludedDomain.isRegex()));
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_ENABLED_KEY, Boolean.valueOf(excludedDomain.isEnabled()));
        if (excludedDomain.isEnabled()) {
            enabledExcludedDomains.add(excludedDomain);
        }
    }
    enabledExcludedDomains.trimToSize();
    this.proxyExcludedDomainsEnabled = enabledExcludedDomains;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Example 9 with HierarchicalConfiguration

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

the class PassiveScanParam method parse.

@Override
protected void parse() {
    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_AUTO_TAG_SCANNERS_KEY);
        this.autoTagScanners = new ArrayList<>(fields.size());
        List<String> tempListNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(AUTO_TAG_SCANNER_NAME_KEY, "");
            if (!"".equals(name) && !tempListNames.contains(name)) {
                tempListNames.add(name);
                RegexAutoTagScanner app = new RegexAutoTagScanner(sub.getString(AUTO_TAG_SCANNER_NAME_KEY), RegexAutoTagScanner.TYPE.valueOf(sub.getString(AUTO_TAG_SCANNER_TYPE_KEY)), sub.getString(AUTO_TAG_SCANNER_CONFIG_KEY), sub.getString(AUTO_TAG_SCANNER_REQ_URL_REGEX_KEY), sub.getString(AUTO_TAG_SCANNER_REQ_HEAD_REGEX_KEY), sub.getString(AUTO_TAG_SCANNER_RES_HEAD_REGEX_KEY), sub.getString(AUTO_TAG_SCANNER_RES_BODY_REGEX_KEY), sub.getBoolean(AUTO_TAG_SCANNER_ENABLED_KEY, true));
                autoTagScanners.add(app);
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading the auto tag scanners: " + e.getMessage(), e);
    }
    try {
        this.confirmRemoveAutoTagScanner = getConfig().getBoolean(CONFIRM_REMOVE_AUTO_TAG_SCANNER_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove option: " + e.getMessage(), e);
    }
    try {
        this.scanOnlyInScope = getConfig().getBoolean(SCAN_ONLY_IN_SCOPE_KEY, false);
    } catch (ConversionException e) {
        logger.error("Error while loading \"scanOnlyInScope\" option: " + e.getMessage(), e);
    }
}
Also used : RegexAutoTagScanner(org.zaproxy.zap.extension.pscan.scanner.RegexAutoTagScanner) ConversionException(org.apache.commons.configuration.ConversionException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 10 with HierarchicalConfiguration

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

the class PluginPassiveScanner method saveTo.

public void saveTo(Configuration conf) {
    boolean removed = false;
    List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(PSCANS_KEY);
    for (HierarchicalConfiguration sub : fields) {
        if (isPluginConfiguration(sub)) {
            sub.getRootNode().getParentNode().removeChild(sub.getRootNode());
            removed = true;
            break;
        }
    }
    boolean persistId = false;
    String entryKey = PSCANS_KEY + "(" + (removed ? fields.size() - 1 : fields.size()) + ").";
    if (getLevel() != AlertThreshold.MEDIUM) {
        conf.setProperty(entryKey + LEVEL_KEY, getLevel().name());
        persistId = true;
    }
    if (!isEnabled()) {
        conf.setProperty(entryKey + ENABLED_KEY, Boolean.FALSE);
        persistId = true;
    }
    if (persistId) {
        conf.setProperty(entryKey + ID_KEY, getPluginId());
    }
}
Also used : 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