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