Package org.keycloak.utils
Class RegexUtils
java.lang.Object
org.keycloak.utils.RegexUtils
Utility methods for validating and matching regular expressions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum regex length — limits complexity to mitigate ReDoS attacks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisValidRegex(String regexp) Validates whether the given string is a syntactically valid regular expression with a maximum length ofDEFAULT_MAX_LENGTHand groups allowed.static booleanisValidRegex(String regexp, int maxLength, boolean allowGroups) Validates whether the given string is a syntactically valid regular expression.static booleanvalueMatchesRegex(String regex, Object value)
-
Field Details
-
DEFAULT_MAX_LENGTH
public static final int DEFAULT_MAX_LENGTHDefault maximum regex length — limits complexity to mitigate ReDoS attacks.- See Also:
-
-
Constructor Details
-
RegexUtils
public RegexUtils()
-
-
Method Details
-
isValidRegex
Validates whether the given string is a syntactically valid regular expression with a maximum length ofDEFAULT_MAX_LENGTHand groups allowed.- Parameters:
regexp- the regular expression to validate- Returns:
trueif the expression is valid,falseotherwise
-
isValidRegex
Validates whether the given string is a syntactically valid regular expression.- Parameters:
regexp- the regular expression to validatemaxLength- the maximum allowed length of the expressionallowGroups- whether capturing and non-capturing groups (parentheses) are permitted- Returns:
trueif the expression is valid,falseif it isnull, exceedsmaxLength, contains groups when disallowed, or has invalid syntax
-
valueMatchesRegex
-