mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
use brics automaton instead of lucene, so we don't depend on lucene
Closes elastic/elasticsearch#710 Original commit: elastic/x-pack-elasticsearch@71ca4e6241
This commit is contained in:
parent
0aeeb8c26f
commit
e7f141bd5c
@ -11,11 +11,6 @@ java.util.concurrent.Executors#privilegedThreadFactory()
|
||||
java.lang.Character#codePointBefore(char[],int) @ Implicit start offset is error-prone when the char[] is a buffer and the first chars are random chars
|
||||
java.lang.Character#codePointAt(char[],int) @ Implicit end offset is error-prone when the char[] is a buffer and the last chars are random chars
|
||||
|
||||
@defaultMessage Collections.sort dumps data into an array, sorts the array and reinserts data into the list, one should rather use Lucene's CollectionUtil sort methods which sort in place
|
||||
|
||||
java.util.Collections#sort(java.util.List)
|
||||
java.util.Collections#sort(java.util.List,java.util.Comparator)
|
||||
|
||||
java.io.StringReader#<init>(java.lang.String) @ Use FastStringReader instead
|
||||
|
||||
@defaultMessage Reference management is tricky, leave it to SearcherManager
|
||||
@ -65,4 +60,4 @@ java.nio.channels.ScatteringByteChannel#read(java.nio.ByteBuffer[], int, int)
|
||||
java.nio.channels.FileChannel#read(java.nio.ByteBuffer, long)
|
||||
|
||||
@defaultMessage The LdapSslSocketFactory should never be cleared manually as it may lead to threading issues.
|
||||
org.elasticsearch.shield.authc.support.ldap.LdapSslSocketFactory#clear()
|
||||
org.elasticsearch.shield.authc.support.ldap.LdapSslSocketFactory#clear()
|
||||
|
7
pom.xml
7
pom.xml
@ -177,6 +177,13 @@
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dk.brics.automaton</groupId>
|
||||
<artifactId>automaton</artifactId>
|
||||
<version>1.11-8</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package org.elasticsearch.shield.authc;
|
||||
|
||||
import org.apache.lucene.util.CollectionUtil;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.collect.Lists;
|
||||
import org.elasticsearch.common.collect.Sets;
|
||||
@ -100,7 +99,7 @@ public class Realms extends AbstractLifecycleComponent<Realms> implements Iterab
|
||||
}
|
||||
|
||||
if (!realms.isEmpty()) {
|
||||
CollectionUtil.introSort(realms);
|
||||
Collections.sort(realms);
|
||||
return realms;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,10 @@
|
||||
*/
|
||||
package org.elasticsearch.shield.authz;
|
||||
|
||||
import org.apache.lucene.util.automaton.Automata;
|
||||
import org.apache.lucene.util.automaton.Automaton;
|
||||
import org.apache.lucene.util.automaton.Operations;
|
||||
import dk.brics.automaton.Automaton;
|
||||
import dk.brics.automaton.BasicAutomata;
|
||||
import dk.brics.automaton.BasicOperations;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
|
||||
@ -115,7 +116,7 @@ public abstract class Privilege<P extends Privilege<P>> {
|
||||
|
||||
public static class General extends AutomatonPrivilege<General> {
|
||||
|
||||
private static final General NONE = new General(Name.NONE, Automata.makeEmpty());
|
||||
private static final General NONE = new General(Name.NONE, BasicAutomata.makeEmpty());
|
||||
|
||||
public General(String name, String... patterns) {
|
||||
super(name, patterns);
|
||||
@ -143,7 +144,7 @@ public abstract class Privilege<P extends Privilege<P>> {
|
||||
|
||||
public static class Index extends AutomatonPrivilege<Index> {
|
||||
|
||||
public static final Index NONE = new Index(Name.NONE, Automata.makeEmpty());
|
||||
public static final Index NONE = new Index(Name.NONE, BasicAutomata.makeEmpty());
|
||||
public static final Index ALL = new Index(Name.ALL, "indices:*");
|
||||
public static final Index MANAGE = new Index("manage", "indices:monitor/*", "indices:admin/*");
|
||||
public static final Index CREATE_INDEX = new Index("create_index", CreateIndexAction.NAME);
|
||||
@ -246,7 +247,7 @@ public abstract class Privilege<P extends Privilege<P>> {
|
||||
|
||||
public static class Cluster extends AutomatonPrivilege<Cluster> {
|
||||
|
||||
public static final Cluster NONE = new Cluster(Name.NONE, Automata.makeEmpty());
|
||||
public static final Cluster NONE = new Cluster(Name.NONE, BasicAutomata.makeEmpty());
|
||||
public static final Cluster ALL = new Cluster(Name.ALL, "cluster:*", "indices:admin/template/*");
|
||||
public static final Cluster MONITOR = new Cluster("monitor", "cluster:monitor/*");
|
||||
public static final Cluster MANAGE_SHIELD = new Cluster("manage_shield", "cluster:admin/shield/*");
|
||||
@ -374,7 +375,7 @@ public abstract class Privilege<P extends Privilege<P>> {
|
||||
|
||||
@Override
|
||||
public boolean implies(P other) {
|
||||
return Operations.subsetOf(other.automaton, automaton);
|
||||
return BasicOperations.subsetOf(other.automaton, automaton);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -5,8 +5,8 @@
|
||||
*/
|
||||
package org.elasticsearch.shield.support;
|
||||
|
||||
import org.apache.lucene.util.automaton.Automaton;
|
||||
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
|
||||
import dk.brics.automaton.RunAutomaton;
|
||||
import dk.brics.automaton.Automaton;
|
||||
import org.elasticsearch.common.base.Predicate;
|
||||
|
||||
/**
|
||||
@ -14,13 +14,13 @@ import org.elasticsearch.common.base.Predicate;
|
||||
*/
|
||||
public class AutomatonPredicate implements Predicate<String> {
|
||||
|
||||
private final CharacterRunAutomaton automaton;
|
||||
private final RunAutomaton automaton;
|
||||
|
||||
public AutomatonPredicate(Automaton automaton) {
|
||||
this(new CharacterRunAutomaton(automaton));
|
||||
this(new RunAutomaton(automaton));
|
||||
}
|
||||
|
||||
public AutomatonPredicate(CharacterRunAutomaton automaton) {
|
||||
public AutomatonPredicate(RunAutomaton automaton) {
|
||||
this.automaton = automaton;
|
||||
}
|
||||
|
||||
|
@ -5,18 +5,18 @@
|
||||
*/
|
||||
package org.elasticsearch.shield.support;
|
||||
|
||||
import org.apache.lucene.util.automaton.Automata;
|
||||
import org.apache.lucene.util.automaton.Automaton;
|
||||
import org.apache.lucene.util.automaton.Operations;
|
||||
import org.apache.lucene.util.automaton.RegExp;
|
||||
import dk.brics.automaton.BasicAutomata;
|
||||
import dk.brics.automaton.Automaton;
|
||||
import dk.brics.automaton.BasicOperations;
|
||||
import dk.brics.automaton.RegExp;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.lucene.util.automaton.MinimizationOperations.minimize;
|
||||
import static org.apache.lucene.util.automaton.Operations.*;
|
||||
import static dk.brics.automaton.MinimizationOperations.minimize;
|
||||
import static dk.brics.automaton.BasicOperations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -42,7 +42,7 @@ public final class Automatons {
|
||||
*/
|
||||
public static Automaton patterns(Collection<String> patterns) {
|
||||
if (patterns.isEmpty()) {
|
||||
return Automata.makeEmpty();
|
||||
return BasicAutomata.makeEmpty();
|
||||
}
|
||||
Automaton automaton = null;
|
||||
for (String pattern : patterns) {
|
||||
@ -52,7 +52,8 @@ public final class Automatons {
|
||||
automaton = union(automaton, pattern(pattern));
|
||||
}
|
||||
}
|
||||
return determinize(minimize(automaton));
|
||||
minimize(automaton); // minimal is also deterministic
|
||||
return automaton;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,36 +78,40 @@ public final class Automatons {
|
||||
static Automaton wildcard(String text) {
|
||||
List<Automaton> automata = new ArrayList<>();
|
||||
for (int i = 0; i < text.length();) {
|
||||
final int c = text.codePointAt(i);
|
||||
int length = Character.charCount(c);
|
||||
final char c = text.charAt(i);
|
||||
int length = 1;
|
||||
switch(c) {
|
||||
case WILDCARD_STRING:
|
||||
automata.add(Automata.makeAnyString());
|
||||
automata.add(BasicAutomata.makeAnyString());
|
||||
break;
|
||||
case WILDCARD_CHAR:
|
||||
automata.add(Automata.makeAnyChar());
|
||||
automata.add(BasicAutomata.makeAnyChar());
|
||||
break;
|
||||
case WILDCARD_ESCAPE:
|
||||
// add the next codepoint instead, if it exists
|
||||
if (i + length < text.length()) {
|
||||
final int nextChar = text.codePointAt(i + length);
|
||||
length += Character.charCount(nextChar);
|
||||
automata.add(Automata.makeChar(nextChar));
|
||||
final char nextChar = text.charAt(i + length);
|
||||
length += 1;
|
||||
automata.add(BasicAutomata.makeChar(nextChar));
|
||||
break;
|
||||
} // else fallthru, lenient parsing with a trailing \
|
||||
default:
|
||||
automata.add(Automata.makeChar(c));
|
||||
automata.add(BasicAutomata.makeChar(c));
|
||||
}
|
||||
i += length;
|
||||
}
|
||||
return Operations.concatenate(automata);
|
||||
return BasicOperations.concatenate(automata);
|
||||
}
|
||||
|
||||
public static Automaton unionAndDeterminize(Automaton a1, Automaton a2) {
|
||||
return determinize(union(a1, a2));
|
||||
Automaton res = union(a1, a2);
|
||||
res.determinize();
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Automaton minusAndDeterminize(Automaton a1, Automaton a2) {
|
||||
return determinize(minus(a1, a2));
|
||||
Automaton res = minus(a1, a2);
|
||||
res.determinize();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*/
|
||||
package org.elasticsearch.shield.support;
|
||||
|
||||
import org.apache.lucene.util.automaton.Automaton;
|
||||
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
|
||||
import dk.brics.automaton.Automaton;
|
||||
import dk.brics.automaton.RunAutomaton;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -60,12 +60,12 @@ public class AutomatonsTests extends ElasticsearchTestCase {
|
||||
}
|
||||
|
||||
private void assertMatch(Automaton automaton, String text) {
|
||||
CharacterRunAutomaton runAutomaton = new CharacterRunAutomaton(automaton);
|
||||
RunAutomaton runAutomaton = new RunAutomaton(automaton);
|
||||
assertThat(runAutomaton.run(text), is(true));
|
||||
}
|
||||
|
||||
private void assertMismatch(Automaton automaton, String text) {
|
||||
CharacterRunAutomaton runAutomaton = new CharacterRunAutomaton(automaton);
|
||||
RunAutomaton runAutomaton = new RunAutomaton(automaton);
|
||||
assertThat(runAutomaton.run(text), is(false));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user