/** * {@inheritDoc} */ @Override public void setFunction(String prefix, Method method) { FunctionMapper functions = elContext.getFunctionMapper(); functions.mapFunction(prefix, method.getName(), method); }
/** * {@inheritDoc} */ @Override public void setFunction(String prefix, String name, Method method) { FunctionMapper functions = elContext.getFunctionMapper(); functions.mapFunction(prefix, name, 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); }
@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"); } }
/** * {@inheritDoc} */ @Override public void setFunction(String prefix, Method method) { FunctionMapper functions = elContext.getFunctionMapper(); functions.mapFunction(prefix, method.getName(), method); }
/** * {@inheritDoc} */ @Override public void setFunction(String prefix, String name, Method method) { FunctionMapper functions = elContext.getFunctionMapper(); functions.mapFunction(prefix, name, 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); }
/** * 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); }
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); }
/** * 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); }
@Override public ELPropertyProvider withFunction(String prefix, String localName, Method method) { checkArgument(!Strings.isNullOrEmpty(localName), "A function local name is required"); if (ELPlugin.isLevel3()) { elContext.getFunctionMapper().mapFunction(prefix, localName, method); } else if (ELPlugin.JUEL_CONTEXT_CLASS != null) { if (ELPlugin.JUEL_CONTEXT_CLASS.isAssignableFrom(elContext.getClass())) { try { ELPlugin.JUEL_CONTEXT_CLASS.getMethod("setFunction", String.class, String.class, Method.class).invoke(elContext, prefix, localName, method); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw SeedException.wrap(e, ExpressionLanguageErrorCode.UNEXPECTED_EXCEPTION); } } else { throw new UnsupportedOperationException( "At EL level 2, function mapping is only supported by JUEL SimpleContext"); } } else { throw new UnsupportedOperationException( "Function mapping is not supported in this environment (EL level 3+ or JUEL required)"); } return this; }
public void mapFunction(String prefix, String function, Method method) { getELContext().getFunctionMapper().mapFunction( prefix, function, method); }
@Override public ELPropertyProvider withFunction(String prefix, String localName, Method method) { SeedCheckUtils.checkIf(StringUtils.isNotBlank(localName)); if (ELPlugin.EL3_MAYBE.isPresent()) { elContext.getFunctionMapper().mapFunction(prefix, localName, method); } else if (ELPlugin.JUEL_MAYBE.isPresent()) { if (elContext instanceof SimpleContext) { ((SimpleContext) elContext).setFunction(prefix, localName, method); } else { throw new UnsupportedOperationException("Function mapping is only supported by the default context"); } } else { throw new UnsupportedOperationException("Function mapping is not supported in this environment (EL level 3+ required)"); } return this; }