Search in sources :

Example 11 with ELResolver

use of javax.el.ELResolver in project tomcat70 by apache.

the class AstValue method getTarget.

private final Target getTarget(EvaluationContext ctx) throws ELException {
    // evaluate expr-a to value-a
    Object base = this.children[0].getValue(ctx);
    // if our base is null (we know there are more properties to evaluate)
    if (base == null) {
        throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.base", this.children[0].getImage()));
    }
    // set up our start/end
    Object property = null;
    int propCount = this.jjtGetNumChildren();
    int i = 1;
    // Evaluate any properties or methods before our target
    ELResolver resolver = ctx.getELResolver();
    while (i < propCount) {
        if (i + 2 < propCount && this.children[i + 1] instanceof AstMethodParameters) {
            // Method call not at end of expression
            base = resolver.invoke(ctx, base, this.children[i].getValue(ctx), null, ((AstMethodParameters) this.children[i + 1]).getParameters(ctx));
            i += 2;
        } else if (i + 2 == propCount && this.children[i + 1] instanceof AstMethodParameters) {
            // Method call at end of expression
            ctx.setPropertyResolved(false);
            property = this.children[i].getValue(ctx);
            i += 2;
            if (property == null) {
                throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
            }
        } else if (i + 1 < propCount) {
            // Object with property not at end of expression
            property = this.children[i].getValue(ctx);
            ctx.setPropertyResolved(false);
            base = resolver.getValue(ctx, base, property);
            i++;
        } else {
            // Object with property at end of expression
            ctx.setPropertyResolved(false);
            property = this.children[i].getValue(ctx);
            i++;
            if (property == null) {
                throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
            }
        }
        if (base == null) {
            throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
        }
    }
    Target t = new Target();
    t.base = base;
    t.property = property;
    return t;
}
Also used : PropertyNotFoundException(javax.el.PropertyNotFoundException) ELResolver(javax.el.ELResolver)

Example 12 with ELResolver

use of javax.el.ELResolver in project tomcat70 by apache.

the class JspApplicationContextImpl method createELContext.

public ELContextImpl createELContext(JspContext context) {
    if (context == null) {
        throw new IllegalArgumentException("JspContext was null");
    }
    // create ELContext for JspContext
    final ELResolver r = this.createELResolver();
    ELContextImpl ctx;
    if (Constants.IS_SECURITY_ENABLED) {
        ctx = AccessController.doPrivileged(new PrivilegedAction<ELContextImpl>() {

            @Override
            public ELContextImpl run() {
                return new ELContextImpl(r);
            }
        });
    } else {
        ctx = new ELContextImpl(r);
    }
    ctx.putContext(JspContext.class, context);
    // alert all ELContextListeners
    ELContextEvent event = new ELContextEvent(ctx);
    for (int i = 0; i < this.contextListeners.size(); i++) {
        this.contextListeners.get(i).contextCreated(event);
    }
    return ctx;
}
Also used : ELResolver(javax.el.ELResolver) JasperELResolver(org.apache.jasper.el.JasperELResolver) CompositeELResolver(javax.el.CompositeELResolver) PrivilegedAction(java.security.PrivilegedAction) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELContextEvent(javax.el.ELContextEvent)

Example 13 with ELResolver

use of javax.el.ELResolver in project tomee by apache.

the class OpenEJBLifecycle method initializeServletContext.

public static void initializeServletContext(final ServletContext servletContext, final WebBeansContext context) {
    if (context == null || !context.getBeanManagerImpl().isInUse()) {
        return;
    }
    final ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
    final ELResolver resolver = elAdaptor.getOwbELResolver();
    // Application is configured as JSP
    if (context.getOpenWebBeansConfiguration().isJspApplication()) {
        logger.debug("Application is configured as JSP. Adding EL Resolver.");
        setJspELFactory(servletContext, resolver);
    }
    // Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
    servletContext.setAttribute(BeanManager.class.getName(), context.getBeanManagerImpl());
}
Also used : ELResolver(javax.el.ELResolver) BeanManager(javax.enterprise.inject.spi.BeanManager) ELAdaptor(org.apache.webbeans.spi.adaptor.ELAdaptor)

Example 14 with ELResolver

use of javax.el.ELResolver in project tomee by apache.

the class TomEEELInvocationHandlerTest method canCreateInvocationHandler.

@Test
public void canCreateInvocationHandler() {
    final DatabaseIdentityStoreDefinition annotation = Color.class.getAnnotation(DatabaseIdentityStoreDefinition.class);
    final ELProcessor elProcessor = new ELProcessor();
    final ELResolver elResolver = bm().getELResolver();
    elProcessor.getELManager().addELResolver(elResolver);
    // small trick because of the @Vetoed bellow - OWB won't pick it up
    // so we will register one ourselves into the processor so it is resolved
    elProcessor.defineBean("color", new Color());
    final DatabaseIdentityStoreDefinition proxiedAnnotation = TomEEELInvocationHandler.of(DatabaseIdentityStoreDefinition.class, annotation, elProcessor);
    Assert.assertEquals("select password from caller where name = ?", proxiedAnnotation.callerQuery());
    Assert.assertEquals(90, proxiedAnnotation.priority());
    Assert.assertEquals("90", proxiedAnnotation.priorityExpression());
    Assert.assertArrayEquals(new IdentityStore.ValidationType[] { IdentityStore.ValidationType.VALIDATE }, proxiedAnnotation.useFor());
    Assert.assertEquals("select group_name from caller_groups where caller_name = ?", proxiedAnnotation.groupsQuery());
    final String[] hashAlgorithmParameters = proxiedAnnotation.hashAlgorithmParameters();
    Assert.assertArrayEquals(new String[] { "Pbkdf2PasswordHash.Iterations=3072", "${color.dyna}" }, hashAlgorithmParameters);
    final Set<String> evaluatedHashParameters = stream(hashAlgorithmParameters).flatMap(s -> toStream(eval(elProcessor, s, Object.class))).collect(toSet());
    System.out.println(evaluatedHashParameters);
    final Map<String, String> parametersMap = evaluatedHashParameters.stream().collect(toMap(s -> (String) s.substring(0, s.indexOf('=')), s -> (String) eval(elProcessor, s.substring(s.indexOf('=') + 1), String.class)));
    System.out.println(parametersMap);
}
Also used : TomEEDatabaseIdentityStore(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore) Vetoed(javax.enterprise.inject.Vetoed) PasswordHash(javax.security.enterprise.identitystore.PasswordHash) CDI(javax.enterprise.inject.spi.CDI) IdentityStore(javax.security.enterprise.identitystore.IdentityStore) Set(java.util.Set) TomEEDatabaseIdentityStore.eval(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.eval) Test(org.junit.Test) ELProcessor(javax.el.ELProcessor) ELResolver(javax.el.ELResolver) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) DatabaseIdentityStoreDefinition(javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition) Map(java.util.Map) Named(javax.inject.Named) Assert(org.junit.Assert) Arrays.stream(java.util.Arrays.stream) BeanManager(javax.enterprise.inject.spi.BeanManager) Collectors.toSet(java.util.stream.Collectors.toSet) TomEEDatabaseIdentityStore.toStream(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.toStream) ELResolver(javax.el.ELResolver) ELProcessor(javax.el.ELProcessor) DatabaseIdentityStoreDefinition(javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition) TomEEDatabaseIdentityStore(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore) IdentityStore(javax.security.enterprise.identitystore.IdentityStore) Test(org.junit.Test)

Example 15 with ELResolver

use of javax.el.ELResolver in project Payara by payara.

the class WeldContextListenerTest method testcontextInitialized.

@Test
public void testcontextInitialized() throws Exception {
    EasyMockSupport mockSupport = new EasyMockSupport();
    ELResolver elResolver = mockSupport.createMock(ELResolver.class);
    ExpressionFactory expressionFactory = mockSupport.createMock(ExpressionFactory.class);
    StandardContext servletContext = new StandardContext();
    servletContext.getServletContext();
    ServletContextEvent servletContextEvent = mockSupport.createMock(ServletContextEvent.class);
    BeanManager beanManager = mockSupport.createMock(BeanManager.class);
    JspApplicationContextImpl jspApplicationContext = new JspApplicationContextImpl(servletContext);
    expect(beanManager.getELResolver()).andReturn(elResolver);
    expect(beanManager.wrapExpressionFactory(isA(ExpressionFactory.class))).andReturn(expressionFactory);
    mockSupport.replayAll();
    WeldContextListener weldContextListener = getWeldContextListener(beanManager, jspApplicationContext);
    weldContextListener.contextInitialized(servletContextEvent);
    assertSame(expressionFactory, jspApplicationContext.getExpressionFactory());
    validateJspApplicationContext(jspApplicationContext, elResolver);
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) ELResolver(javax.el.ELResolver) ExpressionFactory(javax.el.ExpressionFactory) JspApplicationContextImpl(org.apache.jasper.runtime.JspApplicationContextImpl) StandardContext(org.apache.catalina.core.StandardContext) BeanManager(javax.enterprise.inject.spi.BeanManager) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Aggregations

ELResolver (javax.el.ELResolver)15 CompositeELResolver (javax.el.CompositeELResolver)5 ArrayELResolver (javax.el.ArrayELResolver)4 ELContext (javax.el.ELContext)4 ListELResolver (javax.el.ListELResolver)4 MapELResolver (javax.el.MapELResolver)4 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)4 BeanELResolver (javax.el.BeanELResolver)3 PropertyNotFoundException (javax.el.PropertyNotFoundException)3 BeanManager (javax.enterprise.inject.spi.BeanManager)3 Test (org.junit.Test)3 ELContextEvent (javax.el.ELContextEvent)2 FunctionMapper (javax.el.FunctionMapper)2 VariableMapper (javax.el.VariableMapper)2 ImplicitObjectELResolver (javax.servlet.jsp.el.ImplicitObjectELResolver)2 SimpleContext (de.odysseus.el.util.SimpleContext)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 Arrays.stream (java.util.Arrays.stream)1 Map (java.util.Map)1