Package org.casbin.jcasbin.util
Class BuiltInFunctions
- java.lang.Object
-
- org.casbin.jcasbin.util.BuiltInFunctions
-
public class BuiltInFunctions extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBuiltInFunctions.GenerateConditionalGFunctionClassstatic classBuiltInFunctions.GenerateGFunctionClass
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternKEY_MATCH2_PATTERNprivate static java.util.regex.PatternKEY_MATCH3_PATTERNprivate static java.util.regex.PatternKEY_MATCH5_PATTERN
-
Constructor Summary
Constructors Constructor Description BuiltInFunctions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanallMatch(java.lang.String key1, java.lang.String key2)allMatch determines whether key1 matches the pattern of key2 , key2 can contain a *.static booleaneval(java.lang.String eval, java.util.Map<java.lang.String,java.lang.Object> env, com.googlecode.aviator.AviatorEvaluatorInstance aviatorEval)eval calculates the stringified boolean expression and return its result.static booleanglobMatch(java.lang.String key1, java.lang.String key2)globMatch determines whether key1 matches the pattern of key2 in glob expression.static booleanipMatch(java.lang.String ip1, java.lang.String ip2)ipMatch determines whether IP address ip1 matches the pattern of IP address ip2, ip2 can be an IP address or a CIDR pattern.static java.lang.StringkeyGet2Func(java.lang.String key1, java.lang.String key2, java.lang.String pathVar)KeyGet2 returns value matched pattern.For example, "/resource1" matches "/:resource", if the pathVar == "resource", then "resource1" will be returned.static java.lang.StringkeyGetFunc(java.lang.String key1, java.lang.String key2)KeyGet returns the matched part.static booleankeyMatch(java.lang.String key1, java.lang.String key2)keyMatch determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.static booleankeyMatch2(java.lang.String key1, java.lang.String key2)keyMatch2 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.static booleankeyMatch3(java.lang.String key1, java.lang.String key2)keyMatch3 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.static booleankeyMatch4(java.lang.String key1, java.lang.String key2)KeyMatch4 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.static booleankeyMatch5(java.lang.String key1, java.lang.String key2)KeyMatch5 determines whether key1 matches the pattern of key2 and ignores the parameters in key2.static booleanregexMatch(java.lang.String key1, java.lang.String key2)regexMatch determines whether key1 matches the pattern of key2 in regular expression.static booleantimeMatch(java.lang.String startTime, java.lang.String endTime)TimeMatch determines whether the current time is between startTime and endTime.static booleantimeMatchFunc(java.lang.String... args)timeMatchFunc is the wrapper for TimeMatch.static voidvalidateVariadicStringArgs(int expectedLen, java.lang.String... args)validate the variadic string parameter size
-
-
-
Method Detail
-
validateVariadicStringArgs
public static void validateVariadicStringArgs(int expectedLen, java.lang.String... args) throws java.lang.IllegalArgumentExceptionvalidate the variadic string parameter size- Parameters:
args- the expected number of arguments.expectedLen- the variadic string arguments to validate.- Throws:
java.lang.IllegalArgumentException
-
keyMatch
public static boolean keyMatch(java.lang.String key1, java.lang.String key2)keyMatch determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.For example, "/foo/bar" matches "/foo/*"
- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
keyMatch2
public static boolean keyMatch2(java.lang.String key1, java.lang.String key2)keyMatch2 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.For example, "/foo/bar" matches "/foo/*", "/resource1" matches "/:resource"
- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
keyMatch3
public static boolean keyMatch3(java.lang.String key1, java.lang.String key2)keyMatch3 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *.For example, "/foo/bar" matches "/foo/*", "/resource1" matches "/{resource}"- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
keyMatch4
public static boolean keyMatch4(java.lang.String key1, java.lang.String key2)KeyMatch4 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. Besides what KeyMatch3 does, KeyMatch4 can also match repeated patterns:"/parent/123/child/123" matches "/parent/{id}/child/{id}" "/parent/123/child/456" does not match "/parent/{id}/child/{id}" But KeyMatch3 will match both.Attention: key1 cannot contain English commas.- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
keyMatch5
public static boolean keyMatch5(java.lang.String key1, java.lang.String key2)KeyMatch5 determines whether key1 matches the pattern of key2 and ignores the parameters in key2.For example, "/foo/bar?status=1&type=2" matches "/foo/bar"
- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
keyGetFunc
public static java.lang.String keyGetFunc(java.lang.String key1, java.lang.String key2)KeyGet returns the matched part. For example, "/foo/bar/foo" matches "/foo/*", "bar/foo" will been returned- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- the matched part.
-
keyGet2Func
public static java.lang.String keyGet2Func(java.lang.String key1, java.lang.String key2, java.lang.String pathVar)KeyGet2 returns value matched pattern.For example, "/resource1" matches "/:resource", if the pathVar == "resource", then "resource1" will be returned.- Parameters:
key1- the first argument.key2- the second argument.pathVar- the name of the variable to retrieve from the matched pattern.- Returns:
- the matched part.
-
regexMatch
public static boolean regexMatch(java.lang.String key1, java.lang.String key2)regexMatch determines whether key1 matches the pattern of key2 in regular expression.- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
ipMatch
public static boolean ipMatch(java.lang.String ip1, java.lang.String ip2)ipMatch determines whether IP address ip1 matches the pattern of IP address ip2, ip2 can be an IP address or a CIDR pattern. For example, "192.168.2.123" matches "192.168.2.0/24"- Parameters:
ip1- the first argument.ip2- the second argument.- Returns:
- whether ip1 matches ip2.
-
globMatch
public static boolean globMatch(java.lang.String key1, java.lang.String key2)globMatch determines whether key1 matches the pattern of key2 in glob expression.- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
allMatch
public static boolean allMatch(java.lang.String key1, java.lang.String key2)allMatch determines whether key1 matches the pattern of key2 , key2 can contain a *.For example, "*" matches everything
- Parameters:
key1- the first argument.key2- the second argument.- Returns:
- whether key1 matches key2.
-
eval
public static boolean eval(java.lang.String eval, java.util.Map<java.lang.String,java.lang.Object> env, com.googlecode.aviator.AviatorEvaluatorInstance aviatorEval)eval calculates the stringified boolean expression and return its result.- Parameters:
eval- the stringified boolean expression.env- the key-value pair of the parameters in the expression.aviatorEval- the AviatorEvaluatorInstance object which contains built-in functions and custom functions.- Returns:
- the result of the eval.
-
timeMatchFunc
public static boolean timeMatchFunc(java.lang.String... args)
timeMatchFunc is the wrapper for TimeMatch.- Parameters:
args- the arguments for the time match function.- Returns:
- whether the time matches the pattern.
-
timeMatch
public static boolean timeMatch(java.lang.String startTime, java.lang.String endTime)TimeMatch determines whether the current time is between startTime and endTime. You can use "_" to indicate that the parameter is ignored- Parameters:
startTime- the start time as a string in the format "yyyy-MM-dd HH:mm:ss". Use "_" to ignore the start time.endTime- the end time as a string in the format "yyyy-MM-dd HH:mm:ss". Use "_" to ignore the end time.- Returns:
- whether the current time is between startTime and endTime
-
-