Package org.springframework.expression

Examples of org.springframework.expression.ExpressionParser.parseExpression()


public class SpElValueExpressionEvaluator implements ValueExpressionEvaluator {

    /** {@inheritDoc } */
    public Object evaluate(Object context, String expression) {
        final ExpressionParser parser = new SpelExpressionParser();
        return parser.parseExpression(expression).getValue(context);
    }
   
}
View Full Code Here


    public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject, String preAuthorizeAttribute) {
        try {
            // TODO: Optimization of permitAll
            ExpressionParser parser = getParser();
            Expression preAuthorizeExpression = preAuthorizeAttribute == null ? parser.parseExpression("permitAll") : parser.parseExpression(preAuthorizeAttribute);
            Expression preFilterExpression = preFilterAttribute == null ? null : parser.parseExpression(preFilterAttribute);
            return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
        }
View Full Code Here

    public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject, String preAuthorizeAttribute) {
        try {
            // TODO: Optimization of permitAll
            ExpressionParser parser = getParser();
            Expression preAuthorizeExpression = preAuthorizeAttribute == null ? parser.parseExpression("permitAll") : parser.parseExpression(preAuthorizeAttribute);
            Expression preFilterExpression = preFilterAttribute == null ? null : parser.parseExpression(preFilterAttribute);
            return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
        }
View Full Code Here

    public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject, String preAuthorizeAttribute) {
        try {
            // TODO: Optimization of permitAll
            ExpressionParser parser = getParser();
            Expression preAuthorizeExpression = preAuthorizeAttribute == null ? parser.parseExpression("permitAll") : parser.parseExpression(preAuthorizeAttribute);
            Expression preFilterExpression = preFilterAttribute == null ? null : parser.parseExpression(preFilterAttribute);
            return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
        }
    }
View Full Code Here

    }

    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);
            }
View Full Code Here

    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) {
View Full Code Here

        appContext.registerBeanDefinition("role", bean);
        handler.setApplicationContext(appContext);

        EvaluationContext ctx = handler.createEvaluationContext(mock(Authentication.class), mock(FilterInvocation.class));
        ExpressionParser parser = handler.getExpressionParser();
        assertTrue(parser.parseExpression("@role.getAttribute() == 'ROLE_A'").getValue(ctx, Boolean.class));
        assertTrue(parser.parseExpression("@role.attribute == 'ROLE_A'").getValue(ctx, Boolean.class));
    }


    @Test(expected = IllegalArgumentException.class)
View Full Code Here

        handler.setApplicationContext(appContext);

        EvaluationContext ctx = handler.createEvaluationContext(mock(Authentication.class), mock(FilterInvocation.class));
        ExpressionParser parser = handler.getExpressionParser();
        assertTrue(parser.parseExpression("@role.getAttribute() == 'ROLE_A'").getValue(ctx, Boolean.class));
        assertTrue(parser.parseExpression("@role.attribute == 'ROLE_A'").getValue(ctx, Boolean.class));
    }


    @Test(expected = IllegalArgumentException.class)
    public void setTrustResolverNull() {
View Full Code Here

    private final Expression expression;
    private final MapExpressionMethods methods;

    public MapPartitionResolver(String expression, EvaluationContext evaluationContext) {
      ExpressionParser parser = new SpelExpressionParser();
      this.expression = parser.parseExpression(expression);
      this.methods = new MapExpressionMethods(evaluationContext);
      log.info("Using expression=[" + this.expression.getExpressionString() + "]");
    }

    public MapPartitionResolver(Expression expression, EvaluationContext evaluationContext) {
View Full Code Here

    }

    public int vote(Authentication authentication, State object, Collection<ConfigAttribute> attributes) {
        EvaluationContext ctx = expressionHandler.createEvaluationContext(authentication, object);
        ExpressionParser parser = new SpelExpressionParser();
        Expression exp = parser.parseExpression(attributes.iterator().next().getAttribute());
        return ExpressionUtils.evaluateAsBoolean(exp, ctx) ? ACCESS_GRANTED : ACCESS_DENIED;
    }

}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.