use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.
the class OnlineBackupCommandTest method exitCode.
private Matcher<CommandFailed> exitCode(final int expectedCode) {
return new BaseMatcher<CommandFailed>() {
@Override
public void describeTo(Description description) {
description.appendText("expected exit code ").appendValue(expectedCode);
}
@Override
public void describeMismatch(Object o, Description description) {
if (o instanceof CommandFailed) {
CommandFailed e = (CommandFailed) o;
description.appendText("but it was ").appendValue(e.code());
} else {
description.appendText("but exception is not a CommandFailed exception");
}
}
@Override
public boolean matches(Object o) {
if (o instanceof CommandFailed) {
CommandFailed e = (CommandFailed) o;
return expectedCode == e.code();
}
return false;
}
};
}
use of org.neo4j.commandline.admin.CommandFailed 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.commandline.admin.CommandFailed 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 + "'.");
}
}
Aggregations