Skip to content

Commit

Permalink
Ensure security log is closed on LifeCycle.shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner committed Sep 15, 2016
1 parent 265f975 commit ed426bb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
Expand Up @@ -228,6 +228,8 @@ private void editionInvariants( PlatformModule platformModule, Dependencies depe
securityLog = SecurityLog.create( config, logging.getInternalLog( GraphDatabaseFacade.class ),
platformModule.fileSystem, platformModule.jobScheduler );

life.add( securityLog );

life.add( dependencies.satisfyDependency( createAuthManager( config, logging,
platformModule.fileSystem, platformModule.jobScheduler ) ) );

Expand Down
Expand Up @@ -155,6 +155,8 @@ protected Log authManagerLog()
securityLog = SecurityLog.create( config, logging.getInternalLog( GraphDatabaseFacade.class ),
platformModule.fileSystem, platformModule.jobScheduler );

life.add( securityLog );

life.add( dependencies.satisfyDependency( createAuthManager( config, logging,
platformModule.fileSystem, platformModule.jobScheduler ) ) );

Expand Down
Expand Up @@ -515,6 +515,8 @@ public void elected( String role, InstanceId instanceId, URI electedMember )
securityLog = SecurityLog.create( config, logging.getInternalLog( GraphDatabaseFacade.class ),
platformModule.fileSystem, platformModule.jobScheduler );

life.add( securityLog );

life.add( dependencies.satisfyDependency( createAuthManager( config, logging,
platformModule.fileSystem, platformModule.jobScheduler ) ) );

Expand Down
Expand Up @@ -63,6 +63,10 @@ public EnterpriseEditionModule( PlatformModule platformModule )
platformModule.dependencies.satisfyDependency( new IdBasedStoreEntityCounters( this.idGeneratorFactory ) );
ioLimiter = new ConfigurableIOLimiter( platformModule.config );
platformModule.dependencies.satisfyDependency( createSessionTracker() );
if ( securityLog != null )
{
platformModule.life.add( securityLog );
}
}

@Override
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.enterprise.configuration.EnterpriseEditionSettings;
import org.neo4j.kernel.impl.util.JobScheduler;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.logging.FormattedLog;
import org.neo4j.logging.Log;
import org.neo4j.logging.Logger;
Expand All @@ -38,35 +39,31 @@
import static org.neo4j.helpers.Strings.escape;
import static org.neo4j.kernel.impl.enterprise.configuration.EnterpriseEditionSettings.security_log_filename;

public class SecurityLog implements Log
public class SecurityLog extends LifecycleAdapter implements Log
{
private RotatingFileOutputStreamSupplier rotatingSupplier;
private final Log inner;

public SecurityLog( Config config, FileSystemAbstraction fileSystem, Executor executor ) throws IOException
{
this( createLog( config, fileSystem, executor ) );
}

public SecurityLog( Log log )
{
inner = log;
}

private static AsyncLog createLog( Config config, FileSystemAbstraction fileSystem, Executor executor )
throws IOException
{
FormattedLog.Builder builder = FormattedLog.withUTCTimeZone();
File logFile = config.get( security_log_filename );

RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile,
rotatingSupplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile,
config.get( EnterpriseEditionSettings.store_security_log_rotation_threshold ),
config.get( EnterpriseEditionSettings.store_security_log_rotation_delay ),
config.get( EnterpriseEditionSettings.store_security_log_max_archives ), executor );

return new AsyncLog(
this.inner = new AsyncLog(
event -> executor.execute( event::process ),
builder.toOutputStream( rotatingSupplier )
);
);
}

/* Only used for tests */
public SecurityLog( Log log )
{
inner = log;
}

private static String withSubject( AuthSubject subject, String msg )
Expand Down Expand Up @@ -220,4 +217,14 @@ public static SecurityLog create( Config config, Log log, FileSystemAbstraction
return null;
}
}

@Override
public void shutdown() throws Throwable
{
if ( this.rotatingSupplier != null )
{
this.rotatingSupplier.close();
this.rotatingSupplier = null;
}
}
}

0 comments on commit ed426bb

Please sign in to comment.