Skip to content

Commit

Permalink
Rename FileUserRealm to InternalFlatFileRealm
Browse files Browse the repository at this point in the history
  • Loading branch information
henriknyman committed Jun 27, 2016
1 parent 38286c9 commit 39168ff
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
Expand Up @@ -57,7 +57,7 @@ public EnterpriseAuthManagerFactory()
@Override
public AuthManager newInstance( Config config, LogProvider logProvider )
{
FileUserRealm internalRealm = createInternalRealm( config, logProvider );
InternalFlatFileRealm internalRealm = createInternalRealm( config, logProvider );

List<Realm> realms = new ArrayList<>( 2 );

Expand All @@ -76,7 +76,7 @@ public AuthManager newInstance( Config config, LogProvider logProvider )
return new MultiRealmAuthManager( internalRealm, realms );
}

private FileUserRealm createInternalRealm( Config config, LogProvider logProvider )
private InternalFlatFileRealm createInternalRealm( Config config, LogProvider logProvider )
{
// Resolve auth store file names
File authStoreDir = config.get( DatabaseManagementSystemSettings.auth_store_directory );
Expand All @@ -100,7 +100,7 @@ private FileUserRealm createInternalRealm( Config config, LogProvider logProvide

AuthenticationStrategy authenticationStrategy = new RateLimitedAuthenticationStrategy( systemUTC(), 3 );

return new FileUserRealm( userRepository, roleRepository, passwordPolicy, authenticationStrategy,
return new InternalFlatFileRealm( userRepository, roleRepository, passwordPolicy, authenticationStrategy,
true );
}
}
Expand Up @@ -60,9 +60,9 @@
import org.neo4j.server.security.auth.exception.ConcurrentModificationException;

/**
* Shiro realm wrapping FileUserRepository
* Shiro realm wrapping FileUserRepository and FileRoleRepository
*/
public class FileUserRealm extends AuthorizingRealm implements ShiroRealmLifecycle, EnterpriseUserManager
public class InternalFlatFileRealm extends AuthorizingRealm implements ShiroRealmLifecycle, EnterpriseUserManager
{
/**
* This flag is used in the same way as User.PASSWORD_CHANGE_REQUIRED, but it's
Expand Down Expand Up @@ -94,8 +94,9 @@ public Collection<Permission> resolvePermissionsInRole( String roleString )
private final boolean authenticationEnabled;
private final Map<String,SimpleRole> roles;

public FileUserRealm( UserRepository userRepository, RoleRepository roleRepository, PasswordPolicy passwordPolicy,
AuthenticationStrategy authenticationStrategy, boolean authenticationEnabled )
public InternalFlatFileRealm( UserRepository userRepository, RoleRepository roleRepository,
PasswordPolicy passwordPolicy, AuthenticationStrategy authenticationStrategy,
boolean authenticationEnabled )
{
super();

Expand Down Expand Up @@ -229,7 +230,7 @@ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token
// TODO: This will not work if AuthenticationInfo is cached,
// unless you always do SecurityManager.logout properly (which will invalidate the cache)
// For REST we may need to connect HttpSessionListener.sessionDestroyed with logout
if ( user.hasFlag( FileUserRealm.IS_SUSPENDED ) )
if ( user.hasFlag( InternalFlatFileRealm.IS_SUSPENDED ) )
{
throw new DisabledAccountException( "User " + user.name() + " is suspended" );
}
Expand Down
Expand Up @@ -45,15 +45,15 @@ public class ShiroAuthManager extends BasicAuthManager implements EnterpriseAuth
{
protected DefaultSecurityManager securityManager;
private final EhCacheManager cacheManager;
private final FileUserRealm realm;
private final InternalFlatFileRealm realm;
private final RoleRepository roleRepository;

public ShiroAuthManager( UserRepository userRepository, RoleRepository roleRepository,
PasswordPolicy passwordPolicy, AuthenticationStrategy authStrategy )
{
super( userRepository, passwordPolicy, authStrategy, true /* auth always enabled */ );

realm = new FileUserRealm( userRepository, roleRepository, passwordPolicy, authStrategy, true );
realm = new InternalFlatFileRealm( userRepository, roleRepository, passwordPolicy, authStrategy, true );
// TODO: Maybe MemoryConstrainedCacheManager is good enough if we do not need timeToLiveSeconds?
// It would be one less dependency.
// Or we could try to reuse Hazelcast which is already a dependency, but we would need to write some
Expand Down
Expand Up @@ -241,15 +241,15 @@ public void shouldNotAllowDeletingYourself() throws Exception
public void shouldSuspendUser() throws Exception
{
testCallEmpty( adminSubject, "CALL dbms.suspendUser('readSubject')" );
assertTrue( manager.getUser( "readSubject" ).hasFlag( FileUserRealm.IS_SUSPENDED ) );
assertTrue( manager.getUser( "readSubject" ).hasFlag( InternalFlatFileRealm.IS_SUSPENDED ) );
}

@Test
public void shouldSuspendSuspendedUser() throws Exception
{
testCallEmpty( adminSubject, "CALL dbms.suspendUser('readSubject')" );
testCallEmpty( adminSubject, "CALL dbms.suspendUser('readSubject')" );
assertTrue( manager.getUser( "readSubject" ).hasFlag( FileUserRealm.IS_SUSPENDED ) );
assertTrue( manager.getUser( "readSubject" ).hasFlag( InternalFlatFileRealm.IS_SUSPENDED ) );
}

@Test
Expand Down Expand Up @@ -287,7 +287,7 @@ public void shouldActivateUser() throws Exception
{
manager.suspendUser( "readSubject" );
testCallEmpty( adminSubject, "CALL dbms.activateUser('readSubject')" );
assertFalse( manager.getUser( "readSubject" ).hasFlag( FileUserRealm.IS_SUSPENDED ) );
assertFalse( manager.getUser( "readSubject" ).hasFlag( InternalFlatFileRealm.IS_SUSPENDED ) );
}

@Test
Expand All @@ -296,7 +296,7 @@ public void shouldActivateActiveUser() throws Exception
manager.suspendUser( "readSubject" );
testCallEmpty( adminSubject, "CALL dbms.activateUser('readSubject')" );
testCallEmpty( adminSubject, "CALL dbms.activateUser('readSubject')" );
assertFalse( manager.getUser( "readSubject" ).hasFlag( FileUserRealm.IS_SUSPENDED ) );
assertFalse( manager.getUser( "readSubject" ).hasFlag( InternalFlatFileRealm.IS_SUSPENDED ) );
}

/*
Expand Down
Expand Up @@ -44,7 +44,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class FileUserRealmTest
public class InternalFlatFileRealmTest
{
RoleRepository roleRepository;
UserRepository userRepository;
Expand All @@ -54,7 +54,7 @@ public class FileUserRealmTest
private static final String USERNAME = "neo4j";
private static final String ROLE = "admin";

public FileUserRealmTest() throws Exception
public InternalFlatFileRealmTest() throws Exception
{
super();
setup();
Expand Down Expand Up @@ -96,7 +96,7 @@ public void testThreadedTests() throws Exception

try
{
runner.runTests( getClass(), FileUserRealm.class );
runner.runTests( getClass(), InternalFlatFileRealm.class );
}
// We need to work around an issue that we do not get failures from the test framework
catch ( final RuntimeException e )
Expand All @@ -119,8 +119,8 @@ public void addUserToRoleShouldBeAtomic() throws Exception
// Create a code position for where we want to break in the main thread
CodePosition codePosition = getCodePositionAfterCall( "addUserToRole", "getUserByName" );

FileUserRealm realm = new FileUserRealm( userRepository, roleRepository, passwordPolicy, authenticationStrategy,
true );
InternalFlatFileRealm realm = new InternalFlatFileRealm( userRepository, roleRepository, passwordPolicy,
authenticationStrategy, true );

// When
RunResult result = InterleavedRunner.interleave(
Expand All @@ -142,8 +142,8 @@ public void deleteUserShouldBeAtomic() throws Exception
// Create a code position for where we want to break in the main thread
CodePosition codePosition = getCodePositionAfterCall( "deleteUser", "getUserByName" );

FileUserRealm realm = new FileUserRealm( userRepository, roleRepository, passwordPolicy, authenticationStrategy,
true );
InternalFlatFileRealm realm = new InternalFlatFileRealm( userRepository, roleRepository, passwordPolicy,
authenticationStrategy, true );

// When
RunResult result = InterleavedRunner.interleave(
Expand All @@ -159,29 +159,29 @@ public void deleteUserShouldBeAtomic() throws Exception

private CodePosition getCodePositionAfterCall( String caller, String called )
{
ClassInstrumentation instrumentation = Instrumentation.getClassInstrumentation( FileUserRealm.class );
ClassInstrumentation instrumentation = Instrumentation.getClassInstrumentation( InternalFlatFileRealm.class );
CodePosition codePosition = instrumentation.afterCall( caller, called );
return codePosition;
}

// Base class for the main thread
private class AdminMain extends MainRunnableImpl<FileUserRealm>
private class AdminMain extends MainRunnableImpl<InternalFlatFileRealm>
{
protected FileUserRealm realm;
protected InternalFlatFileRealm realm;

public AdminMain( FileUserRealm realm )
public AdminMain( InternalFlatFileRealm realm )
{
this.realm = realm;
}

@Override
public Class<FileUserRealm> getClassUnderTest()
public Class<InternalFlatFileRealm> getClassUnderTest()
{
return FileUserRealm.class;
return InternalFlatFileRealm.class;
}

@Override
public FileUserRealm getMainObject()
public InternalFlatFileRealm getMainObject()
{
return realm;
}
Expand All @@ -193,9 +193,9 @@ public void run() throws Exception
}

// Base class for the secondary thread
private class AdminSecondary extends SecondaryRunnableImpl<FileUserRealm,AdminMain>
private class AdminSecondary extends SecondaryRunnableImpl<InternalFlatFileRealm,AdminMain>
{
protected FileUserRealm realm;
protected InternalFlatFileRealm realm;

@Override
public void initialize( AdminMain main ) throws Exception
Expand All @@ -216,7 +216,7 @@ public void run() throws Exception
// Add user to role
private class AddUserToRoleInMain extends AdminMain
{
public AddUserToRoleInMain( FileUserRealm realm )
public AddUserToRoleInMain( InternalFlatFileRealm realm )
{
super( realm );
}
Expand All @@ -241,7 +241,7 @@ public void run() throws Exception
// Delete user
private class DeleteUserInMain extends AdminMain
{
public DeleteUserInMain( FileUserRealm realm )
public DeleteUserInMain( InternalFlatFileRealm realm )
{
super( realm );
}
Expand Down

0 comments on commit 39168ff

Please sign in to comment.