diff --git a/src/main/java/org/casbin/jcasbin/main/CoreEnforcer.java b/src/main/java/org/casbin/jcasbin/main/CoreEnforcer.java index ec3c7ace..60d88e9a 100644 --- a/src/main/java/org/casbin/jcasbin/main/CoreEnforcer.java +++ b/src/main/java/org/casbin/jcasbin/main/CoreEnforcer.java @@ -42,9 +42,6 @@ import java.util.function.BiPredicate; import java.util.function.Function; -import static org.casbin.jcasbin.util.Util.hasEval; -import static org.casbin.jcasbin.util.Util.splitCommaDelimitedList; - /** * CoreEnforcer defines the core functionality of an enforcer. */ @@ -583,7 +580,6 @@ private EnforceResult enforce(String matcher, Object... rvals) { } else { expString = Util.removeComments(Util.escapeAssertion(matcher)); } - boolean hasEval = hasEval(expString); // json process if (acceptJsonRequest) { @@ -633,9 +629,6 @@ private EnforceResult enforce(String matcher, Object... rvals) { for (int i = 0; i < policy.size(); i++) { List pvals = policy.get(i); - if (hasEval) { - pvals = splitCommaDelimitedList(pvals); - } Map parameters = new HashMap<>(rvals.length + pTokens.length); getPTokens(parameters, pType, pvals, pTokens); getRTokens(parameters, rType, rvals); diff --git a/src/main/java/org/casbin/jcasbin/util/Util.java b/src/main/java/org/casbin/jcasbin/util/Util.java index 6f739025..4077ee18 100644 --- a/src/main/java/org/casbin/jcasbin/util/Util.java +++ b/src/main/java/org/casbin/jcasbin/util/Util.java @@ -284,21 +284,6 @@ public static String[] splitCommaDelimited(String s) { return records; } - /** - * splits each string in the given list by commas according to CSV format - * and removes any extra double quotes - * @param rule the rule to be modified - * @return the modified rule - */ - public static List splitCommaDelimitedList(List rule) { - List modifiedRule = new ArrayList<>(); - for (String s : rule) { - String[] strings = splitCommaDelimited(s); - modifiedRule.add(strings[0]); - } - return modifiedRule; - } - /** * setEquals determines whether two string sets are identical. * @@ -329,7 +314,7 @@ public static boolean setEquals(List a, List b) { } public static boolean hasEval(String exp) { - return evalReg.matcher(exp).find(); + return evalReg.matcher(exp).matches(); } public static String replaceEval(String s, String replacement) { diff --git a/src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java b/src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java index 7a252eb0..d0f8a65b 100644 --- a/src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java +++ b/src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java @@ -14,10 +14,8 @@ package org.casbin.jcasbin.main; +import org.casbin.jcasbin.util.Util; import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.HashMap; @@ -44,15 +42,6 @@ public void testEval() { alice.setAge(60); testEnforce(e, alice, "/data2", "read", false); testEnforce(e, alice, "/data2", "write", false); - - List rule = new ArrayList<>(); - rule.add("\"r.sub.name == 'alice,green'\""); - rule.add("data1"); - rule.add("read"); - e.addPolicy(rule); - - TestEvalRule aliceGreen = new TestEvalRule("alice,green", 18); - testEnforce(e, aliceGreen, "data1", "read", true); } @Test diff --git a/src/test/java/org/casbin/jcasbin/main/UtilTest.java b/src/test/java/org/casbin/jcasbin/main/UtilTest.java index 187951fd..545bc373 100644 --- a/src/test/java/org/casbin/jcasbin/main/UtilTest.java +++ b/src/test/java/org/casbin/jcasbin/main/UtilTest.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.io.StringReader; -import static org.casbin.jcasbin.util.Util.hasEval; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; @@ -85,13 +84,6 @@ public void testSplitCommaDelimited(){ assertArrayEquals(new String[]{"a b", "c", "d"}, Util.splitCommaDelimited("\"a b\", c, d")); } - @Test - public void testHasEval() { - assertTrue(hasEval("eval(test)")); - assertTrue(hasEval("r_act == p_act && eval(p_sub_rule) && eval(p_obj_rule)")); - assertFalse(hasEval("evaltest")); - } - @Test public void testReplaceEval() { Util.logPrint(Util.replaceEval("eval(test)", "testEval"));