Search in sources :

Example 6 with InMemoryUserRepository

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

Example 7 with InMemoryUserRepository

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

the class InternalFlatFileRealmTest method internalTestRealmWithUsers.

private InternalFlatFileRealm internalTestRealmWithUsers(List<String> existing, List<String> defaultAdmin) throws Throwable {
    UserRepository userRepository = new InMemoryUserRepository();
    UserRepository initialUserRepository = new InMemoryUserRepository();
    UserRepository adminUserRepository = new InMemoryUserRepository();
    RoleRepository roleRepository = new InMemoryRoleRepository();
    for (String user : existing) {
        userRepository.create(newUser(user, "123", false));
    }
    for (String user : defaultAdmin) {
        adminUserRepository.create(new User.Builder(user, Credential.INACCESSIBLE).build());
    }
    return new InternalFlatFileRealm(userRepository, roleRepository, new BasicPasswordPolicy(), new RateLimitedAuthenticationStrategy(Clocks.systemClock(), 3), new InternalFlatFileRealmIT.TestJobScheduler(), initialUserRepository, adminUserRepository);
}
Also used : RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) UserRepository(org.neo4j.server.security.auth.UserRepository) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) Matchers.anyString(org.mockito.Matchers.anyString) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy)

Example 8 with InMemoryUserRepository

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

the class MultiRealmAuthManagerRule method setupAuthManager.

private void setupAuthManager(AuthenticationStrategy authStrategy) throws Throwable {
    FormattedLog.Builder builder = FormattedLog.withUTCTimeZone();
    securityLogWriter = new StringWriter();
    Log log = builder.toWriter(securityLogWriter);
    securityLog = new SecurityLog(log);
    InternalFlatFileRealm internalFlatFileRealm = new InternalFlatFileRealm(users, new InMemoryRoleRepository(), new BasicPasswordPolicy(), authStrategy, mock(JobScheduler.class), new InMemoryUserRepository(), new InMemoryUserRepository());
    manager = new MultiRealmAuthManager(internalFlatFileRealm, Collections.singleton(internalFlatFileRealm), new MemoryConstrainedCacheManager(), securityLog, true);
    manager.init();
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) FormattedLog(org.neo4j.logging.FormattedLog) StringWriter(java.io.StringWriter) Log(org.neo4j.logging.Log) FormattedLog(org.neo4j.logging.FormattedLog) SecurityLog(org.neo4j.server.security.enterprise.log.SecurityLog) MemoryConstrainedCacheManager(org.apache.shiro.cache.MemoryConstrainedCacheManager) SecurityLog(org.neo4j.server.security.enterprise.log.SecurityLog) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository)

Example 9 with InMemoryUserRepository

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

the class UserServiceTest method setupAuthManagerAndSubject.

protected void setupAuthManagerAndSubject() {
    BasicAuthManager basicAuthManager = new BasicAuthManager(userRepository, passwordPolicy, mock(AuthenticationStrategy.class), new InMemoryUserRepository());
    userManagerSupplier = basicAuthManager;
    neo4jContext = new BasicSecurityContext(basicAuthManager, NEO4J_USER, AuthenticationResult.SUCCESS);
}
Also used : BasicAuthManager(org.neo4j.server.security.auth.BasicAuthManager) AuthenticationStrategy(org.neo4j.server.security.auth.AuthenticationStrategy) BasicSecurityContext(org.neo4j.server.security.auth.BasicSecurityContext) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository)

Example 10 with InMemoryUserRepository

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

the class UserSecurityGraphComponentTest method setup.

@BeforeAll
static void setup() throws IOException, InvalidArgumentsException {
    Config cfg = Config.newBuilder().set(auth_enabled, TRUE).set(allow_single_automatic_upgrade, FALSE).build();
    dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).impermanent().setConfig(cfg).noOpSystemGraphInitializer().build();
    system = (GraphDatabaseFacade) dbms.database(SYSTEM_DATABASE_NAME);
    DependencyResolver resolver = system.getDependencyResolver();
    systemGraphComponents = resolver.resolveDependency(SystemGraphComponents.class);
    authManager = resolver.resolveDependency(AuthManager.class);
    // Insert a custom SecurityUserComponent instead of the default one,
    // in order to have a handle on it and to migrate a 3.5 user
    systemGraphComponents.deregister(SECURITY_USER_COMPONENT);
    UserRepository oldUsers = new InMemoryUserRepository();
    User oldUser = new User.Builder("alice", credentialFor("secret")).withRequiredPasswordChange(false).build();
    oldUsers.create(oldUser);
    UserRepository initialPassword = new InMemoryUserRepository();
    userSecurityGraphComponent = new UserSecurityGraphComponent(CommunitySecurityLog.NULL_LOG, oldUsers, initialPassword, Config.defaults());
    systemGraphComponents.register(userSecurityGraphComponent);
    // remove DBMS runtime component as it is not a subject of this test
    systemGraphComponents.deregister(DBMS_RUNTIME_COMPONENT);
}
Also used : SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) UserRepository(org.neo4j.server.security.auth.UserRepository) User(org.neo4j.kernel.impl.security.User) UserSecurityGraphComponent(org.neo4j.server.security.systemgraph.UserSecurityGraphComponent) AuthManager(org.neo4j.kernel.api.security.AuthManager) Config(org.neo4j.configuration.Config) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) DependencyResolver(org.neo4j.common.DependencyResolver) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

InMemoryUserRepository (org.neo4j.server.security.auth.InMemoryUserRepository)10 BasicPasswordPolicy (org.neo4j.server.security.auth.BasicPasswordPolicy)6 RateLimitedAuthenticationStrategy (org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy)4 UserRepository (org.neo4j.server.security.auth.UserRepository)4 Before (org.junit.Before)3 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)3 SecurityLog (org.neo4j.server.security.enterprise.log.SecurityLog)3 Log (org.neo4j.logging.Log)2 AuthenticationStrategy (org.neo4j.server.security.auth.AuthenticationStrategy)2 BasicAuthManager (org.neo4j.server.security.auth.BasicAuthManager)2 FakeTicker (com.google.common.testing.FakeTicker)1 StringWriter (java.io.StringWriter)1 MemoryConstrainedCacheManager (org.apache.shiro.cache.MemoryConstrainedCacheManager)1 Realm (org.apache.shiro.realm.Realm)1 Test (org.junit.Test)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Matchers.anyString (org.mockito.Matchers.anyString)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 Config (org.neo4j.configuration.Config)1