List of usage examples for org.apache.lucene.util.automaton Automata makeChar
public static Automaton makeChar(int c)
From source file:org.codelibs.elasticsearch.common.xcontent.support.XContentMapValues.java
License:Apache License
/** Make matches on objects also match dots in field names. * For instance, if the original simple regex is `foo`, this will translate * it into `foo` OR `foo.*`. *//*from w w w .j a v a 2 s .co m*/ private static Automaton makeMatchDotsInFieldNames(Automaton automaton) { return Operations.union(automaton, Operations.concatenate(Arrays.asList(automaton, Automata.makeChar('.'), Automata.makeAnyString()))); }
From source file:org.elasticsearch.xpack.core.security.authz.permission.FieldPermissions.java
License:Open Source License
private static Automaton initializePermittedFieldsAutomaton(final String[] grantedFields, final String[] deniedFields) { Automaton grantedFieldsAutomaton;//from ww w.j a v a 2s .c om if (grantedFields == null || Arrays.stream(grantedFields).anyMatch(Regex::isMatchAllPattern)) { grantedFieldsAutomaton = Automatons.MATCH_ALL; } else { // an automaton that includes metadata fields, including join fields created by the _parent field such // as _parent#type Automaton metaFieldsAutomaton = Operations.concatenate(Automata.makeChar('_'), Automata.makeAnyString()); grantedFieldsAutomaton = Operations.union(Automatons.patterns(grantedFields), metaFieldsAutomaton); } Automaton deniedFieldsAutomaton; if (deniedFields == null || deniedFields.length == 0) { deniedFieldsAutomaton = Automatons.EMPTY; } else { deniedFieldsAutomaton = Automatons.patterns(deniedFields); } grantedFieldsAutomaton = MinimizationOperations.minimize(grantedFieldsAutomaton, Operations.DEFAULT_MAX_DETERMINIZED_STATES); deniedFieldsAutomaton = MinimizationOperations.minimize(deniedFieldsAutomaton, Operations.DEFAULT_MAX_DETERMINIZED_STATES); if (subsetOf(deniedFieldsAutomaton, grantedFieldsAutomaton) == false) { throw new ElasticsearchSecurityException("Exceptions for field permissions must be a subset of the " + "granted fields but " + Strings.arrayToCommaDelimitedString(deniedFields) + " is not a subset of " + Strings.arrayToCommaDelimitedString(grantedFields)); } grantedFieldsAutomaton = Automatons.minusAndMinimize(grantedFieldsAutomaton, deniedFieldsAutomaton); return grantedFieldsAutomaton; }
From source file:org.elasticsearch.xpack.core.security.support.Automatons.java
License:Open Source License
/** * Builds and returns an automaton that represents the given pattern. *///from ww w . j a v a 2 s. c o m @SuppressWarnings("fallthrough") // explicit fallthrough at end of switch static Automaton wildcard(String text) { List<Automaton> automata = new ArrayList<>(); for (int i = 0; i < text.length();) { final char c = text.charAt(i); int length = 1; switch (c) { case WILDCARD_STRING: automata.add(Automata.makeAnyString()); break; case WILDCARD_CHAR: automata.add(Automata.makeAnyChar()); break; case WILDCARD_ESCAPE: // add the next codepoint instead, if it exists if (i + length < text.length()) { final char nextChar = text.charAt(i + length); length += 1; automata.add(Automata.makeChar(nextChar)); break; } // else fallthru, lenient parsing with a trailing \ default: automata.add(Automata.makeChar(c)); } i += length; } return concatenate(automata); }