Example usage for org.apache.commons.configuration HierarchicalConfiguration getString

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration getString.

Prototype

public String getString(String key, String defaultValue) 

Source Link

Usage

From source file:org.zaproxy.zap.extension.pscan.PassiveScanParam.java

@Override
protected void parse() {
    try {// www . j a  v  a2  s .  com
        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);
    }
}

From source file:org.zaproxy.zap.extension.replacer.ReplacerParam.java

@Override
protected void parse() {
    try {/*from   www  . j a  v a 2 s .c  om*/
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_RULES_KEY);
        this.rules = new ArrayList<>(fields.size());
        List<String> tempTokensNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String desc = sub.getString(RULE_DESCRIPTION_KEY, "");
            if (!"".equals(desc) && !tempTokensNames.contains(desc)) {
                boolean enabled = sub.getBoolean(RULE_ENABLED_KEY, true);
                boolean regex = sub.getBoolean(RULE_REGEX_KEY, true);
                String matchStr = sub.getString(RULE_MATCH_STRING_KEY, "");
                MatchType matchType = MatchType.valueOf(
                        sub.getString(RULE_MATCH_TYPE_KEY, MatchType.RESP_BODY_STR.name()).toUpperCase());
                String replace = sub.getString(RULE_REPLACEMENT_KEY, "");
                String initStr = sub.getString(RULE_INITIATORS_KEY, "");
                List<Integer> initList = null;
                if (!StringUtils.isEmpty(initStr)) {
                    initList = new ArrayList<Integer>();
                    String[] initStrArray = initStr.replace("[", "").replace("]", "").split(",");
                    for (String str : initStrArray) {
                        try {
                            initList.add(Integer.parseInt(str.trim()));
                        } catch (NumberFormatException e) {
                            logger.error("Error while loading global repacement rule: " + e.getMessage(), e);
                        }
                    }
                }
                this.rules.add(
                        new ReplacerParamRule(desc, matchType, matchStr, regex, replace, initList, enabled));
                tempTokensNames.add(desc);
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading global repacement rules: " + e.getMessage(), e);
        this.rules = new ArrayList<>(defaultList.size());
    }

    if (this.rules.size() == 0) {
        for (ReplacerParamRule geu : defaultList) {
            this.rules.add(new ReplacerParamRule(geu));
        }
    }

    try {
        this.confirmRemoveToken = getConfig().getBoolean(CONFIRM_REMOVE_RULE_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove rule option: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.extension.script.ScriptParam.java

@Override
protected void parse() {
    defaultScript = getConfig().getString(PARAM_DEFAULT_SCRIPT, "");
    defaultDir = getConfig().getString(PARAM_DEFAULT_DIR, "");

    try {//  w w w  .  ja v  a  2 s.com
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_SCRIPTS_KEY);
        this.scripts = new HashSet<>(fields.size());
        List<String> tempListNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(SCRIPT_NAME_KEY, "");
            try {
                if (!"".equals(name) && !tempListNames.contains(name)) {
                    tempListNames.add(name);

                    File file = new File(sub.getString(SCRIPT_FILE_KEY));
                    if (!file.exists()) {
                        logger.error("Script '" + file.getAbsolutePath() + "' does not exist");
                        continue;
                    }

                    ScriptWrapper script = new ScriptWrapper(sub.getString(SCRIPT_NAME_KEY),
                            sub.getString(SCRIPT_DESC_KEY), sub.getString(SCRIPT_ENGINE_KEY),
                            sub.getString(SCRIPT_TYPE_KEY), sub.getBoolean(SCRIPT_ENABLED_KEY), file);

                    script.setLoadOnStart(true); // Because it was saved ;)

                    scripts.add(script);
                }
            } catch (Exception e) {
                logger.error("Error while loading the script: " + name, e);
            }
        }
    } catch (Exception e) {
        logger.error("Error while loading the scripts: " + e.getMessage(), e);
    }

    try {
        this.scriptDirs = new ArrayList<File>();
        for (Object dirName : getConfig().getList(SCRIPT_DIRS)) {
            File f = new File((String) dirName);
            if (!f.exists() || !f.isDirectory()) {
                logger.error("Not a valid script directory: " + dirName);
            } else {
                scriptDirs.add(f);
            }
        }

    } catch (Exception e) {
        logger.error("Error while loading the script dirs: " + e.getMessage(), e);
    }
    confirmRemoveDir = getConfig().getBoolean(SCRIPT_CONFIRM_REMOVE_DIR, true);

}

From source file:org.zaproxy.zap.extension.spiderAjax.AjaxSpiderParam.java

@Override
protected void parseImpl() {
    try {/*from   w w  w  .j ava  2s  . c o m*/
        this.numberOfBrowsers = getConfig().getInt(NUMBER_OF_BROWSERS_KEY, DEFAULT_NUMBER_OF_BROWSERS);
    } catch (ConversionException e) {
        logger.error("Error while loading the number of browsers: " + e.getMessage(), e);
    }

    try {
        this.maxCrawlDepth = getConfig().getInt(MAX_CRAWL_DEPTH_KEY, DEFAULT_MAX_CRAWL_DEPTH);
    } catch (ConversionException e) {
        logger.error("Error while loading the max crawl depth: " + e.getMessage(), e);
    }

    try {
        this.maxCrawlStates = getConfig().getInt(MAX_CRAWL_STATES_KEY, DEFAULT_CRAWL_STATES);
    } catch (ConversionException e) {
        logger.error("Error while loading max crawl states: " + e.getMessage(), e);
    }

    try {
        this.maxDuration = getConfig().getInt(MAX_DURATION_KEY, DEFAULT_MAX_DURATION);
    } catch (ConversionException e) {
        logger.error("Error while loading the crawl duration: " + e.getMessage(), e);
    }

    try {
        this.eventWait = getConfig().getInt(EVENT_WAIT_TIME_KEY, DEFAULT_EVENT_WAIT_TIME);
    } catch (ConversionException e) {
        logger.error("Error while loading the event wait time: " + e.getMessage(), e);
    }

    try {
        this.reloadWait = getConfig().getInt(RELOAD_WAIT_TIME_KEY, DEFAULT_RELOAD_WAIT_TIME);
    } catch (ConversionException e) {
        logger.error("Error while loading the reload wait time: " + e.getMessage(), e);
    }

    try {
        browserId = getConfig().getString(BROWSER_ID_KEY, DEFAULT_BROWSER_ID);
    } catch (ConversionException e) {
        logger.error("Error while loading the browser id: " + e.getMessage(), e);
        browserId = DEFAULT_BROWSER_ID;
    }
    try {
        Browser.getBrowserWithId(browserId);
    } catch (IllegalArgumentException e) {
        logger.warn("Unknow browser [" + browserId + "] using default [" + DEFAULT_BROWSER_ID + "].", e);
        browserId = DEFAULT_BROWSER_ID;
    }

    try {
        this.clickDefaultElems = getConfig().getBoolean(CLICK_DEFAULT_ELEMS_KEY, DEFAULT_CLICK_DEFAULT_ELEMS);
    } catch (ConversionException e) {
        logger.error("Error while loading the click default option: " + e.getMessage(), e);
    }

    try {
        this.clickElemsOnce = getConfig().getBoolean(CLICK_ELEMS_ONCE_KEY, DEFAULT_CLICK_ELEMS_ONCE);
    } catch (ConversionException e) {
        logger.error("Error while loading the click once option: " + e.getMessage(), e);
    }

    try {
        this.randomInputs = getConfig().getBoolean(RANDOM_INPUTS_KEY, DEFAULT_RANDOM_INPUTS);
    } catch (ConversionException e) {
        logger.error("Error while loading the random inputs option: " + e.getMessage(), e);
    }

    try {
        this.showAdvancedDialog = getConfig().getBoolean(SHOW_ADV_OPTIONS_KEY, false);
    } catch (ConversionException e) {
        logger.error("Error while loading the show advanced option: " + e.getMessage(), e);
    }

    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_ELEMS_KEY);
        this.elems = new ArrayList<>(fields.size());
        enabledElemsNames = new ArrayList<>(fields.size());
        List<String> tempElemsNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(ELEM_NAME_KEY, "");
            if (!"".equals(name) && !tempElemsNames.contains(name)) {
                boolean enabled = sub.getBoolean(ELEM_ENABLED_KEY, true);
                this.elems.add(new AjaxSpiderParamElem(name, enabled));
                tempElemsNames.add(name);
                if (enabled) {
                    enabledElemsNames.add(name);
                }
            }
        }
    } catch (ConversionException e) {
        logger.error("Error while loading clickable elements: " + e.getMessage(), e);
        this.elems = new ArrayList<>(DEFAULT_ELEMS_NAMES.length);
        this.enabledElemsNames = new ArrayList<>(DEFAULT_ELEMS_NAMES.length);
    }

    if (this.elems.size() == 0) {
        for (String elemName : DEFAULT_ELEMS_NAMES) {
            this.elems.add(new AjaxSpiderParamElem(elemName));
            this.enabledElemsNames.add(elemName);
        }
    }

    try {
        this.confirmRemoveElem = getConfig().getBoolean(CONFIRM_REMOVE_ELEM_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove element option: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.spider.SpiderParam.java

private void loadDomainsAlwaysInScope() {
    List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
            .configurationsAt(ALL_DOMAINS_ALWAYS_IN_SCOPE_KEY);
    this.domainsAlwaysInScope = new ArrayList<>(fields.size());
    ArrayList<DomainAlwaysInScopeMatcher> domainsInScopeEnabled = new ArrayList<>(fields.size());
    for (HierarchicalConfiguration sub : fields) {
        String value = sub.getString(DOMAIN_ALWAYS_IN_SCOPE_VALUE_KEY, "");
        if ("".equals(value)) {
            log.warn("Failed to read an spider domain in scope entry, required value is empty.");
        }// ww  w  .  j ava  2 s . c  o  m

        DomainAlwaysInScopeMatcher excludedDomain = null;
        boolean regex = sub.getBoolean(DOMAIN_ALWAYS_IN_SCOPE_REGEX_KEY, false);
        if (regex) {
            try {
                Pattern pattern = DomainAlwaysInScopeMatcher.createPattern(value);
                excludedDomain = new DomainAlwaysInScopeMatcher(pattern);
            } catch (IllegalArgumentException e) {
                log.error("Failed to read an spider domain in scope entry with regex: " + value, e);
            }
        } else {
            excludedDomain = new DomainAlwaysInScopeMatcher(value);
        }

        if (excludedDomain != null) {
            excludedDomain.setEnabled(sub.getBoolean(DOMAIN_ALWAYS_IN_SCOPE_ENABLED_KEY, true));

            domainsAlwaysInScope.add(excludedDomain);

            if (excludedDomain.isEnabled()) {
                domainsInScopeEnabled.add(excludedDomain);
            }
        }
    }

    domainsInScopeEnabled.trimToSize();
    this.domainsAlwaysInScopeEnabled = domainsInScopeEnabled;
}