Search in sources :

Example 16 with CommandFailed

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;
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) CommandFailed(org.neo4j.commandline.admin.CommandFailed)

Example 17 with CommandFailed

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 + "'");
}
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 18 with CommandFailed

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

Aggregations

CommandFailed (org.neo4j.commandline.admin.CommandFailed)18 Test (org.junit.Test)9 Path (java.nio.file.Path)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 File (java.io.File)7 IOException (java.io.IOException)7 Config (org.neo4j.kernel.configuration.Config)7 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 IncorrectUsage (org.neo4j.commandline.admin.IncorrectUsage)5 CheckConsistencyConfig (org.neo4j.consistency.checking.full.CheckConsistencyConfig)3 StoreLocker (org.neo4j.kernel.internal.StoreLocker)3 Closeable (java.io.Closeable)2 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)2 MandatoryCanonicalPath (org.neo4j.commandline.arguments.common.MandatoryCanonicalPath)2 OptionalCanonicalPath (org.neo4j.commandline.arguments.common.OptionalCanonicalPath)2 StoreLockException (org.neo4j.kernel.StoreLockException)2 FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)2 FileLock (java.nio.channels.FileLock)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 FileSystemException (java.nio.file.FileSystemException)1