From ac2df9999488608f45058f0ea0dac6502b2e8dbf Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 15 Aug 2021 14:58:41 +0200 Subject: [PATCH] Add support for true and false constants in permission expressions --- .../permissions/PermissionExpressionParser.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionExpressionParser.java b/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionExpressionParser.java index cb20e5e..4a43639 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionExpressionParser.java +++ b/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionExpressionParser.java @@ -5,6 +5,7 @@ import java.util.function.Function; import com.fathzer.soft.javaluator.AbstractEvaluator; import com.fathzer.soft.javaluator.BracketPair; +import com.fathzer.soft.javaluator.Constant; import com.fathzer.soft.javaluator.Operator; import com.fathzer.soft.javaluator.Operator.Associativity; import com.fathzer.soft.javaluator.Parameters; @@ -32,6 +33,8 @@ public class PermissionExpressionParser { private static final Operator NOT = new Operator("!", 1, Associativity.LEFT, 3); private static final Operator AND = new Operator("&&", 2, Associativity.LEFT, 2); private static final Operator OR = new Operator("||", 2, Associativity.LEFT, 1); + private static final Constant TRUE = new Constant("true"); + private static final Constant FALSE = new Constant("false"); private static final Parameters PARAMETERS; @@ -41,6 +44,8 @@ public class PermissionExpressionParser { PARAMETERS.add(NOT); PARAMETERS.add(AND); PARAMETERS.add(OR); + PARAMETERS.add(TRUE); + PARAMETERS.add(FALSE); PARAMETERS.addExpressionBracket(BracketPair.PARENTHESES); } @@ -73,6 +78,15 @@ public class PermissionExpressionParser { return super.evaluate(operator, operands, evaluationContext); } } + + @Override + protected Boolean evaluate(Constant constant, Object evaluationContext) { + if (constant == TRUE) + return true; + if (constant == FALSE) + return false; + return super.evaluate(constant, evaluationContext); + } }