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 @@ -1941,14 +1941,19 @@ private List<String> getRules(String filename, String fieldKey, boolean readAllR
conditionString.append(map.get(RuleConstant.CONDITION).toString());

List<String> fields = (List<String>) map.get(RuleConstant.ACTIONS);
List<String> newFields = new ArrayList<>();
if (fields != null) {
for (String field : fields) {
if (field.trim().startsWith(RuleConstant.CALCULATION) ||
field.trim().startsWith(RuleConstant.CONSTRAINT)) {
conditionString.append(" " + field);
}

newFields.add("facts." + field);
}

fields.clear();
fields.addAll(newFields);
}

actions.addAll(getConditionKeys(conditionString.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.interfaces.FormFileSource;
import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt;
import com.vijay.jsonwizard.utils.Utils;

import org.jeasy.rules.api.Rules;
Expand All @@ -25,7 +26,7 @@ public class AssetsFileSource implements FormFileSource {
private MVELRuleFactory mvelRuleFactory;

private AssetsFileSource() {
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.interfaces.FormFileSource;
import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt;
import com.vijay.jsonwizard.utils.Utils;

import org.jeasy.rules.api.Rules;
Expand All @@ -30,7 +31,7 @@ public class DiskFileSource implements FormFileSource {
private MVELRuleFactory mvelRuleFactory;

private DiskFileSource() {
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public RulesEngineFactory(Context context, Map<String, String> globalValues) {
this.ruleMap = new HashMap<>();
gson = new Gson();
this.rulesEngineHelper = new RulesEngineHelper();
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt());


if (globalValues != null) {
Expand Down Expand Up @@ -257,19 +257,31 @@ public void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult) {
//Overriden
}


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

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

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

facts.remove("facts");
}

@Override
public void onFailure(Rule rule, Facts facts, Exception exception) {
//Overriden
Timber.e("Putting facts in onFailure");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kindly check if there might be successful executions of rules meaning that we might need to update our facts object with key-values from the facts.facts map

facts.remove("facts");
}

public String getRulesFolderPath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.vijay.jsonwizard.rules;

import org.jeasy.rules.support.RuleDefinition;
import org.jeasy.rules.support.reader.YamlRuleDefinitionReader;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Created by Ephraim Kigamba - nek.eam@gmail.com on 22-11-2022.
*/
public class YamlRuleDefinitionReaderExt extends YamlRuleDefinitionReader {


@Override
protected RuleDefinition createRuleDefinition(Map<String, Object> map) {
RuleDefinition ruleDefinition = super.createRuleDefinition(map);

List<String> actionList = ruleDefinition.getActions();
List<String> newActionList = new ArrayList<>();

for (int i = 0; i < actionList.size(); i++) {
newActionList.add("facts." + actionList.get(i));
}

actionList.clear();
actionList.addAll(newActionList);

return ruleDefinition;
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=3.1.2-SNAPSHOT
VERSION_NAME=3.1.5-LOCAL-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down