use of org.neo4j.server.security.auth.BasicPasswordPolicy 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"));
}
use of org.neo4j.server.security.auth.BasicPasswordPolicy 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);
}
use of org.neo4j.server.security.auth.BasicPasswordPolicy 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());
}
use of org.neo4j.server.security.auth.BasicPasswordPolicy 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();
}
Aggregations