Search in sources :

Example 6 with FileUserRepository

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

the class SetDefaultAdminCommand method setDefaultAdmin.

private void setDefaultAdmin(String username) throws Throwable {
    FileSystemAbstraction fileSystem = outsideWorld.fileSystem();
    Config config = loadNeo4jConfig();
    FileUserRepository users = CommunitySecurityModule.getUserRepository(config, NullLogProvider.getInstance(), fileSystem);
    users.init();
    users.start();
    Set<String> userNames = users.getAllUsernames();
    users.stop();
    users.shutdown();
    if (userNames.isEmpty()) {
        FileUserRepository initialUsers = CommunitySecurityModule.getInitialUserRepository(config, NullLogProvider.getInstance(), fileSystem);
        initialUsers.init();
        initialUsers.start();
        userNames = initialUsers.getAllUsernames();
        initialUsers.stop();
        initialUsers.shutdown();
    }
    if (!userNames.contains(username)) {
        throw new CommandFailed(String.format("no such user: '%s'", username));
    }
    File adminIniFile = new File(CommunitySecurityModule.getUserRepositoryFile(config).getParentFile(), ADMIN_INI);
    if (fileSystem.fileExists(adminIniFile)) {
        fileSystem.deleteFile(adminIniFile);
    }
    UserRepository admins = new FileUserRepository(fileSystem, adminIniFile, NullLogProvider.getInstance());
    admins.init();
    admins.start();
    admins.create(new User.Builder(username, Credential.INACCESSIBLE).build());
    admins.stop();
    admins.shutdown();
    outsideWorld.stdOutLine("default admin user set to '" + username + "'");
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) Config(org.neo4j.kernel.configuration.Config) CommandFailed(org.neo4j.commandline.admin.CommandFailed) File(java.io.File)

Example 7 with FileUserRepository

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

the class SetInitialPasswordCommand method setPassword.

private void setPassword(String password) throws Throwable {
    Config config = loadNeo4jConfig();
    if (realUsersExist(config)) {
        throw new CommandFailed("initial password was not set because live Neo4j-users were detected.");
    } else {
        File file = CommunitySecurityModule.getInitialUserRepositoryFile(config);
        FileSystemAbstraction fileSystem = outsideWorld.fileSystem();
        if (fileSystem.fileExists(file)) {
            fileSystem.deleteFile(file);
        }
        FileUserRepository userRepository = new FileUserRepository(fileSystem, file, NullLogProvider.getInstance());
        userRepository.start();
        userRepository.create(new User.Builder(INITIAL_USER_NAME, Credential.forPassword(password)).withRequiredPasswordChange(false).build());
        userRepository.shutdown();
        outsideWorld.stdOutLine("Changed password for user '" + INITIAL_USER_NAME + "'.");
    }
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) User(org.neo4j.kernel.impl.security.User) Config(org.neo4j.kernel.configuration.Config) CommandFailed(org.neo4j.commandline.admin.CommandFailed) File(java.io.File)

Example 8 with FileUserRepository

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

the class SetInitialPasswordCommandIT method assertAuthIniFile.

private void assertAuthIniFile(String password) throws Throwable {
    File authIniFile = getAuthFile("auth.ini");
    assertTrue(fileSystem.fileExists(authIniFile));
    FileUserRepository userRepository = new FileUserRepository(fileSystem, authIniFile, NullLogProvider.getInstance());
    userRepository.start();
    User neo4j = userRepository.getUserByName(UserManager.INITIAL_USER_NAME);
    assertNotNull(neo4j);
    assertTrue(neo4j.credentials().matchesPassword(password));
    assertFalse(neo4j.hasFlag(User.PASSWORD_CHANGE_REQUIRED));
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) User(org.neo4j.kernel.impl.security.User) File(java.io.File)

Aggregations

FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)8 File (java.io.File)6 User (org.neo4j.kernel.impl.security.User)3 CommandFailed (org.neo4j.commandline.admin.CommandFailed)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 Config (org.neo4j.kernel.configuration.Config)2 UserRepository (org.neo4j.server.security.auth.UserRepository)2 Before (org.junit.Before)1 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)1 PasswordPolicy (org.neo4j.kernel.api.security.PasswordPolicy)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