use of org.springframework.expression.ParseException in project engine by craftercms.
the class ConfigAwareUrlAccessRestrictionCheckingProcessor method getUrlRestrictions.
@Override
@SuppressWarnings("unchecked")
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.springframework.expression.ParseException in project spring-security by spring-projects.
the class ExpressionBasedAnnotationAttributeFactory method createPostInvocationAttribute.
public PostInvocationAttribute createPostInvocationAttribute(String postFilterAttribute, String postAuthorizeAttribute) {
try {
ExpressionParser parser = getParser();
Expression postAuthorizeExpression = postAuthorizeAttribute == null ? null : parser.parseExpression(postAuthorizeAttribute);
Expression postFilterExpression = postFilterAttribute == null ? null : parser.parseExpression(postFilterAttribute);
if (postFilterExpression != null || postAuthorizeExpression != null) {
return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression);
}
} catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
}
return null;
}
use of org.springframework.expression.ParseException in project spring-security by spring-projects.
the class ExpressionBasedFilterInvocationSecurityMetadataSource method processMap.
private static LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> processMap(LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap, ExpressionParser parser) {
Assert.notNull(parser, "SecurityExpressionHandler returned a null parser object");
LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestToExpressionAttributesMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>(requestMap);
for (Map.Entry<RequestMatcher, Collection<ConfigAttribute>> entry : requestMap.entrySet()) {
RequestMatcher request = entry.getKey();
Assert.isTrue(entry.getValue().size() == 1, "Expected a single expression attribute for " + request);
ArrayList<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(1);
String expression = entry.getValue().toArray(new ConfigAttribute[1])[0].getAttribute();
logger.debug("Adding web access control expression '" + expression + "', for " + request);
AbstractVariableEvaluationContextPostProcessor postProcessor = createPostProcessor(request);
try {
attributes.add(new WebExpressionConfigAttribute(parser.parseExpression(expression), postProcessor));
} catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '" + expression + "'");
}
requestToExpressionAttributesMap.put(request, attributes);
}
return requestToExpressionAttributesMap;
}
use of org.springframework.expression.ParseException in project spring-security by spring-projects.
the class AbstractAuthorizeTag method authorizeUsingAccessExpression.
/**
* Make an authorization decision based on a Spring EL expression. See the
* "Expression-Based Access Control" chapter in Spring Security for details on what
* expressions can be used.
*
* @return the result of the authorization decision
* @throws IOException
*/
public boolean authorizeUsingAccessExpression() throws IOException {
if (SecurityContextHolder.getContext().getAuthentication() == null) {
return false;
}
SecurityExpressionHandler<FilterInvocation> handler = getExpressionHandler();
Expression accessExpression;
try {
accessExpression = handler.getExpressionParser().parseExpression(getAccess());
} catch (ParseException e) {
IOException ioException = new IOException();
ioException.initCause(e);
throw ioException;
}
return ExpressionUtils.evaluateAsBoolean(accessExpression, createExpressionEvaluationContext(handler));
}
use of org.springframework.expression.ParseException in project scheduling by ow2-proactive.
the class SPELParserValidator method createValidator.
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
String spelRegexp = "^" + SPEL_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
String spelString = parseAndGetOneGroup(model, spelRegexp);
try {
return new SpelValidator(spelString);
} catch (ParseException e) {
throw new ModelSyntaxException(e.getMessage(), e);
}
}
Aggregations