THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||
---|---|---|---|---|
| ||||
/** * Returns true if two strings match, both of which might be ending in a special wildcard which matches everything. * Examples: * matchWildcardSuffixedString("rob", "rob") => true * matchWildcardSuffixedString("*", "rob") => true * matchWildcardSuffixedString("ro*", "rob") => true * matchWildcardSuffixedString("rob", "bob") => false * matchWildcardSuffixedString("ro*", "bob") => false * * matchWildcardSuffixedString("rob", "*") => true * matchWildcardSuffixedString("rob", "ro*") => true * matchWildcardSuffixedString("bob", "ro*") => false * * matchWildcardSuffixedString("ro*", "ro*") => true * matchWildcardSuffixedString("rob*", "ro*") => false * matchWildcardSuffixedString("ro*", "rob*") => true * * @param valueInZk Value stored in ZK in either resource name or Acl. * @param input Value present in the request. * @return true if there is a match (including wildcard-suffix matching). */ def matchWildcardSuffixedString(valueInZk: String, input: String): Boolean = { if (valueInZk.equals(input) || valueInZk.equals(Acl.WildCardString) || input.equals(Acl.WildCardString)) { // if strings are equal or either of acl or input is a wildcard true } else if (valueInZk.endsWith(Acl.WildCardString)) { val aclPrefix = valueInZk.substring(0, valueInZk.length - Acl.WildCardString.length) if (input.endsWith(Acl.WildCardString)) { // when both acl and input ends with wildcard, non-wildcard prefix of input should start with non-wildcard prefix of acl val inputPrefix = input.substring(0, input.length - Acl.WildCardString.length) inputPrefix.startsWith(aclPrefix) } else { // when acl ends with wildcard but input doesn't, then input should start with non-wildcard prefix of acl input.startsWith(aclPrefix) } } else { if (input.endsWith(Acl.WildCardString)) { // when input ends with wildcard but acl doesn't, then acl should start with non-wildcard prefix of input val inputPrefix = input.substring(0, input.length - Acl.WildCardString.length) valueInZk.startsWith(inputPrefix) } else { // when neither acl nor input ends with wildcard, they have to match exactly. valueInZk.equals(input) } } } |
Compatibility, Deprecation, and Migration Plan
...