/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
@Override public void executePolicy(String policyStatement, Errors.Collector collector, ProviderRequest request) { StandardELContext context = new StandardELContext(ef); context.addELResolver(ATTRIBUTE_RESOLVER); FunctionMapper functions = context.getFunctionMapper(); VariableMapper variables = context.getVariableMapper(); customMethods.forEach(customFunction -> functions.mapFunction(customFunction.prefix, customFunction.localName, customFunction.method)); Subject userSubject = request.subject().orElse(SecurityContext.ANONYMOUS); variable(variables, "user", userSubject, Subject.class); variable(variables, "subject", userSubject, Subject.class); variable(variables, "service", request.service().orElse(SecurityContext.ANONYMOUS), Subject.class); variable(variables, "env", request.env(), SecurityEnvironment.class); variable(variables, "object", request.getObject().orElse(null), Object.class); variable(variables, "request", request, ProviderRequest.class); try { ValueExpression expression = ef.createValueExpression(context, policyStatement, boolean.class); boolean value = (boolean) expression.getValue(context); if (!value) { collector.fatal(this, "Policy statement \"" + policyStatement + "\" evaluated to false"); } } catch (Exception e) { collector.fatal(this, "Policy statement \"" + policyStatement + "\" evaluated to an exception " + e.getClass() .getName() + " with message: " + e.getMessage()); LOGGER.log(Level.FINEST, e, () -> "Statement " + policyStatement + " evaluation failed"); } }
private void init() { final StandardELContext context = new StandardELContext(factory); functionMapper = context.getFunctionMapper(); variableMapper = context.getVariableMapper(); } }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
/** * Assign a ValueExpression to an EL variable, replacing * any previous assignment to the same variable. * The assignment for the variable is removed if * the expression is <code>null</code>. * * @param variable The variable name * @param expression The ValueExpression to be assigned * to the variable. */ public void setVariable(String variable, ValueExpression expression) { getELContext().getVariableMapper().setVariable(variable, expression); }
@Override public <T> T eval(ExecutionContext ctx, String expr, Class<T> type) { try { ELResolver r = createResolver(ctx); StandardELContext sc = new StandardELContext(expressionFactory); sc.putContext(ExpressionFactory.class, expressionFactory); sc.addELResolver(r); VariableMapper vm = sc.getVariableMapper(); for (String k : contextVariableNames) { vm.setVariable(k, expressionFactory.createValueExpression(ctx, ExecutionContext.class)); } ValueExpression x = expressionFactory.createValueExpression(sc, expr, type); Object v = x.getValue(sc); return type.cast(v); } catch (Exception e) { log.warn("eval ['{}'] -> error: {}", expr, e.getMessage()); throw e; } }
private StandardELContext createELContext(Context ctx) { ELResolver r = new VariablesResolver(ctx); StandardELContext sc = new StandardELContext(expressionFactory); sc.putContext(ExpressionFactory.class, expressionFactory); sc.addELResolver(r); VariableMapper vm = sc.getVariableMapper(); vm.setVariable(InternalConstants.Context.CONTEXT_KEY, expressionFactory.createValueExpression(ctx, Context.class)); return sc; }
@Override public void executePolicy(String policyStatement, Errors.Collector collector, ProviderRequest request) { StandardELContext context = new StandardELContext(ef); context.addELResolver(ATTRIBUTE_RESOLVER); FunctionMapper functions = context.getFunctionMapper(); VariableMapper variables = context.getVariableMapper(); customMethods.forEach(customFunction -> functions.mapFunction(customFunction.prefix, customFunction.localName, customFunction.method)); Subject userSubject = request.subject().orElse(SecurityContext.ANONYMOUS); variable(variables, "user", userSubject, Subject.class); variable(variables, "subject", userSubject, Subject.class); variable(variables, "service", request.service().orElse(SecurityContext.ANONYMOUS), Subject.class); variable(variables, "env", request.env(), SecurityEnvironment.class); variable(variables, "object", request.getObject().orElse(null), Object.class); variable(variables, "request", request, ProviderRequest.class); try { ValueExpression expression = ef.createValueExpression(context, policyStatement, boolean.class); boolean value = (boolean) expression.getValue(context); if (!value) { collector.fatal(this, "Policy statement \"" + policyStatement + "\" evaluated to false"); } } catch (Exception e) { collector.fatal(this, "Policy statement \"" + policyStatement + "\" evaluated to an exception " + e.getClass() .getName() + " with message: " + e.getMessage()); LOGGER.log(Level.FINEST, e, () -> "Statement " + policyStatement + " evaluation failed"); } }
@Override public void executePolicy(String policyStatement, Errors.Collector collector, ProviderRequest request) { StandardELContext context = new StandardELContext(ef); context.addELResolver(ATTRIBUTE_RESOLVER); FunctionMapper functions = context.getFunctionMapper(); VariableMapper variables = context.getVariableMapper(); customMethods.forEach(customFunction -> functions.mapFunction(customFunction.prefix, customFunction.localName, customFunction.method)); Subject userSubject = request.getSubject().orElse(SecurityContext.ANONYMOUS); variable(variables, "user", userSubject, Subject.class); variable(variables, "subject", userSubject, Subject.class); variable(variables, "service", request.getService().orElse(SecurityContext.ANONYMOUS), Subject.class); variable(variables, "env", request.getEnv(), SecurityEnvironment.class); variable(variables, "object", request.getObject().orElse(null), Object.class); variable(variables, "request", request, ProviderRequest.class); try { ValueExpression expression = ef.createValueExpression(context, policyStatement, boolean.class); boolean value = (boolean) expression.getValue(context); if (!value) { collector.fatal(this, "Policy statement \"" + policyStatement + "\" evaluated to false"); } } catch (Exception e) { collector.fatal(this, "Policy statement \"" + policyStatement + "\" evaluated to an exception " + e.getClass() .getName() + " with message: " + e.getMessage()); LOGGER.log(Level.FINEST, e, () -> "Statement " + policyStatement + " evaluation failed"); } }