private bool RealUsersExist(Config config) { bool result = false; File authFile = CommunitySecurityModule.getUserRepositoryFile(config); if (_outsideWorld.fileSystem().fileExists(authFile)) { result = true; // Check if it only contains the default neo4j user FileUserRepository userRepository = new FileUserRepository(_outsideWorld.fileSystem(), authFile, NullLogProvider.Instance); try { using (Lifespan life = new Lifespan(userRepository)) { ListSnapshot <User> users = userRepository.PersistedSnapshot; if (users.Values().Count == 1) { User user = users.Values()[0]; if (INITIAL_USER_NAME.Equals(user.Name()) && user.Credentials().matchesPassword(INITIAL_PASSWORD)) { // We allow overwriting an unmodified default neo4j user result = false; } } } } catch (IOException) { // Do not allow overwriting if we had a problem reading the file } } return(result); }
private void ReadFilesFromDisk( int attemptLeft, IList<string> failures ) { if ( attemptLeft < 0 ) { throw new Exception( "Unable to load valid flat file repositories! Attempts failed with:\n\t" + string.join( "\n\t", failures ) ); } try { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final boolean valid; bool valid; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final boolean needsUpdate; bool needsUpdate; lock ( this ) { ListSnapshot<User> users = _userRepository.PersistedSnapshot; ListSnapshot<RoleRecord> roles = _roleRepository.PersistedSnapshot; needsUpdate = users.FromPersisted() || roles.FromPersisted(); valid = needsUpdate && RoleRepository.validate( users.Values(), roles.Values() ); if ( valid ) { if ( users.FromPersisted() ) { _userRepository.Users = users; } if ( roles.FromPersisted() ) { _roleRepository.Roles = roles; } } } if ( needsUpdate && !valid ) { failures.Add( "Role-auth file combination not valid." ); Thread.Sleep( 10 ); ReadFilesFromDisk( attemptLeft - 1, failures ); } } catch ( Exception e ) when ( e is IOException || e is System.InvalidOperationException || e is InterruptedException || e is InvalidArgumentsException ) { failures.Add( e.Message ); ReadFilesFromDisk( attemptLeft - 1, failures ); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMaintainConsistency() throws InterruptedException, java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldMaintainConsistency() { ExecutorService service = SetupWorkload(N); for (int t = 0; t < TimeoutInSeconds; t++) { Thread.Sleep(_oneSecond); if (Errors.Count > ErrorLimit) { break; } } _keepRunning = false; service.shutdown(); service.awaitTermination(5, SECONDS); // Assert that no errors occured string msg = string.join(Environment.NewLine, Errors.Select(Exception.getMessage).ToList()); assertThat(msg, Errors, empty()); // Assert that user and role repos are consistent ListSnapshot <User> users = _userRepository.PersistedSnapshot; ListSnapshot <RoleRecord> roles = _roleRepository.PersistedSnapshot; assertTrue("User and role repositories are no longer consistent", RoleRepository.validate(users.Values(), roles.Values())); }