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;
}
}
}
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);
}
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;
}
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;
}
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;
}
}
Aggregations