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 + "'");
}
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 + "'.");
}
}
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));
}
Aggregations