Search in sources :

Example 1 with UserRepository

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

the class BasicAuthenticationTest method setup.

@Before
public void setup() throws Throwable {
    UserRepository userRepository = new InMemoryUserRepository();
    PasswordPolicy policy = mock(PasswordPolicy.class);
    BasicAuthManager manager = new BasicAuthManager(userRepository, policy, Clocks.systemClock(), userRepository);
    authentication = new BasicAuthentication(manager, manager);
    manager.newUser("bob", "secret", true);
    manager.newUser("mike", "secret2", false);
}
Also used : UserRepository(org.neo4j.server.security.auth.UserRepository) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) BasicAuthManager(org.neo4j.server.security.auth.BasicAuthManager) PasswordPolicy(org.neo4j.kernel.api.security.PasswordPolicy) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) Before(org.junit.Before)

Example 2 with UserRepository

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

the class InternalFlatFileRealmIT method setup.

@Before
public void setup() throws Throwable {
    fs = new EvilFileSystem(new EphemeralFileSystemAbstraction());
    userStoreFile = new File("dbms", "auth");
    roleStoreFile = new File("dbms", "roles");
    final UserRepository userRepository = new FileUserRepository(fs, userStoreFile, logProvider);
    final RoleRepository roleRepository = new FileRoleRepository(fs, roleStoreFile, logProvider);
    final UserRepository initialUserRepository = CommunitySecurityModule.getInitialUserRepository(Config.defaults(), logProvider, fs);
    final UserRepository defaultAdminRepository = EnterpriseSecurityModule.getDefaultAdminRepository(Config.defaults(), logProvider, fs);
    final PasswordPolicy passwordPolicy = new BasicPasswordPolicy();
    AuthenticationStrategy authenticationStrategy = new RateLimitedAuthenticationStrategy(Clocks.systemClock(), 3);
    realm = new InternalFlatFileRealm(userRepository, roleRepository, passwordPolicy, authenticationStrategy, true, true, jobScheduler, initialUserRepository, defaultAdminRepository);
    realm.init();
    realm.start();
}
Also used : FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) AuthenticationStrategy(org.neo4j.server.security.auth.AuthenticationStrategy) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) PasswordPolicy(org.neo4j.kernel.api.security.PasswordPolicy) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) File(java.io.File) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) Before(org.junit.Before)

Example 3 with UserRepository

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

the class MultiRealmAuthManagerTest method shouldFailIfNoRolesFileButManyUsersAndNonExistingDefaultAdmin.

@Test
public void shouldFailIfNoRolesFileButManyUsersAndNonExistingDefaultAdmin() throws Throwable {
    // Given
    UserRepository defaultAdminRepository = EnterpriseSecurityModule.getDefaultAdminRepository(config, NullLogProvider.getInstance(), fsRule.get());
    defaultAdminRepository.start();
    defaultAdminRepository.create(new User.Builder("foo", Credential.INACCESSIBLE).withRequiredPasswordChange(false).build());
    defaultAdminRepository.shutdown();
    users.create(newUser("jake", "abc123", false));
    users.create(newUser("jane", "123abc", false));
    expect.expect(InvalidArgumentsException.class);
    expect.expectMessage("No roles defined, and default admin user 'foo' does not exist. " + "Please use `neo4j-admin " + SetDefaultAdminCommand.COMMAND_NAME + "` to select a valid admin.");
    manager.start();
}
Also used : UserRepository(org.neo4j.server.security.auth.UserRepository) User(org.neo4j.kernel.impl.security.User) Test(org.junit.Test)

Example 4 with UserRepository

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

the class SetDefaultAdminCommand method execute.

@Override
public void execute() {
    Config config = loadNeo4jConfig();
    try {
        Path adminIniFile = CommunitySecurityModule.getUserRepositoryFile(config).getParent().resolve(ADMIN_INI);
        if (ctx.fs().fileExists(adminIniFile)) {
            ctx.fs().deleteFile(adminIniFile);
        }
        UserRepository admins = new FileUserRepository(ctx.fs(), adminIniFile, NullLogProvider.getInstance());
        admins.init();
        admins.start();
        admins.create(new User.Builder(username, LegacyCredential.INACCESSIBLE).build());
        admins.stop();
        admins.shutdown();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    ctx.out().println("default admin user set to '" + username + "'");
}
Also used : Path(java.nio.file.Path) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) Config(org.neo4j.configuration.Config)

Example 5 with UserRepository

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

the class InternalFlatFileRealmTest method shouldAssignAdminRoleAfterBadSetting.

@Test
public void shouldAssignAdminRoleAfterBadSetting() throws Throwable {
    UserRepository userRepository = new InMemoryUserRepository();
    UserRepository initialUserRepository = new InMemoryUserRepository();
    UserRepository adminUserRepository = new InMemoryUserRepository();
    RoleRepository roleRepository = new InMemoryRoleRepository();
    userRepository.create(newUser("morpheus", "123", false));
    userRepository.create(newUser("trinity", "123", false));
    InternalFlatFileRealm realm = new InternalFlatFileRealm(userRepository, roleRepository, new BasicPasswordPolicy(), new RateLimitedAuthenticationStrategy(Clocks.systemClock(), 3), new InternalFlatFileRealmIT.TestJobScheduler(), initialUserRepository, adminUserRepository);
    try {
        realm.initialize();
        realm.start();
        fail("Multiple users, no default admin provided");
    } catch (InvalidArgumentsException e) {
        realm.stop();
        realm.shutdown();
    }
    adminUserRepository.create(new User.Builder("trinity", Credential.INACCESSIBLE).build());
    realm.initialize();
    realm.start();
    assertThat(realm.getUsernamesForRole(PredefinedRoles.ADMIN).size(), equalTo(1));
    assertThat(realm.getUsernamesForRole(PredefinedRoles.ADMIN), contains("trinity"));
}
Also used : RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) UserRepository(org.neo4j.server.security.auth.UserRepository) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException) Test(org.junit.Test)

Aggregations

UserRepository (org.neo4j.server.security.auth.UserRepository)10 InMemoryUserRepository (org.neo4j.server.security.auth.InMemoryUserRepository)5 BasicPasswordPolicy (org.neo4j.server.security.auth.BasicPasswordPolicy)4 FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)4 RateLimitedAuthenticationStrategy (org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy)4 Config (org.neo4j.configuration.Config)3 PasswordPolicy (org.neo4j.kernel.api.security.PasswordPolicy)3 User (org.neo4j.kernel.impl.security.User)3 File (java.io.File)2 Before (org.junit.Before)2 Test (org.junit.Test)2 AuthenticationStrategy (org.neo4j.server.security.auth.AuthenticationStrategy)2 PrintStream (java.io.PrintStream)1 Path (java.nio.file.Path)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ExecutionContext (org.neo4j.cli.ExecutionContext)1 CommandFailed (org.neo4j.commandline.admin.CommandFailed)1 DependencyResolver (org.neo4j.common.DependencyResolver)1