Search in sources :

Example 6 with UserRepository

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

the class InternalFlatFileRealmTest method assertSetUsersAndRolesNTimes.

private void assertSetUsersAndRolesNTimes(boolean usersChanged, boolean rolesChanged, int nSetUsers, int nSetRoles) throws Throwable {
    final UserRepository userRepository = mock(UserRepository.class);
    final RoleRepository roleRepository = mock(RoleRepository.class);
    final UserRepository initialUserRepository = mock(UserRepository.class);
    final UserRepository defaultAdminRepository = mock(UserRepository.class);
    final PasswordPolicy passwordPolicy = new BasicPasswordPolicy();
    AuthenticationStrategy authenticationStrategy = new RateLimitedAuthenticationStrategy(Clocks.systemClock(), 3);
    InternalFlatFileRealmIT.TestJobScheduler jobScheduler = new InternalFlatFileRealmIT.TestJobScheduler();
    InternalFlatFileRealm realm = new InternalFlatFileRealm(userRepository, roleRepository, passwordPolicy, authenticationStrategy, jobScheduler, initialUserRepository, defaultAdminRepository);
    when(userRepository.getPersistedSnapshot()).thenReturn(new ListSnapshot<>(10L, Collections.emptyList(), usersChanged));
    when(userRepository.getUserByName(any())).thenReturn(new User.Builder().build());
    when(roleRepository.getPersistedSnapshot()).thenReturn(new ListSnapshot<>(10L, Collections.emptyList(), rolesChanged));
    when(roleRepository.getRoleByName(anyString())).thenReturn(new RoleRecord(""));
    realm.init();
    realm.start();
    jobScheduler.scheduledRunnable.run();
    verify(userRepository, times(nSetUsers)).setUsers(any());
    verify(roleRepository, times(nSetRoles)).setRoles(any());
}
Also used : RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) AuthenticationStrategy(org.neo4j.server.security.auth.AuthenticationStrategy) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) UserRepository(org.neo4j.server.security.auth.UserRepository) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) PasswordPolicy(org.neo4j.kernel.api.security.PasswordPolicy) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy)

Example 7 with UserRepository

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

the class SetDefaultAdminCommandTest method setup.

@Before
public void setup() throws IOException, InvalidArgumentsException {
    OutsideWorld mock = mock(OutsideWorld.class);
    when(mock.fileSystem()).thenReturn(fileSystem);
    setDefaultAdmin = new SetDefaultAdminCommand(testDir.directory("home").toPath(), testDir.directory("conf").toPath(), mock);
    config = setDefaultAdmin.loadNeo4jConfig();
    UserRepository users = CommunitySecurityModule.getUserRepository(config, NullLogProvider.getInstance(), fileSystem);
    users.create(new User.Builder("jake", Credential.forPassword("123")).withRequiredPasswordChange(false).build());
    adminIniFile = new File(CommunitySecurityModule.getUserRepositoryFile(config).getParentFile(), "admin.ini");
}
Also used : OutsideWorld(org.neo4j.commandline.admin.OutsideWorld) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) User(org.neo4j.kernel.impl.security.User) File(java.io.File) Before(org.junit.Before)

Example 8 with UserRepository

use of org.neo4j.server.security.auth.UserRepository 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)

Aggregations

UserRepository (org.neo4j.server.security.auth.UserRepository)8 BasicPasswordPolicy (org.neo4j.server.security.auth.BasicPasswordPolicy)4 InMemoryUserRepository (org.neo4j.server.security.auth.InMemoryUserRepository)4 RateLimitedAuthenticationStrategy (org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy)4 File (java.io.File)3 Before (org.junit.Before)3 PasswordPolicy (org.neo4j.kernel.api.security.PasswordPolicy)3 FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)3 Test (org.junit.Test)2 User (org.neo4j.kernel.impl.security.User)2 AuthenticationStrategy (org.neo4j.server.security.auth.AuthenticationStrategy)2 Matchers.anyString (org.mockito.Matchers.anyString)1 CommandFailed (org.neo4j.commandline.admin.CommandFailed)1 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)1 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 InvalidArgumentsException (org.neo4j.kernel.api.exceptions.InvalidArgumentsException)1 Config (org.neo4j.kernel.configuration.Config)1 BasicAuthManager (org.neo4j.server.security.auth.BasicAuthManager)1