use of org.apache.commons.configuration.HierarchicalConfiguration in project engine by craftercms.
the class ConfigAwareUrlAccessRestrictionCheckingProcessor method getUrlRestrictions.
@Override
protected Map<String, Expression> getUrlRestrictions() {
Callback<Map<String, Expression>> callback = new Callback<Map<String, Expression>>() {
@Override
public Map<String, Expression> execute() {
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
Map<String, Expression> customRestrictions = null;
if (config != null) {
List<HierarchicalConfiguration> restrictionsConfig = config.configurationsAt(URL_RESTRICTION_KEY);
if (CollectionUtils.isNotEmpty(restrictionsConfig)) {
customRestrictions = new LinkedHashMap<>(restrictionsConfig.size());
ExpressionParser parser = new SpelExpressionParser();
for (HierarchicalConfiguration restrictionConfig : restrictionsConfig) {
String url = restrictionConfig.getString(URL_RESTRICTION_URL_KEY);
String expression = restrictionConfig.getString(URL_RESTRICTION_EXPRESSION_KEY);
if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(expression)) {
try {
customRestrictions.put(url, parser.parseExpression(expression));
} catch (ParseException e) {
throw new ConfigurationException(expression + " is not a valid SpEL expression", e);
}
}
}
}
}
if (customRestrictions != null) {
return customRestrictions;
} else {
return urlRestrictions;
}
}
};
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
return cacheTemplate.getObject(siteContext.getContext(), callback, URL_RESTRICTIONS_CACHE_KEY);
} else {
return urlRestrictions;
}
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project engine by craftercms.
the class ToTargetedUrlTransformerTest method setUpCurrentSiteContext.
private void setUpCurrentSiteContext() {
HierarchicalConfiguration config = mock(HierarchicalConfiguration.class);
when(config.getBoolean(TARGETING_ENABLED_CONFIG_KEY, false)).thenReturn(true);
when(config.getStringArray(ROOT_FOLDERS_CONFIG_KEY)).thenReturn(ROOT_FOLDERS);
when(config.getStringArray(EXCLUDE_PATTERNS_CONFIG_KEY)).thenReturn(new String[] { "/site/website/index\\.xml" });
SiteContext siteContext = new SiteContext();
siteContext.setSiteName(SITE_NAME);
siteContext.setConfig(config);
SiteContext.setCurrent(siteContext);
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project orientdb by orientechnologies.
the class OrientGraphConfiguration method configureGraphInstance.
public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException {
final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION);
if (graphFile == null || graphFile.length() == 0) {
throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION);
}
// get the <properties> section of the xml configuration
final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties();
SubnodeConfiguration orientDbSpecificConfiguration;
try {
orientDbSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES);
} catch (IllegalArgumentException iae) {
throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES, iae);
}
try {
final String username = orientDbSpecificConfiguration.getString("username", "");
final String password = orientDbSpecificConfiguration.getString("password", "");
// implementation of shutdown will call the orientdb close method.
return OrientGraphFactory.getTxGraphImplFactory().getGraph(graphFile, username, password);
} catch (Exception ex) {
throw new GraphConfigurationException(ex);
}
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.
the class AntiCsrfParam method parse.
@Override
protected void parse() {
try {
List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_TOKENS_KEY);
this.tokens = new ArrayList<>(fields.size());
enabledTokensNames = 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.tokens.add(new AntiCsrfParamToken(name, enabled));
tempTokensNames.add(name);
if (enabled) {
enabledTokensNames.add(name);
}
}
}
} catch (ConversionException e) {
logger.error("Error while loading anti CSRF tokens: " + e.getMessage(), e);
this.tokens = new ArrayList<>(DEFAULT_TOKENS_NAMES.length);
this.enabledTokensNames = new ArrayList<>(DEFAULT_TOKENS_NAMES.length);
}
if (this.tokens.size() == 0) {
for (String tokenName : DEFAULT_TOKENS_NAMES) {
this.tokens.add(new AntiCsrfParamToken(tokenName));
this.enabledTokensNames.add(tokenName);
}
}
try {
this.confirmRemoveToken = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
} catch (ConversionException e) {
logger.error("Error while loading the confirm remove token option: " + e.getMessage(), e);
}
}
use of org.apache.commons.configuration.HierarchicalConfiguration in project zaproxy by zaproxy.
the class OptionsParamApi method loadPermittedAddresses.
private void loadPermittedAddresses() {
List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ADDRESS_KEY);
this.permittedAddresses = new ArrayList<>(fields.size());
ArrayList<DomainMatcher> addrsEnabled = new ArrayList<>(fields.size());
for (HierarchicalConfiguration sub : fields) {
String value = sub.getString(ADDRESS_VALUE_KEY, "");
if (value.isEmpty()) {
LOGGER.warn("Failed to read a permitted address entry, required value is empty.");
continue;
}
DomainMatcher addr = null;
boolean regex = sub.getBoolean(ADDRESS_REGEX_KEY, false);
if (regex) {
try {
Pattern pattern = DomainMatcher.createPattern(value);
addr = new DomainMatcher(pattern);
} catch (IllegalArgumentException e) {
LOGGER.error("Failed to read a permitted address entry with regex: " + value, e);
}
} else {
addr = new DomainMatcher(value);
}
if (addr != null) {
addr.setEnabled(sub.getBoolean(ADDRESS_ENABLED_KEY, true));
permittedAddresses.add(addr);
if (addr.isEnabled()) {
addrsEnabled.add(addr);
}
}
}
addrsEnabled.trimToSize();
if (permittedAddresses.size() == 0) {
// None specified - add in the defaults (which can then be disabled)
DomainMatcher addr = new DomainMatcher("127.0.0.1");
permittedAddresses.add(addr);
addrsEnabled.add(addr);
addr = new DomainMatcher("localhost");
permittedAddresses.add(addr);
addrsEnabled.add(addr);
addr = new DomainMatcher("zap");
permittedAddresses.add(addr);
addrsEnabled.add(addr);
}
this.permittedAddressesEnabled = addrsEnabled;
}
Aggregations