Search in sources :

Example 1 with FileUserRepository

use of org.neo4j.server.security.auth.FileUserRepository in project neo4j by neo4j.

the class InternalFlatFileRealmIT method setup.

@Before
public void setup() throws Throwable {
    fs = new EvilFileSystem(new EphemeralFileSystemAbstraction());
    userStoreFile = new File("dbms", "auth");
    roleStoreFile = new File("dbms", "roles");
    final UserRepository userRepository = new FileUserRepository(fs, userStoreFile, logProvider);
    final RoleRepository roleRepository = new FileRoleRepository(fs, roleStoreFile, logProvider);
    final UserRepository initialUserRepository = CommunitySecurityModule.getInitialUserRepository(Config.defaults(), logProvider, fs);
    final UserRepository defaultAdminRepository = EnterpriseSecurityModule.getDefaultAdminRepository(Config.defaults(), logProvider, fs);
    final PasswordPolicy passwordPolicy = new BasicPasswordPolicy();
    AuthenticationStrategy authenticationStrategy = new RateLimitedAuthenticationStrategy(Clocks.systemClock(), 3);
    realm = new InternalFlatFileRealm(userRepository, roleRepository, passwordPolicy, authenticationStrategy, true, true, jobScheduler, initialUserRepository, defaultAdminRepository);
    realm.init();
    realm.start();
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) AuthenticationStrategy(org.neo4j.server.security.auth.AuthenticationStrategy) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) PasswordPolicy(org.neo4j.kernel.api.security.PasswordPolicy) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) File(java.io.File) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) Before(org.junit.Before)

Example 2 with FileUserRepository

use of org.neo4j.server.security.auth.FileUserRepository in project neo4j by neo4j.

the class SetDefaultAdminCommandIT method insertUser.

private void insertUser(String username, boolean initial) throws Throwable {
    File userFile = getAuthFile(initial ? CommunitySecurityModule.INITIAL_USER_STORE_FILENAME : CommunitySecurityModule.USER_STORE_FILENAME);
    FileUserRepository userRepository = new FileUserRepository(fileSystem, userFile, NullLogProvider.getInstance());
    userRepository.start();
    userRepository.create(new User.Builder(username, Credential.INACCESSIBLE).build());
    assertTrue(userRepository.getAllUsernames().contains(username));
    userRepository.stop();
    userRepository.shutdown();
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) File(java.io.File)

Example 3 with FileUserRepository

use of org.neo4j.server.security.auth.FileUserRepository in project neo4j by neo4j.

the class SetDefaultAdminCommand method execute.

@Override
public void execute() {
    Config config = loadNeo4jConfig();
    try {
        Path adminIniFile = CommunitySecurityModule.getUserRepositoryFile(config).getParent().resolve(ADMIN_INI);
        if (ctx.fs().fileExists(adminIniFile)) {
            ctx.fs().deleteFile(adminIniFile);
        }
        UserRepository admins = new FileUserRepository(ctx.fs(), adminIniFile, NullLogProvider.getInstance());
        admins.init();
        admins.start();
        admins.create(new User.Builder(username, LegacyCredential.INACCESSIBLE).build());
        admins.stop();
        admins.shutdown();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    ctx.out().println("default admin user set to '" + username + "'");
}
Also used : Path(java.nio.file.Path) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) Config(org.neo4j.configuration.Config)

Example 4 with FileUserRepository

use of org.neo4j.server.security.auth.FileUserRepository in project neo4j by neo4j.

the class SetInitialPasswordCommandTest method assertAuthIniFile.

private void assertAuthIniFile(String password) throws Throwable {
    assertTrue(fileSystem.fileExists(authInitFile));
    FileUserRepository userRepository = new FileUserRepository(fileSystem, authInitFile, NullLogProvider.getInstance());
    userRepository.start();
    User neo4j = userRepository.getUserByName(AuthManager.INITIAL_USER_NAME);
    assertNotNull(neo4j);
    assertTrue(neo4j.credentials().matchesPassword(UTF8.encode(password)));
    assertFalse(neo4j.hasFlag(User.PASSWORD_CHANGE_REQUIRED));
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) User(org.neo4j.kernel.impl.security.User)

Example 5 with FileUserRepository

use of org.neo4j.server.security.auth.FileUserRepository in project neo4j by neo4j.

the class SetDefaultAdminCommandIT method assertAdminIniFile.

private void assertAdminIniFile(String username) throws Throwable {
    Path adminIniFile = homeDir.resolve("data").resolve("dbms").resolve(SetDefaultAdminCommand.ADMIN_INI);
    Assertions.assertTrue(fileSystem.fileExists(adminIniFile));
    FileUserRepository userRepository = new FileUserRepository(fileSystem, adminIniFile, NullLogProvider.getInstance());
    userRepository.start();
    assertThat(userRepository.getAllUsernames()).contains(username);
    userRepository.stop();
    userRepository.shutdown();
}
Also used : Path(java.nio.file.Path) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository)

Aggregations

FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)12 User (org.neo4j.kernel.impl.security.User)6 File (java.io.File)5 Path (java.nio.file.Path)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 UserRepository (org.neo4j.server.security.auth.UserRepository)3 IOException (java.io.IOException)2 CommandFailed (org.neo4j.commandline.admin.CommandFailed)2 Config (org.neo4j.configuration.Config)2 Config (org.neo4j.kernel.configuration.Config)2 Before (org.junit.Before)1 CommandFailedException (org.neo4j.cli.CommandFailedException)1 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)1 PasswordPolicy (org.neo4j.kernel.api.security.PasswordPolicy)1 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)1 AuthenticationStrategy (org.neo4j.server.security.auth.AuthenticationStrategy)1 BasicPasswordPolicy (org.neo4j.server.security.auth.BasicPasswordPolicy)1 RateLimitedAuthenticationStrategy (org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy)1