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