aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2023-02-23 11:18:02 -0800
committerGitHub <noreply@github.com>2023-02-23 11:18:02 -0800
commit8acc8f0eb2fec2e9b079950ebad835f027fe3f9c (patch)
tree5dc044ddb8f417920593fd6a245a1fe5dbf7c411 /src/main/java/org/traccar/handler
parent2b7c3ecde2512478dac381feaab9d35a93c3b9cb (diff)
parent7a8fc065a116af1f944959354495db00459d2199 (diff)
downloadtrackermap-server-8acc8f0eb2fec2e9b079950ebad835f027fe3f9c.tar.gz
trackermap-server-8acc8f0eb2fec2e9b079950ebad835f027fe3f9c.tar.bz2
trackermap-server-8acc8f0eb2fec2e9b079950ebad835f027fe3f9c.zip
Merge pull request #5036 from memesaregood1/master
Implement JEXL parser settings
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
index ca6c0fc74..e8a4998e3 100644
--- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
@@ -26,8 +26,10 @@ import java.util.Map;
import java.util.Set;
import io.netty.channel.ChannelHandler;
-import org.apache.commons.jexl3.JexlBuilder;
+import org.apache.commons.jexl3.JexlFeatures;
import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.JexlBuilder;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.MapContext;
import org.slf4j.Logger;
@@ -53,14 +55,25 @@ public class ComputedAttributesHandler extends BaseDataHandler {
private final JexlEngine engine;
+ private final JexlFeatures features;
+
private final boolean includeDeviceAttributes;
@Inject
public ComputedAttributesHandler(Config config, CacheManager cacheManager) {
this.cacheManager = cacheManager;
+ JexlSandbox sandbox = new JexlSandbox(false);
+ sandbox.allow("com.safe.Functions");
+ sandbox.allow(Math.class.getName());
+ features = new JexlFeatures()
+ .localVar(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES))
+ .loops(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOOPS))
+ .newInstance(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION))
+ .structuredLiteral(true);
engine = new JexlBuilder()
.strict(true)
.namespaces(Collections.singletonMap("math", Math.class))
+ .sandbox(sandbox)
.create();
includeDeviceAttributes = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES);
}
@@ -102,7 +115,9 @@ public class ComputedAttributesHandler extends BaseDataHandler {
*/
@Deprecated
public Object computeAttribute(Attribute attribute, Position position) throws JexlException {
- return engine.createExpression(attribute.getExpression()).evaluate(prepareContext(position));
+ return engine.createScript(features,
+ engine.createInfo(),
+ attribute.getExpression()).execute(prepareContext(position));
}
@Override