Skip to content

Commit

Permalink
Minor clean-ups from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Oct 21, 2016
1 parent df67896 commit 0164c04
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
Expand Up @@ -231,28 +231,28 @@ public class SecuritySettings
//========================================================================= //=========================================================================


@Internal @Internal
public static final Setting<File> security_log_filename = derivedSetting("dbms.security.log_path", public static final Setting<File> security_log_filename = derivedSetting( "dbms.security.log_path",
GraphDatabaseSettings.logs_directory, GraphDatabaseSettings.logs_directory,
( logs ) -> new File( logs, "security.log" ), ( logs ) -> new File( logs, "security.log" ),
PATH ); PATH );


@Description("Security log level threshold.") @Description( "Security log level threshold." )
public static final Setting<Level> security_log_level = setting( "dbms.logs.security.level", public static final Setting<Level> security_log_level = setting( "dbms.logs.security.level",
options( Level.class ), "INFO" ); options( Level.class ), "INFO" );


@Description( "Set to log successful authentication events." ) @Description( "Set to log successful authentication events." )
public static final Setting<Boolean> security_log_successful_authentication = public static final Setting<Boolean> security_log_successful_authentication =
setting("dbms.security.log_successful_authentication", BOOLEAN, "true" ); setting( "dbms.security.log_successful_authentication", BOOLEAN, "true" );


@Description( "Threshold for rotation of the security log." ) @Description( "Threshold for rotation of the security log." )
public static final Setting<Long> store_security_log_rotation_threshold = public static final Setting<Long> store_security_log_rotation_threshold =
setting("dbms.logs.security.rotation.size", BYTES, "20m", min(0L), max( Long.MAX_VALUE ) ); setting( "dbms.logs.security.rotation.size", BYTES, "20m", min(0L), max( Long.MAX_VALUE ) );


@Description( "Minimum time interval after last rotation of the security log before it may be rotated again." ) @Description( "Minimum time interval after last rotation of the security log before it may be rotated again." )
public static final Setting<Long> store_security_log_rotation_delay = public static final Setting<Long> store_security_log_rotation_delay =
setting("dbms.logs.security.rotation.delay", DURATION, "300s" ); setting( "dbms.logs.security.rotation.delay", DURATION, "300s" );


@Description( "Maximum number of history files for the security log." ) @Description( "Maximum number of history files for the security log." )
public static final Setting<Integer> store_security_log_max_archives = public static final Setting<Integer> store_security_log_max_archives =
setting("dbms.logs.security.rotation.keep_number", INTEGER, "7", min(1) ); setting( "dbms.logs.security.rotation.keep_number", INTEGER, "7", min(1) );
} }
Expand Up @@ -91,64 +91,42 @@ private void assertLogged( String name )
); );
} }


private class LoggingAuthPlugin extends LoggingAdapter implements AuthPlugin private class LoggingAuthPlugin extends TestAuthPlugin
{ {
@Override @Override
public String name() public void initialize( RealmOperations realmOperations ) throws Throwable
{
return "LoggingAuthPlugin";
}

@Override
public AuthInfo authenticateAndAuthorize( AuthToken authToken ) throws AuthenticationException
{ {
return null; logLines( realmOperations );
} }
} }


private class LoggingAuthenticationPlugin extends LoggingAdapter implements AuthenticationPlugin private class LoggingAuthenticationPlugin extends TestAuthenticationPlugin
{ {
@Override @Override
public String name() public void initialize( RealmOperations realmOperations ) throws Throwable
{
return "LoggingAuthenticationPlugin";
}

@Override
public AuthenticationInfo authenticate( AuthToken authToken ) throws AuthenticationException
{ {
return null; logLines( realmOperations );
} }
} }


private class LoggingAuthorizationPlugin extends LoggingAdapter implements AuthorizationPlugin private class LoggingAuthorizationPlugin extends TestAuthorizationPlugin
{ {
@Override @Override
public String name() public void initialize( RealmOperations realmOperations ) throws Throwable
{
return "LoggingAuthorizationPlugin";
}

@Override
public AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals )
{ {
return null; logLines( realmOperations );
} }
} }


abstract class LoggingAdapter extends RealmLifecycle.Adapter private static void logLines( RealmOperations realmOperations ) throws Throwable
{ {
@Override RealmOperations.Log log = realmOperations.log();
public void initialize( RealmOperations realmOperations ) throws Throwable if ( log.isDebugEnabled() )
{ {
RealmOperations.Log log = realmOperations.log(); log.debug( "debug line" );
if ( log.isDebugEnabled() )
{
log.debug( "debug line" );
}
log.info( "info line" );
log.warn( "warn line" );
log.error( "error line" );
} }
log.info( "info line" );
log.warn( "warn line" );
log.error( "error line" );
} }
} }
Expand Up @@ -19,7 +19,6 @@
*/ */
package org.neo4j.server.security.enterprise.log; package org.neo4j.server.security.enterprise.log;


import org.hamcrest.Matchers;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


Expand All @@ -37,6 +36,7 @@
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.array; import static org.hamcrest.Matchers.array;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.neo4j.helpers.collection.MapUtil.stringMap; import static org.neo4j.helpers.collection.MapUtil.stringMap;


public class SecurityLogTest public class SecurityLogTest
Expand All @@ -58,9 +58,9 @@ public void shouldRotateLog() throws IOException
FileSystemAbstraction fs = fileSystemRule.get(); FileSystemAbstraction fs = fileSystemRule.get();


File activeLogFile = config.get( SecuritySettings.security_log_filename ); File activeLogFile = config.get( SecuritySettings.security_log_filename );
assertThat( fs.fileExists( activeLogFile ), Matchers.equalTo( true ) ); assertThat( fs.fileExists( activeLogFile ), equalTo( true ) );
assertThat( fs.fileExists( archive( 1 ) ), Matchers.equalTo( true ) ); assertThat( fs.fileExists( archive( 1 ) ), equalTo( true ) );
assertThat( fs.fileExists( archive( 2 ) ), Matchers.equalTo( false ) ); assertThat( fs.fileExists( archive( 2 ) ), equalTo( false ) );


String[] activeLines = readLogFile( fs, activeLogFile ); String[] activeLines = readLogFile( fs, activeLogFile );
assertThat( activeLines, array( containsString( "line 2" ) ) ); assertThat( activeLines, array( containsString( "line 2" ) ) );
Expand Down

0 comments on commit 0164c04

Please sign in to comment.