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