aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authormemesaregood1 <sifepe4679@yandex.ru>2023-02-21 22:39:14 +0300
committermemesaregood1 <sifepe4679@yandex.ru>2023-02-21 22:39:14 +0300
commit7678392d85f43c60c93f2a08dcba6aa7ec6102e4 (patch)
treebfa49125aab1105a5d3e5f9213b2ea40a0e5949a /src/main/java/org/traccar/handler
parentcd1d80896b16c84ae0a8a4631a9dba6955e9e344 (diff)
downloadtrackermap-server-7678392d85f43c60c93f2a08dcba6aa7ec6102e4.tar.gz
trackermap-server-7678392d85f43c60c93f2a08dcba6aa7ec6102e4.tar.bz2
trackermap-server-7678392d85f43c60c93f2a08dcba6aa7ec6102e4.zip
Implement JEXL parser settings
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
index ca6c0fc74..c3f202fa2 100644
--- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
@@ -26,10 +26,8 @@ import java.util.Map;
import java.util.Set;
import io.netty.channel.ChannelHandler;
-import org.apache.commons.jexl3.JexlBuilder;
-import org.apache.commons.jexl3.JexlEngine;
-import org.apache.commons.jexl3.JexlException;
-import org.apache.commons.jexl3.MapContext;
+import org.apache.commons.jexl3.*;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.BaseDataHandler;
@@ -55,14 +53,51 @@ public class ComputedAttributesHandler extends BaseDataHandler {
private final boolean includeDeviceAttributes;
+
@Inject
public ComputedAttributesHandler(Config config, CacheManager cacheManager) {
this.cacheManager = cacheManager;
+ boolean enableJEXLAnnotation = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_ANNOTATION);
+ boolean enableJEXLArrayReferences = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_ARRAY_REFERENCES);
+ boolean enableJEXLLambdas = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LAMBDA);
+ boolean enableJEXLLexical = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LEXICAL);
+ boolean enableJEXLLexicalShade = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LEXICAL_SHADE);
+ boolean enableJEXLLocalVariables = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES);
+ boolean enableJEXLLoops = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOOPS);
+ boolean enableJEXLMethodCalls = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_METHOD_CALLS);
+ boolean enableJEXLNewInstanceCreation = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION);
+ boolean enableJEXLPragma = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_PRAGMA);
+ boolean enableJEXLScriptConstructs = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_SCRIPT_CONSTRUCTS);
+ boolean enableJEXLSideEffect = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_SIDE_EFFECT);
+ boolean enableJEXLSideEffectGlobal = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_SIDE_EFFECT_GLOBAL);
+ boolean enableJEXLStructuredLiteral = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_STRUCTURED_LITERAL);
+ JexlSandbox sandbox = new JexlSandbox(false);
+ sandbox.allow("com.safe.Functions");
+ boolean enableJEXLRegister = true;
+ JexlFeatures features = new JexlFeatures()
+ .annotation(enableJEXLAnnotation)
+ .arrayReferenceExpr(enableJEXLArrayReferences)
+ .lambda(enableJEXLLambdas)
+ .lexical(enableJEXLLexical)
+ .lexicalShade(enableJEXLLexicalShade)
+ .localVar(enableJEXLLocalVariables)
+ .loops(enableJEXLLoops)
+ .methodCall(enableJEXLMethodCalls)
+ .newInstance(enableJEXLNewInstanceCreation)
+ .pragma(enableJEXLPragma)
+ .register(enableJEXLRegister)
+ .script(enableJEXLScriptConstructs)
+ .sideEffect(enableJEXLSideEffect)
+ .sideEffectGlobal(enableJEXLSideEffectGlobal)
+ .structuredLiteral(enableJEXLStructuredLiteral);
engine = new JexlBuilder()
.strict(true)
.namespaces(Collections.singletonMap("math", Math.class))
+ .sandbox(sandbox)
+ .features(features)
.create();
includeDeviceAttributes = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES);
+
}
private MapContext prepareContext(Position position) {