//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAssignAdminRoleAfterBadSetting() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAssignAdminRoleAfterBadSetting() { 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(), NewRateLimitedAuthStrategy(), new InternalFlatFileRealmIT.TestJobScheduler(), initialUserRepository, adminUserRepository); try { realm.Initialize(); realm.Start(); fail("Multiple users, no default admin provided"); } catch (InvalidArgumentsException) { realm.Stop(); realm.Shutdown(); } adminUserRepository.Create((new User.Builder("trinity", LegacyCredential.INACCESSIBLE)).build()); realm.Initialize(); realm.Start(); assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN).Count, equalTo(1)); assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN), contains("trinity")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertSetUsersAndRolesNTimes(boolean usersChanged, boolean rolesChanged, int nSetUsers, int nSetRoles) throws Throwable private void AssertSetUsersAndRolesNTimes(bool usersChanged, bool rolesChanged, int nSetUsers, int nSetRoles) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.server.security.auth.UserRepository userRepository = mock(org.neo4j.server.security.auth.UserRepository.class); UserRepository userRepository = mock(typeof(UserRepository)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final RoleRepository roleRepository = mock(RoleRepository.class); RoleRepository roleRepository = mock(typeof(RoleRepository)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.server.security.auth.UserRepository initialUserRepository = mock(org.neo4j.server.security.auth.UserRepository.class); UserRepository initialUserRepository = mock(typeof(UserRepository)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.server.security.auth.UserRepository defaultAdminRepository = mock(org.neo4j.server.security.auth.UserRepository.class); UserRepository defaultAdminRepository = mock(typeof(UserRepository)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.api.security.PasswordPolicy passwordPolicy = new org.neo4j.server.security.auth.BasicPasswordPolicy(); PasswordPolicy passwordPolicy = new BasicPasswordPolicy(); AuthenticationStrategy authenticationStrategy = NewRateLimitedAuthStrategy(); InternalFlatFileRealmIT.TestJobScheduler jobScheduler = new InternalFlatFileRealmIT.TestJobScheduler(); InternalFlatFileRealm realm = new InternalFlatFileRealm(userRepository, roleRepository, passwordPolicy, authenticationStrategy, jobScheduler, initialUserRepository, defaultAdminRepository); when(userRepository.PersistedSnapshot).thenReturn(new ListSnapshot <>(10L, Collections.emptyList(), usersChanged)); when(userRepository.GetUserByName(any())).thenReturn((new User.Builder()).build()); when(roleRepository.PersistedSnapshot).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)).Users = any(); verify(roleRepository, times(nSetRoles)).Roles = any(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Setup() { Fs = new EvilFileSystem(this, new EphemeralFileSystemAbstraction()); UserStoreFile = new File("dbms", "auth"); RoleStoreFile = new File("dbms", "roles"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.server.security.auth.UserRepository userRepository = new org.neo4j.server.security.auth.FileUserRepository(fs, userStoreFile, logProvider); UserRepository userRepository = new FileUserRepository(Fs, UserStoreFile, LogProvider); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final RoleRepository roleRepository = new FileRoleRepository(fs, roleStoreFile, logProvider); RoleRepository roleRepository = new FileRoleRepository(Fs, RoleStoreFile, LogProvider); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.server.security.auth.UserRepository initialUserRepository = org.neo4j.server.security.auth.CommunitySecurityModule.getInitialUserRepository(org.neo4j.kernel.configuration.Config.defaults(), logProvider, fs); UserRepository initialUserRepository = CommunitySecurityModule.getInitialUserRepository(Config.defaults(), LogProvider, Fs); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.server.security.auth.UserRepository defaultAdminRepository = EnterpriseSecurityModule.getDefaultAdminRepository(org.neo4j.kernel.configuration.Config.defaults(), logProvider, fs); UserRepository defaultAdminRepository = EnterpriseSecurityModule.GetDefaultAdminRepository(Config.defaults(), LogProvider, Fs); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.api.security.PasswordPolicy passwordPolicy = new org.neo4j.server.security.auth.BasicPasswordPolicy(); PasswordPolicy passwordPolicy = new BasicPasswordPolicy(); AuthenticationStrategy authenticationStrategy = new RateLimitedAuthenticationStrategy(Clocks.systemClock(), Config.defaults()); Realm = new InternalFlatFileRealm(userRepository, roleRepository, passwordPolicy, authenticationStrategy, true, true, JobScheduler, initialUserRepository, defaultAdminRepository); Realm.init(); Realm.start(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private MultiRealmAuthManager createAuthManager(boolean logSuccessfulAuthentications) throws Throwable private MultiRealmAuthManager CreateAuthManager(bool logSuccessfulAuthentications) { Log log = _logProvider.getLog(this.GetType()); InternalFlatFileRealm internalFlatFileRealm = new InternalFlatFileRealm(Users, new InMemoryRoleRepository(), mock(typeof(PasswordPolicy)), _authStrategy, mock(typeof(JobScheduler)), CommunitySecurityModule.getInitialUserRepository(Config, NullLogProvider.Instance, FsRule.get()), EnterpriseSecurityModule.GetDefaultAdminRepository(Config, NullLogProvider.Instance, FsRule.get())); _manager = new MultiRealmAuthManager(internalFlatFileRealm, Collections.singleton(internalFlatFileRealm), new MemoryConstrainedCacheManager(), new SecurityLog(log), logSuccessfulAuthentications, false, Collections.emptyMap()); _manager.init(); return(_manager); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAssignAdminRoleToDefaultUser() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAssignAdminRoleToDefaultUser() { // Given InternalFlatFileRealm realm = InternalTestRealmWithUsers(Collections.emptyList(), Collections.emptyList()); // When realm.Initialize(); realm.Start(); // Then assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN), contains(InternalFlatFileRealm.INITIAL_USER_NAME)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void setupAuthManager(org.neo4j.server.security.auth.AuthenticationStrategy authStrategy) throws Throwable private void SetupAuthManager(AuthenticationStrategy authStrategy) { 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(typeof(JobScheduler)), new InMemoryUserRepository(), new InMemoryUserRepository() ); _manager = new MultiRealmAuthManager(internalFlatFileRealm, Collections.singleton(internalFlatFileRealm), new MemoryConstrainedCacheManager(), _securityLog, true, false, Collections.emptyMap()); _manager.init(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailToAssignMultipleDefaultAdmins() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFailToAssignMultipleDefaultAdmins() { // Given InternalFlatFileRealm realm = InternalTestRealmWithUsers(Arrays.asList("morpheus", "trinity", "tank"), Arrays.asList("morpheus", "trinity")); // Expect Exception.expect(typeof(InvalidArgumentsException)); Exception.expectMessage("No roles defined, and multiple users defined as default admin user. Please use `neo4j-admin " + SetDefaultAdminCommand.COMMAND_NAME + "` to select a valid admin."); // When realm.Initialize(); realm.Start(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGiveErrorOnMultipleUsersNoDefault() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldGiveErrorOnMultipleUsersNoDefault() { // Given InternalFlatFileRealm realm = InternalTestRealmWithUsers(Arrays.asList("morpheus", "trinity"), Collections.emptyList()); // Expect Exception.expect(typeof(InvalidArgumentsException)); Exception.expectMessage("No roles defined, and cannot determine which user should be admin. Please use `neo4j-admin " + SetDefaultAdminCommand.COMMAND_NAME + "` to select an admin."); // When realm.Initialize(); realm.Start(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAssignAdminToNonExistentUser() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotAssignAdminToNonExistentUser() { // Given InternalFlatFileRealm realm = InternalTestRealmWithUsers(Collections.singletonList("neo4j"), Collections.singletonList("morpheus")); // Expect Exception.expect(typeof(InvalidArgumentsException)); Exception.expectMessage("No roles defined, and default admin user 'morpheus' does not exist. Please use `neo4j-admin " + SetDefaultAdminCommand.COMMAND_NAME + "` to select a valid admin."); // When realm.Initialize(); realm.Start(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAssignAdminRoleToOnlyUser() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAssignAdminRoleToOnlyUser() { // Given InternalFlatFileRealm realm = InternalTestRealmWithUsers(Collections.singletonList("morpheus"), Collections.emptyList()); // When realm.Initialize(); realm.Start(); // Then assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN), contains("morpheus")); assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN).Count, equalTo(1)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Setup() { SecurityLog securityLog = mock(typeof(SecurityLog)); InternalFlatFileRealm internalFlatFileRealm = new InternalFlatFileRealm(new InMemoryUserRepository(), new InMemoryRoleRepository(), new BasicPasswordPolicy(), new RateLimitedAuthenticationStrategy(Clock.systemUTC(), Config.defaults()), mock(typeof(JobScheduler)), new InMemoryUserRepository(), new InMemoryUserRepository() ); _testRealm = new TestRealm(this, LdapConfig, securityLog, new SecureHasher()); IList <Realm> realms = listOf(internalFlatFileRealm, _testRealm); _fakeTicker = new FakeTicker(); _authManager = new MultiRealmAuthManager(internalFlatFileRealm, realms, new ShiroCaffeineCache.Manager(_fakeTicker.read, 100, 10, true), securityLog, false, false, Collections.emptyMap()); _authManager.init(); _authManager.start(); _authManager.UserManager.newUser("mike", password("123"), false); _authManager.UserManager.newUser("mats", password("456"), false); }