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