Refine search
@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"); } }
/** * Register an evaluation listener. * * @param listener The evaluation listener to be added. */ public void addEvaluationListener(EvaluationListener listener) { getELContext().addEvaluationListener(listener); } }
/** * Import a static field or method. The class of the static member must be * loadable from the classloader, at class resolution time. * @param staticMemberName The full class name of the class to be imported * @throws ELException if the name is not a full class name. */ public void importStatic(String staticMemberName) throws ELException { getELContext().getImportHandler().importStatic(staticMemberName); }
/** * Add an user defined ELResolver to the list of ELResolvers. * Can be called multiple times. The new ELResolver is * placed ahead of the default ELResolvers. The list of the ELResolvers * added this way are ordered chronologically. * * @param elr The ELResolver to be added to the list of ELResolvers in * ELContext. * @see StandardELContext#addELResolver */ public void addELResolver(ELResolver elr) { getELContext().addELResolver(elr); }
/** * 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); }
/** * Maps a static method to an EL function. * @param prefix The namespace of the functions, can be "". * @param function The name of the function. * @param meth The static method to be invoked when the function is used. */ public void mapFunction(String prefix, String function, Method meth) { getELContext().getFunctionMapper().mapFunction(prefix, function, meth); }
/** * Import a class. The imported class must be loadable from the classloader * at the expression evaluation time. * @param className The full class name of the class to be imported * @throws ELException if the name is not a full class name. */ public void importClass(String className) throws ELException { getELContext().getImportHandler().importClass(className); }
/** * Import a package. At the expression evaluation time, the imported package * name will be used to construct the full class name, which will then be * used to load the class. Inherently, this is less efficient than * importing a class. * @param packageName The package name to be imported */ public void importPackage(String packageName) { getELContext().getImportHandler().importPackage(packageName); }
/** * Define a bean in the local bean repository * @param name The name of the bean * @param bean The bean instance to be defined. If null, the definition * of the bean is removed. */ public Object defineBean(String name, Object bean) { Object ret = getELContext().getBeans().get(name); getELContext().getBeans().put(name, bean); return ret; }
/** * Return the ELContext used for parsing and evaluating EL expressions. * If there is currently no ELContext, a default instance of * StandardELContext is returned. * * @return The ELContext used for parsing and evaluating EL expressions.. */ public StandardELContext getELContext() { if (elContext == null) { elContext = new StandardELContext(getExpressionFactory()); } return elContext; }
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; }
private void init() { final StandardELContext context = new StandardELContext(factory); functionMapper = context.getFunctionMapper(); variableMapper = context.getVariableMapper(); } }
/** * Set the ELContext used for parsing and evaluating EL expressions. * The supplied ELContext will not be modified, except for the context * object map. * @param context The new ELContext. * @return The previous ELContext, null if none. */ public ELContext setELContext(ELContext context) { ELContext prev = elContext; elContext = new StandardELContext(context); return prev; }
public static ELContext createELContext(BeanManagerImpl beanManagerImpl) { StandardELContext context = new StandardELContext(EXPRESSION_FACTORY); context.addELResolver(beanManagerImpl.getELResolver()); callELContextListeners(context); return context; }
StandardELContext context = processor.getELManager().getELContext(); Object part = context.getELResolver().getValue(context, null, partName);
/** * Add a custom ELResolver to the context. The list of the custom * ELResolvers will be accessed in the order they are added. * A custom ELResolver added to the context cannot be removed. * @param cELResolver The new ELResolver to be added to the context */ public void addELResolver(ELResolver cELResolver) { getELResolver(); // make sure elResolver is constructed customResolvers.add(cELResolver); }
/** * Construct a StandardELContext from another ELContext. * @param context The ELContext that acts as a delegate in most cases */ public StandardELContext(ELContext context) { this.delegate = context; // Copy all attributes except map and resolved CompositeELResolver elr = new CompositeELResolver(); elr.add(new BeanNameELResolver(new LocalBeanNameResolver())); customResolvers = new CompositeELResolver(); elr.add(customResolvers); elr.add(context.getELResolver()); elResolver = elr; functionMapper = context.getFunctionMapper(); variableMapper = context.getVariableMapper(); setLocale(context.getLocale()); }
/** * Register a BeanNameResolver. * Construct a BeanNameELResolver with the BeanNameResolver and add it * to the list of ELResolvers. * Once registered, the BeanNameResolver cannot be removed. * @param bnr The BeanNameResolver to be registered. */ public void addBeanNameResolver(BeanNameResolver bnr) { getELContext().addELResolver(new BeanNameELResolver(bnr)); }
/** * 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); }
/** * Maps a static method to an EL function. * @param prefix The namespace of the functions, can be "". * @param function The name of the function. * @param meth The static method to be invoked when the function is used. */ public void mapFunction(String prefix, String function, Method meth) { getELContext().getFunctionMapper().mapFunction(prefix, function, meth); }