Skip to content

Commit

Permalink
Use a common global variable for the name of the initial user
Browse files Browse the repository at this point in the history
  • Loading branch information
Mats-SX committed Oct 5, 2016
1 parent 8dea75c commit 105d98e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
Expand Up @@ -40,6 +40,8 @@
import org.neo4j.server.security.auth.FileUserRepository;
import org.neo4j.server.security.auth.User;

import static org.neo4j.server.security.auth.UserManager.INITIAL_USER_NAME;

public class SetInitialPasswordCommand implements AdminCommand
{
public static class Provider extends AdminCommand.Provider
Expand Down Expand Up @@ -69,7 +71,6 @@ public AdminCommand create( Path homeDir, Path configDir, OutsideWorld outsideWo
}
}

private static final String INITIAL_USER_NAME = "neo4j";
private final Path homeDir;
private final Path configDir;
private OutsideWorld outsideWorld;
Expand Down
Expand Up @@ -33,6 +33,8 @@
import org.neo4j.kernel.api.security.exception.InvalidAuthTokenException;
import org.neo4j.server.security.auth.exception.ConcurrentModificationException;

import static org.neo4j.server.security.auth.UserManager.INITIAL_USER_NAME;

/**
* Manages server authentication and authorization.
* <p>
Expand Down Expand Up @@ -79,10 +81,10 @@ public void start() throws Throwable

if ( userRepository.numberOfUsers() == 0 )
{
User neo4j = newUser( "neo4j", "neo4j", true );
User neo4j = newUser( INITIAL_USER_NAME, "neo4j", true );
if ( initialUserRepository.numberOfUsers() > 0 )
{
User user = initialUserRepository.getUserByName( "neo4j" );
User user = initialUserRepository.getUserByName( INITIAL_USER_NAME );
if ( user != null )
{
userRepository.update( neo4j, user );
Expand Down
Expand Up @@ -26,6 +26,8 @@

public interface UserManager
{
String INITIAL_USER_NAME = "neo4j";

User newUser( String username, String initialPassword, boolean requirePasswordChange )
throws IOException, InvalidArgumentsException;

Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.neo4j.logging.NullLogProvider;
import org.neo4j.server.security.auth.FileUserRepository;
import org.neo4j.server.security.auth.User;
import org.neo4j.server.security.auth.UserManager;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -108,7 +109,7 @@ private void assertAuthIniFile(String password) throws Throwable
assertTrue( fileSystem.fileExists( authIniFile ) );
FileUserRepository userRepository = new FileUserRepository( fileSystem, authIniFile, NullLogProvider.getInstance() );
userRepository.start();
User neo4j = userRepository.getUserByName( "neo4j" );
User neo4j = userRepository.getUserByName( UserManager.INITIAL_USER_NAME );
assertNotNull( neo4j );
assertTrue( neo4j.credentials().matchesPassword( password ) );
assertFalse( neo4j.hasFlag( User.PASSWORD_CHANGE_REQUIRED ) );
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.server.security.auth.CommunitySecurityModule;
import org.neo4j.server.security.auth.FileUserRepository;
import org.neo4j.server.security.auth.User;
import org.neo4j.server.security.auth.UserManager;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -124,7 +125,7 @@ private void assertAuthIniFile( String password ) throws Throwable
FileUserRepository userRepository = new FileUserRepository( fileSystem, authInitFile,
NullLogProvider.getInstance() );
userRepository.start();
User neo4j = userRepository.getUserByName( "neo4j" );
User neo4j = userRepository.getUserByName( UserManager.INITIAL_USER_NAME );
assertNotNull( neo4j );
assertTrue( neo4j.credentials().matchesPassword( password ) );
assertFalse( neo4j.hasFlag( User.PASSWORD_CHANGE_REQUIRED ) );
Expand Down
Expand Up @@ -212,16 +212,16 @@ private Set<String> ensureDefaultUsers() throws Throwable
{
if ( userRepository.numberOfUsers() == 0 )
{
User neo4j = newUser( "neo4j", "neo4j", true );
User neo4j = newUser( INITIAL_USER_NAME, "neo4j", true );
if ( initialUserRepository.numberOfUsers() > 0 )
{
User initUser = initialUserRepository.getUserByName( "neo4j" );
User initUser = initialUserRepository.getUserByName( INITIAL_USER_NAME );
if (initUser != null)
{
userRepository.update( neo4j, initUser );
}
}
return Collections.singleton( "neo4j" );
return Collections.singleton( INITIAL_USER_NAME );
}
}
return Collections.emptySet();
Expand Down

0 comments on commit 105d98e

Please sign in to comment.