Search in sources :

Example 16 with HierarchicalConfiguration

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;
    }
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) Callback(org.craftercms.commons.lang.Callback) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ConfigurationException(org.craftercms.engine.exception.ConfigurationException) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) ParseException(org.springframework.expression.ParseException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 17 with HierarchicalConfiguration

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);
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 18 with HierarchicalConfiguration

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);
    }
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException)

Example 19 with HierarchicalConfiguration

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);
    }
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 20 with HierarchicalConfiguration

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;
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DomainMatcher(org.zaproxy.zap.network.DomainMatcher)

Aggregations

HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)34 ArrayList (java.util.ArrayList)17 ConversionException (org.apache.commons.configuration.ConversionException)7 SiteContext (org.craftercms.engine.service.context.SiteContext)6 HashMap (java.util.HashMap)4 DomainMatcher (org.zaproxy.zap.network.DomainMatcher)4 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 ConfigurationException (org.apache.commons.configuration.ConfigurationException)3 SubnodeConfiguration (org.apache.commons.configuration.SubnodeConfiguration)3 Callback (org.craftercms.commons.lang.Callback)3 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)3 GraphConfigurationException (com.tinkerpop.rexster.config.GraphConfigurationException)2 Map (java.util.Map)2 SiteContextCreationException (org.craftercms.engine.exception.SiteContextCreationException)2 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 RegexAutoTagScanner (org.zaproxy.zap.extension.pscan.scanner.RegexAutoTagScanner)2 Neo4j2Graph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)1 Neo4j2HaGraph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2HaGraph)1