Package org.springframework.expression

Examples of org.springframework.expression.Expression


    assertTrue((Boolean) expression.getValue(context));
  }

  @Test
  public void testReEvaluationWithDifferentRoot() throws Exception {
    Expression expression = handler.getExpressionParser().parseExpression("#oauth2.isClient()");
    MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(),
        "testNonOauthClient"));
    Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar");
    EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
    assertFalse((Boolean) expression.getValue(context));

    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("foo", true,
        Collections.singleton("read"));

    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(storedOAuth2Request, null);
    EvaluationContext anotherContext = handler.createEvaluationContext(oAuth2Authentication, invocation);
    assertTrue((Boolean) expression.getValue(anotherContext));
  }
View Full Code Here


  public static Boolean evaluateExpression(Object obj, String expression) {
    if (StringUtil.isEmpty(expression))
      return false;
    try {
      ExpressionParser parser = new SpelExpressionParser();
      Expression exp = parser.parseExpression(expression);
      return exp.getValue(obj, Boolean.class);    
    } catch (Exception e) {
      _log.debug("Failed to evaluate expression ["+expression+"] for object ["+obj.getClass()+"].");
      _log.debug(e.getMessage());
      return false;
    }
View Full Code Here

    }

    public PreInvocationAttribute createPreInvocationAttribute(PreFilter preFilter, PreAuthorize preAuthorize) {
        try {
         // TODO: Optimization of permitAll
            Expression preAuthorizeExpression = preAuthorize == null ? parser.parseExpression("permitAll") : parser.parseExpression(preAuthorize.value());
            Expression preFilterExpression = preFilter == null ? null : parser.parseExpression(preFilter.value());
            String filterObject = preFilter == null ? null : preFilter.filterTarget();
            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(PostFilter postFilter, PostAuthorize postAuthorize) {
        try {
            Expression postAuthorizeExpression = postAuthorize == null ? null : parser.parseExpression(postAuthorize.value());
            Expression postFilterExpression = postFilter == null ? null : parser.parseExpression(postFilter.value());

            if (postFilterExpression != null || postAuthorizeExpression != null) {
                return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression);
            }
        } catch (ParseException e) {
View Full Code Here

    private int authorizeUsingAccessExpression(Authentication currentUser) throws JspException {
        // Get web expression
        WebSecurityExpressionHandler handler = getExpressionHandler();

        Expression accessExpression;
        try {
            accessExpression = handler.getExpressionParser().parseExpression(access);

        } catch (ParseException e) {
            throw new JspException(e);
View Full Code Here

    private MethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();

    public boolean before(Authentication authentication, MethodInvocation mi, PreInvocationAttribute attr) {
        PreInvocationExpressionAttribute preAttr = (PreInvocationExpressionAttribute) attr;
        EvaluationContext ctx = expressionHandler.createEvaluationContext(authentication, mi);
        Expression preFilter = preAttr.getFilterExpression();
        Expression preAuthorize = preAttr.getAuthorizeExpression();

        if (preFilter != null) {
            Object filterTarget = findFilterTarget(preAttr.getFilterTarget(), ctx, mi);

            expressionHandler.filter(filterTarget, preFilter, ctx);
View Full Code Here

    public Object after(Authentication authentication, MethodInvocation mi,
            PostInvocationAttribute postAttr, Object returnedObject) throws AccessDeniedException{
        PostInvocationExpressionAttribute pia = (PostInvocationExpressionAttribute) postAttr;
        EvaluationContext ctx = expressionHandler.createEvaluationContext(authentication, mi);
        Expression postFilter = pia.getFilterExpression();
        Expression postAuthorize = pia.getAuthorizeExpression();

        if (postFilter != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Applying PostFilter expression " + postFilter);
            }
View Full Code Here

    private String getId(Synchronized annotation, Method method, EvaluationContext context) {
        return parseIdExpression(method, annotation).getValue(context, String.class);
    }

    private Expression parseConditionExpression(Method method, Synchronized annotation) {
        Expression expression = conditionCache.get(method);
        if (expression == null) {
            expression = parser.parseExpression(annotation.condition());
            conditionCache.put(method, expression);
        }
        return expression;
View Full Code Here

        }
        return expression;
    }

    private Expression parseDiscriminatorExpression(Method method, Synchronized annotation) {
        Expression expression = discriminatorCache.get(method);
        if (expression == null) {
            expression = parser.parseExpression(annotation.discriminator());
            discriminatorCache.put(method, expression);
        }
        return expression;
View Full Code Here

        }
        return expression;
    }

    private Expression parseIdExpression(Method method, Synchronized annotation) {
        Expression expression = idCache.get(method);
        if (expression == null) {
            expression = parser.parseExpression(annotation.id());
            idCache.put(method, expression);
        }
        return expression;
View Full Code Here

TOP

Related Classes of org.springframework.expression.Expression

Copyright © 2018 www.massapicom. 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.