Skip to content

Commit

Permalink
Fixed more tests using correct internal APIs
Browse files Browse the repository at this point in the history
In particular procedures pass a different transaction object in, and we need to control the index creation privileges more exactly.
  • Loading branch information
craigtaverner committed Mar 6, 2021
1 parent 07d5c70 commit 41d9bd1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
29 changes: 28 additions & 1 deletion src/main/java/org/neo4j/gis/spatial/index/IndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.internal.kernel.api.security.PrivilegeAction;
import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.api.security.OverriddenAccessMode;
import org.neo4j.kernel.internal.GraphDatabaseAPI;

import java.util.List;
Expand All @@ -15,9 +17,34 @@ public class IndexManager {
private final GraphDatabaseAPI db;
private final SecurityContext securityContext;

public static class IndexAccessMode extends OverriddenAccessMode {
public static SecurityContext withIndexCreate(SecurityContext securityContext) {
return securityContext.withMode(new IndexAccessMode(securityContext));
}

private IndexAccessMode(SecurityContext securityContext) {
super(Static.ACCESS, securityContext.mode());
}

@Override
public boolean allowsTokenCreates(PrivilegeAction action) {
return true;
}

@Override
public boolean allowsSchemaWrites() {
return true;
}

@Override
public boolean allowsSchemaWrites(PrivilegeAction action) {
return true;
}
}

public IndexManager(GraphDatabaseAPI db, SecurityContext securityContext) {
this.db = db;
this.securityContext = securityContext;
this.securityContext = IndexAccessMode.withIndexCreate(securityContext);
}

public IndexDefinition indexFor(Transaction tx, String indexName, Label label, String propertyKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.internal.helpers.collection.Iterators;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.coreapi.TransactionImpl;
import org.neo4j.kernel.impl.coreapi.InternalTransaction;

import java.util.Iterator;

Expand Down Expand Up @@ -51,7 +51,7 @@ public Iterable<Node> queryAll(Transaction tx) {
}

public Iterator<Node> query(Transaction tx, ExplicitIndexBackedPointIndex.Neo4jIndexSearcher searcher) {
KernelTransaction ktx = ((TransactionImpl) tx).kernelTransaction();
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
return searcher.search(ktx, label, propertyKey);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/neo4j/gis/spatial/osm/OSMImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,7 @@ private Transaction beginTx(GraphDatabaseService database) {
}

private Transaction beginIndexTx(GraphDatabaseService database) {
SecurityContext withSchema = securityContext.withMode(new OverriddenAccessMode(securityContext.mode(), AccessMode.Static.FULL));
return beginTx(database, withSchema);
return beginTx(database, IndexManager.IndexAccessMode.withIndexCreate(securityContext));
}

private static Transaction beginTx(GraphDatabaseService database, SecurityContext securityContext) {
Expand Down

0 comments on commit 41d9bd1

Please sign in to comment.