use of javax.el.ExpressionFactory in project rubia-forums by flashboss.
the class ACLWhenTagHandler method isAllowed.
/**
* @param ctx
* the context to check
* @return true is the passed context is allowed
*/
public boolean isAllowed(FaceletContext ctx) {
boolean isAllowed = false;
FacesContext facesContext = ctx.getFacesContext();
ForumsACLProvider forumsACLProvider = (ForumsACLProvider) forumsACLProviderAttr.getObject(ctx);
UserModule userModule = (UserModule) userModuleAttr.getObject(ctx);
// make sure an authorization provider has been hooked in
boolean skipAuth = false;
try {
if (forumsACLProvider == null) {
// no authorization will be enforced
skipAuth = true;
}
} catch (Exception e) {
// something went wrong in the Authorization system
skipAuth = true;
}
if (skipAuth) {
isAllowed = true;
return isAllowed;
}
// authorization
try {
String resource = fragment.getValue();
String contextStr = null;
if (contextData != null) {
contextStr = contextData.getValue();
}
// resourcesetup
Object[] runtime = null;
if (contextStr != null && contextStr.trim().length() > 0) {
StringTokenizer st = new StringTokenizer(contextStr, ",");
runtime = new Object[st.countTokens()];
int i = 0;
while (st.hasMoreTokens()) {
String parameter = st.nextToken();
Object parameterValue = null;
// evaluate this expression to a value
ExpressionFactory f = ctx.getExpressionFactory();
ValueExpression expr = f.createValueExpression(ctx, parameter, Object.class);
parameterValue = expr.getValue(facesContext.getELContext());
runtime[i++] = parameterValue;
}
}
// check access here
UIContext securityContext = new UIContext(getUser(userModule));
securityContext.setFragment(resource);
securityContext.setContextData(runtime);
// feed this context to the Authorization system which will decide
// whether
// access should be granted or not
isAllowed = forumsACLProvider.hasAccess(securityContext);
} catch (NoSuchMethodException nsme) {
throw new FacesException(nsme);
} catch (Exception e) {
throw new FacesException(e);
}
return isAllowed;
}
use of javax.el.ExpressionFactory in project core by weld.
the class ELResolverTest method testResolveBeanPropertyOfNamedBean.
/**
* Test that the WeldELResolver only works to resolve the base of an EL
* expression, in this case a named bean. Once the base is resolved, the
* remainder of the expression should be delegated to the standard chain of
* property resolvers. If the WeldELResolver oversteps its bounds by
* trying to resolve the property against the Weld namespace, the test
* will fail.
*/
@Test
public void testResolveBeanPropertyOfNamedBean() {
ELContext elContext = EL.createELContext(beanManager);
ExpressionFactory exprFactory = EL.EXPRESSION_FACTORY;
Object value = exprFactory.createValueExpression(elContext, "#{beer.style}", String.class).getValue(elContext);
Assert.assertEquals("Belgium Strong Dark Ale", value);
}
use of javax.el.ExpressionFactory in project core by weld.
the class ELResolverTest method testResolveNormalScopedBean.
// WELD-874
@Test
public void testResolveNormalScopedBean() {
ELContext elContext = EL.createELContext(beanManager);
ExpressionFactory exprFactory = EL.EXPRESSION_FACTORY;
Lager value1 = (Lager) exprFactory.createValueExpression(elContext, "#{lager}", Lager.class).getValue(elContext);
value1.drink();
Lager value2 = (Lager) exprFactory.createValueExpression(elContext, "#{lager}", Lager.class).getValue(elContext);
value2.drink();
Lager value3 = (Lager) exprFactory.createValueExpression(elContext, "#{lager}", Lager.class).getValue(elContext);
value3.drink();
assertEquals(value1, value2);
assertEquals(value2, value3);
}
use of javax.el.ExpressionFactory in project vertx-zero by silentbalanceyh.
the class ValidatorInterpolator method buildExpressionFactory.
private static ExpressionFactory buildExpressionFactory() {
if (canLoadExpressionFactory()) {
final ExpressionFactory expressionFactory = ELManager.getExpressionFactory();
LOGGER.debug("Loaded expression factory via original TCCL");
return expressionFactory;
} else {
final ClassLoader originalContextClassLoader = (ClassLoader) run(GetClassLoader.fromContext());
try {
run(SetContextClassLoader.action(ResourceBundleMessageInterpolator.class.getClassLoader()));
final ExpressionFactory expressionFactory;
final ExpressionFactory var2;
if (canLoadExpressionFactory()) {
expressionFactory = ELManager.getExpressionFactory();
LOGGER.debug("Loaded expression factory via HV classloader");
var2 = expressionFactory;
return var2;
}
run(SetContextClassLoader.action(ELManager.class.getClassLoader()));
if (canLoadExpressionFactory()) {
expressionFactory = ELManager.getExpressionFactory();
LOGGER.debug("Loaded expression factory via EL classloader");
var2 = expressionFactory;
return var2;
}
} catch (final Throwable var6) {
// throw LOG.getUnableToInitializeELExpressionFactoryException(var6);
LOGGER.jvm(var6);
throw var6;
} finally {
run(SetContextClassLoader.action(originalContextClassLoader));
}
throw new RuntimeException("[ ZERO ] Expression Factory error.");
// throw LOG.getUnableToInitializeELExpressionFactoryException((Throwable) null);
}
}
use of javax.el.ExpressionFactory in project wildfly-camel by wildfly-extras.
the class ExpressionFactoryTest method testStatelessSessionBean.
@Test
public void testStatelessSessionBean() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
ExpressionFactory factory = ExpressionFactory.newInstance();
Assert.assertNotNull("Factory not null", factory);
}
Aggregations