use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.
the class APIUnitTest method shouldDenyHostnameNotSet.
@Test
public void shouldDenyHostnameNotSet() throws Exception {
// Given
API api = new API();
OptionsParamApi apiOptions = new OptionsParamApi();
apiOptions.load(new ZapXmlConfiguration());
apiOptions.setPermittedAddresses(createPermittedAddresses("127.0.0.1", "localhost"));
api.setOptionsParamApi(apiOptions);
TestApiImplementor apiImplementor = new TestApiImplementor();
String requestUri = api.getCallBackUrl(apiImplementor, "http://example.com");
// When
boolean requestHandled = api.handleApiRequest(createApiRequest(new byte[] { 127, 0, 0, 1 }, "example.com", requestUri), createMockedHttpInputStream(), createMockedHttpOutputStream());
// Then
assertThat(requestHandled, is(equalTo(true)));
assertThat(apiImplementor.wasUsed(), is(equalTo(false)));
}
use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.
the class DriverConfiguration method write.
public void write() {
if (file == null) {
fireStateChanged();
return;
}
ZapXmlConfiguration configuration = new ZapXmlConfiguration();
configuration.setRootElementName("driverConfiguration");
for (int i = 0; i < names.size(); i++) {
String baseKey = "driver(" + i + ").";
configuration.setProperty(baseKey + "name", names.get(i));
configuration.setProperty(baseKey + "path", paths.get(i));
configuration.setProperty(baseKey + "slot", slots.get(i).toString());
configuration.setProperty(baseKey + "slotListIndex", slotListIndexes.get(i).toString());
}
try {
configuration.save(file);
} catch (ConfigurationException e) {
logger.error("Failed to save driver configuration to " + file, e);
}
fireStateChanged();
}
use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.
the class DriverConfiguration method load.
private void load() {
names = new Vector<>();
paths = new Vector<>();
slots = new Vector<>();
slotListIndexes = new Vector<>();
try {
ZapXmlConfiguration configuration = file != null ? new ZapXmlConfiguration(file) : new ZapXmlConfiguration(url);
List<HierarchicalConfiguration> drivers = configuration.configurationsAt("driver");
for (HierarchicalConfiguration driver : drivers) {
names.add(driver.getString("name", ""));
paths.add(driver.getString("path", ""));
slots.add(getInt(driver.getString("slot")));
slotListIndexes.add(getInt(driver.getString("slotListIndex")));
}
} catch (ConfigurationException e) {
logger.error("Failed to read the configuration from " + (file != null ? file : url), e);
}
}
use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.
the class Constant method upgradeFrom1_2_0.
private void upgradeFrom1_2_0(XMLConfiguration config) throws ConfigurationException {
// Upgrade the regexs
// ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when
// reading/writing configurations.
XMLConfiguration newConfig = new ZapXmlConfiguration(getUrlDefaultConfigFile());
newConfig.setAutoSave(false);
copyProperty(newConfig, config, "view.brkPanelView");
copyProperty(newConfig, config, "view.showMainToolbar");
}
use of org.zaproxy.zap.utils.ZapXmlConfiguration in project zaproxy by zaproxy.
the class PolicyManager method savePolicy.
public void savePolicy(ScanPolicy policy, String previousName) throws ConfigurationException {
logger.debug("Save policy " + policy.getName());
File file = new File(Constant.getPoliciesDir(), policy.getName() + POLICY_EXTENSION);
ZapXmlConfiguration conf = new ZapXmlConfiguration();
conf.setProperty("policy", policy.getName());
conf.setProperty("scanner.level", policy.getDefaultThreshold().name());
conf.setProperty("scanner.strength", policy.getDefaultStrength().name());
policy.getPluginFactory().saveTo(conf);
conf.save(file);
if (previousName != null && previousName.length() > 0) {
allPolicyNames.remove(previousName);
}
if (!allPolicyNames.contains(policy.getName())) {
allPolicyNames.add(policy.getName());
Collections.sort(allPolicyNames);
}
}
Aggregations