Upgraded to Lucene 4.10 and fixed the build

The automaton support changed quite a bit in 4.10 which required determinizing all the automatons used in the Privilege

Original commit: elastic/x-pack-elasticsearch@96a82f0f5d
This commit is contained in:
uboness 2014-09-06 15:41:22 +02:00
parent 5cc7d55568
commit f4b4075cfa
5 changed files with 29 additions and 20 deletions

View File

@ -30,7 +30,7 @@
</repositories>
<properties>
<lucene.version>4.9.0</lucene.version>
<lucene.version>4.10.0</lucene.version>
<elasticsearch.version>1.4.0-SNAPSHOT</elasticsearch.version>
<tests.jvms>auto</tests.jvms>

View File

@ -5,8 +5,9 @@
*/
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.BasicAutomata;
import org.apache.lucene.util.automaton.Operations;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.action.get.GetAction;
@ -74,7 +75,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, BasicAutomata.makeEmpty());
public static final Index NONE = new Index(Name.NONE, Automata.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", "indices:admin/create");
@ -173,7 +174,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, BasicAutomata.makeEmpty());
public static final Cluster NONE = new Cluster(Name.NONE, Automata.makeEmpty());
public static final Cluster ALL = new Cluster(Name.ALL, "cluster:.*", "indices:admin/template/.*");
public static final Cluster MONITOR = new Cluster("monitor", "cluster:monitor/.*");
@ -285,7 +286,7 @@ public abstract class Privilege<P extends Privilege<P>> {
if (this.implies(other)) {
return (P) this;
}
return create(name.add(other.name), automaton.union(other.automaton));
return create(name.add(other.name), Automatons.unionAndDeterminize(automaton, other.automaton));
}
protected P minus(P other) {
@ -295,12 +296,12 @@ public abstract class Privilege<P extends Privilege<P>> {
if (other == none() || !this.implies(other)) {
return (P) this;
}
return create(name.remove(other.name), automaton.minus(other.automaton));
return create(name.remove(other.name), Automatons.minusAndDeterminize(automaton, other.automaton));
}
@Override
public boolean implies(P other) {
return other.automaton.subsetOf(automaton);
return Operations.subsetOf(other.automaton, automaton);
}
public String toString() {

View File

@ -5,13 +5,15 @@
*/
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.BasicAutomata;
import org.apache.lucene.util.automaton.MinimizationOperations;
import org.apache.lucene.util.automaton.RegExp;
import java.util.Collection;
import static org.apache.lucene.util.automaton.MinimizationOperations.minimize;
import static org.apache.lucene.util.automaton.Operations.*;
/**
*
*/
@ -22,29 +24,35 @@ public final class Automatons {
public static Automaton patterns(String... patterns) {
if (patterns.length == 0) {
return BasicAutomata.makeEmpty();
return Automata.makeEmpty();
}
Automaton automaton = new RegExp(patterns[0]).toAutomaton();
for (String pattern : patterns) {
automaton = automaton.union(new RegExp(pattern).toAutomaton());
automaton = union(automaton, new RegExp(pattern).toAutomaton());
}
MinimizationOperations.minimize(automaton);
return automaton;
return determinize(minimize(automaton));
}
public static Automaton patterns(Collection<String> patterns) {
if (patterns.isEmpty()) {
return BasicAutomata.makeEmpty();
return Automata.makeEmpty();
}
Automaton automaton = null;
for (String pattern : patterns) {
if (automaton == null) {
automaton = new RegExp(pattern).toAutomaton();
} else {
automaton = automaton.union(new RegExp(pattern).toAutomaton());
automaton = union(automaton, new RegExp(pattern).toAutomaton());
}
}
MinimizationOperations.minimize(automaton);
return automaton;
return determinize(minimize(automaton));
}
public static Automaton unionAndDeterminize(Automaton a1, Automaton a2) {
return determinize(union(a1, a2));
}
public static Automaton minusAndDeterminize(Automaton a1, Automaton a2) {
return determinize(minus(a1, a2));
}
}

View File

@ -59,7 +59,7 @@ public class SecuredTransportService extends TransportService {
return handler.newInstance();
}
@Override
@Override @SuppressWarnings("unchecked")
public void messageReceived(TransportRequest request, TransportChannel channel) throws Exception {
try {
filter.inboundRequest(action, request);
@ -96,7 +96,7 @@ public class SecuredTransportService extends TransportService {
return handler.newInstance();
}
@Override
@Override @SuppressWarnings("unchecked")
public void handleResponse(TransportResponse response) {
try {
filter.inboundResponse(response);

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.shield.authz;
import org.apache.lucene.util.LuceneTestCase;
import com.carrotsearch.randomizedtesting.annotations.Repeat;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.shield.support.AutomatonPredicate;
import org.elasticsearch.shield.support.Automatons;