/** * 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); }
@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"); } }
/** * 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); }
/** * 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); }
private void init() { final StandardELContext context = new StandardELContext(factory); functionMapper = context.getFunctionMapper(); variableMapper = context.getVariableMapper(); } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
public void mapFunction(String prefix, String function, Method method) { getELContext().getFunctionMapper().mapFunction( prefix, function, method); }
/** * 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); }
public void mapFunction(String prefix, String function, Method method) { getELContext().getFunctionMapper().mapFunction( prefix, function, method); }
/** * 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); }
public void mapFunction(String prefix, String function, Method method) { getELContext().getFunctionMapper().mapFunction( prefix, function, method); }
@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"); } }