Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JEASY MVEL dependencies to fix security vulnerabilities #655

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.interfaces.FormFileSource;
import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt;
import com.vijay.jsonwizard.utils.NativeFormsProperties;
import com.vijay.jsonwizard.utils.Utils;

import org.jeasy.rules.api.Rules;
import org.jeasy.rules.mvel.MVELRuleFactory;
import org.jeasy.rules.support.reader.YamlRuleDefinitionReader;
import org.json.JSONObject;

import java.io.BufferedReader;
Expand All @@ -27,8 +29,16 @@ public class AssetsFileSource implements FormFileSource {
private MVELRuleFactory mvelRuleFactory;

private AssetsFileSource() {
if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the formatting and/or spacing in the files

{
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());
Timber.e("AssetsFileSource Engaged");
}
else
{
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
Timber.e("AssetsFileSource not Engaged");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.interfaces.FormFileSource;
import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt;
import com.vijay.jsonwizard.utils.NativeFormsProperties;
import com.vijay.jsonwizard.utils.Utils;

import org.jeasy.rules.api.Rules;
import org.jeasy.rules.mvel.MVELRuleFactory;
import org.jeasy.rules.support.reader.YamlRuleDefinitionReader;
import org.json.JSONObject;

import java.io.BufferedReader;
Expand All @@ -20,6 +22,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;

import timber.log.Timber;


/**
* Returns forms rules and other files stored on the devices
Expand All @@ -31,7 +35,15 @@ public class DiskFileSource implements FormFileSource {
private MVELRuleFactory mvelRuleFactory;

private DiskFileSource() {
if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)){
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());
Timber.e("Disk File source Mvel backward compat engaged");

}
else {
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
Timber.e("Disk File source Mvel backward compat not engaged");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.mvel.MVELRule;
import org.jeasy.rules.mvel.MVELRuleFactory;
import org.jeasy.rules.support.reader.YamlRuleDefinitionReader;
import org.json.JSONArray;
import org.json.JSONObject;
import org.smartregister.client.utils.contract.ClientFormContract;
Expand Down Expand Up @@ -54,8 +55,15 @@ public RulesEngineFactory(Context context, Map<String, String> globalValues) {
this.ruleMap = new HashMap<>();
gson = new Gson();
this.rulesEngineHelper = new RulesEngineHelper();
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());
Timber.e("yaml ext Reader engaged : RulesEngineFactory");
if(backwardCompatibility) {
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());
Timber.e("yaml ext Reader engaged : RulesEngineFactory");
}
else
{
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
Timber.e("yaml ext Reader disengaged : RulesEngineFactory");
}


if (globalValues != null) {
Expand Down Expand Up @@ -272,23 +280,27 @@ public void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult) {

@Override
public void beforeExecute(Rule rule, Facts facts) {
if(backwardCompatibility) {
Timber.e("Putting facts in beforeExecute");
HashMap<String, Object> myMap = new HashMap<>();
facts.put("facts", myMap);
}

}

@Override
public void onSuccess(Rule rule, Facts facts) {
Timber.e("Putting facts in onSuccess");
HashMap<String, Object> myMap = facts.get("facts");
if(backwardCompatibility) {
Timber.e("Putting facts in onSuccess");
HashMap<String, Object> myMap = facts.get("facts");

for (String key :
myMap.keySet()) {
facts.put(key, myMap.get(key));
}
for (String key :
myMap.keySet()) {
facts.put(key, myMap.get(key));
}

facts.remove("facts");
facts.remove("facts");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.vijay.jsonwizard.activities.JsonFormActivity;
import com.vijay.jsonwizard.constants.JsonFormConstants;

import com.vijay.jsonwizard.utils.NativeFormsProperties;
import com.vijay.jsonwizard.utils.Utils;

import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.Rules;
Expand Down Expand Up @@ -43,9 +46,13 @@ public class RulesEngineFactoryTest {
@Mock
private AssetManager assetManager;

private NativeFormsProperties nativeFormsProperties;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
nativeFormsProperties = Utils.getProperties(context);
nativeFormsProperties.setProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY,"true");
rulesEngineFactory = new RulesEngineFactory();
}

Expand Down
3 changes: 2 additions & 1 deletion form_tester/src/main/assets/app.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
widget.datepicker.is.numeric=true
widget.value.translated=true
widget.value.translated=true
easy_rule.v3.compatibility=true