Search in sources :

Example 1 with ELProcessor

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

the class RememberMeInterceptor method getElProcessor.

private ELProcessor getElProcessor(InvocationContext invocationContext, HttpMessageContext httpMessageContext) {
    ELProcessor elProcessor = new ELProcessor();
    elProcessor.getELManager().addELResolver(beanManager.getELResolver());
    elProcessor.defineBean("self", invocationContext.getTarget());
    elProcessor.defineBean("this", invocationContext.getTarget());
    elProcessor.defineBean("httpMessageContext", httpMessageContext);
    return elProcessor;
}
Also used : ELProcessor(javax.el.ELProcessor)

Example 2 with ELProcessor

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

the class TomEEELInvocationHandler method of.

public static <T extends Annotation> T of(final Class<T> annotationClass, final T annotation, final BeanManager beanManager) {
    final ELProcessor elProcessor = new ELProcessor();
    elProcessor.getELManager().addELResolver(beanManager.getELResolver());
    return of(annotationClass, annotation, elProcessor);
}
Also used : ELProcessor(javax.el.ELProcessor)

Example 3 with ELProcessor

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

the class RolesPermittedInterceptor method getElProcessor.

private ELProcessor getElProcessor(InvocationContext invocationContext) {
    final BeanManager beanManager = lazyProperties.getBeanManager();
    ELProcessor elProcessor = new ELProcessor();
    elProcessor.getELManager().addELResolver(beanManager.getELResolver());
    elProcessor.defineBean("self", invocationContext.getTarget());
    Parameter[] parameters = invocationContext.getMethod().getParameters();
    Object[] values = invocationContext.getParameters();
    boolean paramAdded = false;
    for (int i = 0; i < parameters.length; i++) {
        Parameter param = parameters[i];
        Named named = param.getAnnotation(Named.class);
        String key = null;
        if (named != null && !(key = named.value().trim()).isEmpty()) {
            elProcessor.defineBean(key, values[i]);
            paramAdded = true;
        }
    }
    if (!paramAdded && parameters.length == 1) {
        elProcessor.defineBean("param", values[0]);
    }
    return elProcessor;
}
Also used : Named(javax.inject.Named) ELProcessor(javax.el.ELProcessor) Parameter(java.lang.reflect.Parameter) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 4 with ELProcessor

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

the class RealmUtil method getConfiguredValue.

static <T> T getConfiguredValue(Class<T> type, T value, Config provider, String mpConfigKey) {
    T result = value;
    Optional<T> configResult = provider.getOptionalValue(mpConfigKey, type);
    if (configResult.isPresent()) {
        return configResult.get();
    }
    if (type == String.class) {
        result = (T) TranslatedConfigView.expandValue((String) result);
    }
    if (type == String.class && isELExpression((String) value)) {
        ELProcessor elProcessor = new ELProcessor();
        BeanManager beanManager = CDI.current().getBeanManager();
        elProcessor.getELManager().addELResolver(beanManager.getELResolver());
        result = (T) elProcessor.getValue(toRawExpression((String) result), type);
    }
    return result;
}
Also used : ELProcessor(javax.el.ELProcessor) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 5 with ELProcessor

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

the class TomEEDatabaseIdentityStore method init.

@PostConstruct
private void init() throws Exception {
    definition = definitionSupplier.get();
    validationTypes = new HashSet<>(asList(definition.useFor()));
    passwordHash = getInstance(definition.hashAlgorithm());
    final ELProcessor elProcessor = new ELProcessor();
    elProcessor.getELManager().addELResolver(beanManager.getELResolver());
    // the trick with hashAlgorithmParameters is that it returns a String[]
    // each of them may be an EL to evaluate
    // and then we need to create a Map to pass in the password hash class
    // 1. get the list of String and evaluate expressions
    // 2. then split and create the map
    passwordHash.initialize(stream(definition.hashAlgorithmParameters()).flatMap(s -> toStream(eval(elProcessor, s, Object.class))).collect(toMap(s -> (String) s.substring(0, s.indexOf('=')), s -> (String) eval(elProcessor, s.substring(s.indexOf('=') + 1), String.class))));
}
Also used : ELProcessor(javax.el.ELProcessor) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ELProcessor (javax.el.ELProcessor)7 BeanManager (javax.enterprise.inject.spi.BeanManager)3 Named (javax.inject.Named)2 Parameter (java.lang.reflect.Parameter)1 Arrays.stream (java.util.Arrays.stream)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 PostConstruct (javax.annotation.PostConstruct)1 ELResolver (javax.el.ELResolver)1 Vetoed (javax.enterprise.inject.Vetoed)1 CDI (javax.enterprise.inject.spi.CDI)1 SecurityContext (javax.security.enterprise.SecurityContext)1 DatabaseIdentityStoreDefinition (javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition)1 IdentityStore (javax.security.enterprise.identitystore.IdentityStore)1 PasswordHash (javax.security.enterprise.identitystore.PasswordHash)1 TomEEDatabaseIdentityStore (org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore)1 TomEEDatabaseIdentityStore.eval (org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.eval)1