Search in sources :

Example 11 with HierarchicalConfiguration

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

the class PluginPassiveScanner method loadFrom.

public void loadFrom(Configuration conf) {
    List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(PSCANS_KEY);
    for (HierarchicalConfiguration sub : fields) {
        if (isPluginConfiguration(sub)) {
            setLevel(AlertThreshold.valueOf(sub.getString(LEVEL_KEY, AlertThreshold.DEFAULT.name())));
            setEnabled(sub.getBoolean(ENABLED_KEY, true));
            break;
        }
    }
}
Also used : HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 12 with HierarchicalConfiguration

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

the class ScriptParam method parse.

@Override
protected void parse() {
    defaultScript = getConfig().getString(PARAM_DEFAULT_SCRIPT, "");
    defaultDir = getConfig().getString(PARAM_DEFAULT_DIR, "");
    try {
        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);
                    // Because it was saved ;)
                    script.setLoadOnStart(true);
                    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);
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) File(java.io.File)

Example 13 with HierarchicalConfiguration

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

the class SpiderParam method loadDomainsAlwaysInScope.

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.");
        }
        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;
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 14 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project engine by craftercms.

the class ConfigurationScriptJobResolver method resolveJobs.

@Override
public List<JobContext> resolveJobs(SiteContext siteContext) throws SchedulingException {
    HierarchicalConfiguration config = siteContext.getConfig();
    List<JobContext> jobContexts = new ArrayList<>();
    if (config != null) {
        List<HierarchicalConfiguration> jobFoldersConfig = config.configurationsAt(JOB_FOLDER_KEY);
        if (CollectionUtils.isNotEmpty(jobFoldersConfig)) {
            for (HierarchicalConfiguration jobFolderConfig : jobFoldersConfig) {
                List<JobContext> folderJobContexts = getJobsUnderFolder(siteContext, jobFolderConfig);
                if (CollectionUtils.isNotEmpty(folderJobContexts)) {
                    jobContexts.addAll(folderJobContexts);
                }
            }
        }
        List<HierarchicalConfiguration> jobsConfig = config.configurationsAt(JOB_KEY);
        if (CollectionUtils.isNotEmpty(jobsConfig)) {
            for (HierarchicalConfiguration jobConfig : jobsConfig) {
                JobContext jobContext = getJob(siteContext, jobConfig);
                if (jobContext != null) {
                    jobContexts.add(jobContext);
                }
            }
        }
    }
    return jobContexts;
}
Also used : ArrayList(java.util.ArrayList) JobContext(org.craftercms.engine.util.quartz.JobContext) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 15 with HierarchicalConfiguration

use of org.apache.commons.configuration.HierarchicalConfiguration in project engine by craftercms.

the class SiteContextFactory method createContext.

public SiteContext createContext(String siteName) {
    Map<String, String> macroValues = Collections.singletonMap(siteNameMacroName, siteName);
    String resolvedRootFolderPath = macroResolver.resolveMacros(rootFolderPath, macroValues);
    Context context = storeService.createContext(storeType, storeServerUrl, username, password, resolvedRootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
    try {
        SiteContext siteContext = new SiteContext();
        siteContext.setStoreService(storeService);
        siteContext.setSiteName(siteName);
        siteContext.setContext(context);
        siteContext.setStaticAssetsPath(staticAssetsPath);
        siteContext.setTemplatesPath(templatesPath);
        siteContext.setFreeMarkerConfig(freeMarkerConfigFactory.getObject());
        siteContext.setUrlTransformationEngine(urlTransformationEngine);
        siteContext.setOverlayCallback(overlayCallback);
        siteContext.setRestScriptsPath(restScriptsPath);
        siteContext.setControllerScriptsPath(controllerScriptsPath);
        String[] resolvedConfigPaths = new String[configPaths.length];
        for (int i = 0; i < configPaths.length; i++) {
            resolvedConfigPaths[i] = macroResolver.resolveMacros(configPaths[i], macroValues);
        }
        String[] resolvedAppContextPaths = new String[applicationContextPaths.length];
        for (int i = 0; i < applicationContextPaths.length; i++) {
            resolvedAppContextPaths[i] = macroResolver.resolveMacros(applicationContextPaths[i], macroValues);
        }
        ResourceLoader resourceLoader = new ContentStoreResourceLoader(siteContext);
        HierarchicalConfiguration config = getConfig(siteContext, resolvedConfigPaths, resourceLoader);
        URLClassLoader classLoader = getClassLoader(siteContext);
        ScriptFactory scriptFactory = getScriptFactory(siteContext, classLoader);
        ConfigurableApplicationContext appContext = getApplicationContext(siteContext, classLoader, config, resolvedAppContextPaths, resourceLoader);
        siteContext.setConfigPaths(resolvedConfigPaths);
        siteContext.setApplicationContextPaths(resolvedAppContextPaths);
        siteContext.setGroovyClassesPath(groovyClassesPath);
        siteContext.setScriptFactory(scriptFactory);
        siteContext.setConfig(config);
        siteContext.setApplicationContext(appContext);
        siteContext.setClassLoader(classLoader);
        executeInitScript(siteContext, scriptFactory);
        Scheduler scheduler = scheduleJobs(siteContext);
        siteContext.setScheduler(scheduler);
        return siteContext;
    } catch (Exception e) {
        // Destroy context if the site context creation failed
        storeService.destroyContext(context);
        throw e;
    }
}
Also used : JobContext(org.craftercms.engine.util.quartz.JobContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Context(org.craftercms.core.service.Context) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ServletContext(javax.servlet.ServletContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ContentStoreGroovyResourceLoader(org.craftercms.engine.util.groovy.ContentStoreGroovyResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) ContentStoreResourceLoader(org.craftercms.engine.util.spring.ContentStoreResourceLoader) Scheduler(org.quartz.Scheduler) ContentStoreResourceLoader(org.craftercms.engine.util.spring.ContentStoreResourceLoader) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) BeansException(org.springframework.beans.BeansException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) URLClassLoader(java.net.URLClassLoader) GroovyScriptFactory(org.craftercms.engine.scripting.impl.GroovyScriptFactory) ScriptFactory(org.craftercms.engine.scripting.ScriptFactory)

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