use of org.craftercms.engine.exception.ConfigurationException 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.craftercms.engine.exception.ConfigurationException in project engine by craftercms.
the class ConfigAwareAccessTokenIdResolver method getAccessTokenId.
@Override
public String getAccessTokenId() {
String accessTokenId = null;
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
if (config != null) {
accessTokenId = config.getString(ACCESS_TOKEN_ID_KEY);
}
if (StringUtils.isNotEmpty(accessTokenId)) {
return accessTokenId;
} else {
throw new ConfigurationException("Current config for site '" + SiteContext.getCurrent().getSiteName() + "' doesn't contain required property " + ACCESS_TOKEN_ID_KEY);
}
}
use of org.craftercms.engine.exception.ConfigurationException in project engine by craftercms.
the class ScriptFilter method getFilterMappings.
protected List<FilterMapping> getFilterMappings() {
final SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
Callback<List<FilterMapping>> callback = new Callback<List<FilterMapping>>() {
@Override
public List<FilterMapping> execute() {
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
CachingAwareList<FilterMapping> mappings = new CachingAwareList<>();
if (config != null) {
List<HierarchicalConfiguration> filtersConfig = config.configurationsAt(FILTER_KEY);
if (CollectionUtils.isNotEmpty(filtersConfig)) {
for (HierarchicalConfiguration filterConfig : filtersConfig) {
String scriptUrl = filterConfig.getString(SCRIPT_KEY);
String[] includes = filterConfig.getStringArray(INCLUDE_MAPPINGS_KEY);
String[] excludes = filterConfig.getStringArray(EXCLUDE_MAPPINGS_KEY);
if (StringUtils.isNotEmpty(scriptUrl) && ArrayUtils.isNotEmpty(includes)) {
ContentStoreService storeService = siteContext.getStoreService();
ScriptFactory scriptFactory = siteContext.getScriptFactory();
if (!storeService.exists(siteContext.getContext(), scriptUrl)) {
throw new ConfigurationException("No filter script found at " + scriptUrl);
}
FilterMapping mapping = new FilterMapping();
mapping.script = scriptFactory.getScript(scriptUrl);
mapping.includes = includes;
mapping.excludes = excludes;
mappings.add(mapping);
mappings.addDependencyKey(mapping.script.getKey());
}
}
}
}
return mappings;
}
};
return cacheTemplate.getObject(siteContext.getContext(), callback, FILTER_MAPPINGS_CACHE_KEY);
} else {
return null;
}
}
Aggregations