Search in sources :

Example 31 with ExpressionFactory

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExpressionFactory(javax.el.ExpressionFactory) IOException(java.io.IOException) FacesException(javax.faces.FacesException) ELException(javax.el.ELException) FacesException(javax.faces.FacesException) StringTokenizer(java.util.StringTokenizer) ValueExpression(javax.el.ValueExpression)

Example 32 with ExpressionFactory

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);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) Test(org.junit.Test)

Example 33 with ExpressionFactory

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);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) Test(org.junit.Test)

Example 34 with ExpressionFactory

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);
    }
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) GetClassLoader(org.hibernate.validator.internal.util.privilegedactions.GetClassLoader) SetContextClassLoader(org.hibernate.validator.internal.util.privilegedactions.SetContextClassLoader)

Example 35 with ExpressionFactory

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);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) Test(org.junit.Test)

Aggregations

ExpressionFactory (javax.el.ExpressionFactory)39 ValueExpression (javax.el.ValueExpression)28 Test (org.junit.Test)24 ELContext (javax.el.ELContext)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ELException (javax.el.ELException)4 ValueReference (javax.el.ValueReference)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 FacesException (javax.faces.FacesException)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 SimpleContext (de.odysseus.el.util.SimpleContext)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ELResolver (javax.el.ELResolver)1 ServletContextEvent (javax.servlet.ServletContextEvent)1