Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.3' into 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfurmanski committed Mar 19, 2018
2 parents fd6ae5d + 169513a commit 74ad7bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void registerEditionSpecificProcedures( Procedures procedures ) throws Ke
procedures.register( new ClusterOverviewProcedure( topologyService, logProvider ) );
procedures.register( new CoreRoleProcedure( consensusModule.raftMachine() ) );
procedures.register( new InstalledProtocolsProcedure( clientInstalledProtocols, serverInstalledProtocols ) );
procedures.registerComponent( Replicator.class, x -> replicationModule.getReplicator(), true );
procedures.registerComponent( Replicator.class, x -> replicationModule.getReplicator(), false );
procedures.registerProcedure( ReplicationBenchmarkProcedure.class );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import java.util.stream.Stream;

import org.neo4j.causalclustering.core.state.machines.dummy.DummyRequest;
import org.neo4j.graphdb.security.AuthorizationViolationException;
import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.logging.Log;
import org.neo4j.procedure.Context;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure;

import static java.lang.Math.toIntExact;
import static org.neo4j.graphdb.security.AuthorizationViolationException.PERMISSION_DENIED;
import static org.neo4j.procedure.Mode.DBMS;

@SuppressWarnings( "unused" )
Expand All @@ -40,6 +43,9 @@ public class ReplicationBenchmarkProcedure
@Context
public Replicator replicator;

@Context
public SecurityContext securityContext;

@Context
public Log log;

Expand All @@ -50,6 +56,8 @@ public class ReplicationBenchmarkProcedure
@Procedure( name = "dbms.cluster.benchmark.start", mode = DBMS )
public synchronized void start( @Name( "nThreads" ) Long nThreads, @Name( "blockSize" ) Long blockSize )
{
checkSecurity();

if ( workers != null )
{
throw new IllegalStateException( "Already running." );
Expand All @@ -72,6 +80,8 @@ public synchronized void start( @Name( "nThreads" ) Long nThreads, @Name( "block
@Procedure( name = "dbms.cluster.benchmark.stop", mode = DBMS )
public synchronized Stream<BenchmarkResult> stop() throws InterruptedException
{
checkSecurity();

if ( workers == null )
{
throw new IllegalStateException( "Not running." );
Expand Down Expand Up @@ -105,6 +115,15 @@ public synchronized Stream<BenchmarkResult> stop() throws InterruptedException
return Stream.of( new BenchmarkResult( totalRequests, totalBytes, runTime ) );
}

private void checkSecurity() throws AuthorizationViolationException
{
securityContext.assertCredentialsNotExpired();
if ( !securityContext.isAdmin() )
{
throw new AuthorizationViolationException( PERMISSION_DENIED );
}
}

private class Worker implements Runnable
{
private final int blockSize;
Expand Down

0 comments on commit 74ad7bd

Please sign in to comment.