Package org.springframework.expression

Examples of org.springframework.expression.EvaluationContext


    Authentication userAuthentication = null;
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
    MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(),
        "testOauthClient"));
    EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
    Expression expression = handler.getExpressionParser().parseExpression(
        "#oauth2.hasScopeMatching('.*_admin:read')");
    assertTrue((Boolean) expression.getValue(context));
    expression = handler.getExpressionParser().parseExpression(
        "#oauth2.hasAnyScopeMatching('.*_admin:write','.*_admin:read')");
 
View Full Code Here


    Authentication userAuthentication = null;
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
    MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(),
        "testOauthClient"));
    EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
    Expression expression = handler.getExpressionParser().parseExpression(
        "#oauth2.hasScopeMatching('.*_admin:write')");
    assertFalse((Boolean) expression.getValue(context));
  }
View Full Code Here

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

  public void testStandardSecurityRoot() throws Exception {
    Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar", null);
    assertTrue(clientAuthentication.isAuthenticated());
    MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(),
        "testStandardSecurityRoot"));
    EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
    Expression expression = handler.getExpressionParser().parseExpression("isAuthenticated()");
    assertTrue((Boolean) expression.getValue(context));
  }
View Full Code Here

  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

            return combinedArgs;
        }

        protected boolean isConditionPassing(Object result) {
            if (StringUtils.hasText(this.operation.getCondition())) {
                EvaluationContext evaluationContext = createEvaluationContext(result);
                return evaluator.condition(this.operation.getCondition(), this.method, evaluationContext);
            }
            return true;
        }
View Full Code Here

                unless = ((CacheableOperation) this.operation).getUnless();
            } else if (this.operation instanceof CachePutOperation) {
                unless = ((CachePutOperation) this.operation).getUnless();
            }
            if (StringUtils.hasText(unless)) {
                EvaluationContext evaluationContext = createEvaluationContext(value);
                return !evaluator.unless(unless, this.method, evaluationContext);
            }
            return true;
        }
View Full Code Here

         *
         * @return generated key (null if none can be generated)
         */
        protected Object generateKey(Object result) {
            if (StringUtils.hasText(this.operation.getKey())) {
                EvaluationContext evaluationContext = createEvaluationContext(result);
                return evaluator.key(this.operation.getKey(), this.method, evaluationContext);
            }
            return keyGenerator.generate(this.target, this.method, this.args);
        }
View Full Code Here

        SpelExpressionParser parser = new SpelExpressionParser();
        expression = parser.parseExpression(el);
    }

    public boolean matches(HttpServletRequest request) {
        EvaluationContext context = createELContext(request);
        return evaluateAsBoolean(expression, context);
    }
View Full Code Here

public class ExpressionBasedPreInvocationAdvice implements PreInvocationAuthorizationAdvice {
    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);
View Full Code Here

TOP

Related Classes of org.springframework.expression.EvaluationContext

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.