//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRecoverIfCrashedDuringMove() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRecoverIfCrashedDuringMove() { // Given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.IOException exception = new java.io.IOException("simulated IO Exception on create"); IOException exception = new IOException("simulated IO Exception on create"); FileSystemAbstraction crashingFileSystem = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _fs, exception); _roleRepository = new FileRoleRepository(crashingFileSystem, _roleFile, _logProvider); _roleRepository.start(); RoleRecord role = new RoleRecord("admin", "jake"); // When try { _roleRepository.create(role); fail("Expected an IOException"); } catch (IOException e) { assertSame(exception, e); } // Then assertFalse(crashingFileSystem.FileExists(_roleFile)); assertThat(crashingFileSystem.ListFiles(_roleFile.ParentFile).Length, equalTo(0)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized boolean delete(RoleRecord role) throws java.io.IOException public override bool Delete(RoleRecord role) { lock (this) { bool foundRole = false; // Copy-on-write for the roles list IList <RoleRecord> newRoles = new List <RoleRecord>(); foreach (RoleRecord other in RolesConflict) { if (other.Name().Equals(role.Name())) { foundRole = true; } else { newRoles.Add(other); } } if (foundRole) { RolesConflict = newRoles; PersistRoles(); _rolesByName.Remove(role.Name()); } RemoveFromUserMap(role); return(foundRole); } }
// ------------------ helpers -------------------- protected internal virtual void PopulateUserMap(RoleRecord role) { foreach (string username in role.Users()) { SortedSet <string> memberOfRoles = _rolesByUsername.computeIfAbsent(username, k => new ConcurrentSkipListSet <string>()); memberOfRoles.Add(role.Name()); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private RoleRecord getRole(String roleName) throws org.neo4j.kernel.api.exceptions.InvalidArgumentsException private RoleRecord GetRole( string roleName ) { RoleRecord role = _roleRepository.getRoleByName( roleName ); if ( role == null ) { throw new InvalidArgumentsException( "Role '" + roleName + "' does not exist." ); } return role; }
protected internal virtual void RemoveFromUserMap(RoleRecord role) { foreach (string username in role.Users()) { SortedSet <string> memberOfRoles = _rolesByUsername[username]; if (memberOfRoles != null) { memberOfRoles.remove(role.Name()); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStoreAndRetrieveRolesByName() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStoreAndRetrieveRolesByName() { // Given RoleRecord role = new RoleRecord("admin", "petra", "olivia"); _roleRepository.create(role); // When RoleRecord result = _roleRepository.getRoleByName(role.Name()); // Then assertThat(result, equalTo(role)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotFindRoleAfterDelete() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotFindRoleAfterDelete() { // Given RoleRecord role = new RoleRecord("jake", "admin"); _roleRepository.create(role); // When _roleRepository.delete(role); // Then assertThat(_roleRepository.getRoleByName(role.Name()), nullValue()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPersistRoles() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPersistRoles() { // Given RoleRecord role = new RoleRecord("admin", "craig", "karl"); _roleRepository.create(role); _roleRepository = new FileRoleRepository(_fs, _roleFile, _logProvider); _roleRepository.start(); // When RoleRecord resultByName = _roleRepository.getRoleByName(role.Name()); // Then assertThat(resultByName, equalTo(role)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized void removeUserFromAllRoles(String username) throws org.neo4j.server.security.auth.exception.ConcurrentModificationException, java.io.IOException public override void RemoveUserFromAllRoles(string username) { lock (this) { ISet <string> roles = _rolesByUsername[username]; if (roles != null) { // Since update() is modifying the set we create a copy for the iteration IList <string> rolesToRemoveFrom = new List <string>(roles); foreach (string roleName in rolesToRemoveFrom) { RoleRecord role = _rolesByName[roleName]; RoleRecord newRole = role.Augment().withoutUser(username).build(); Update(role, newRole); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAddEmptyUserToRole() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotAddEmptyUserToRole() { // Given _fs.mkdirs(_roleFile.ParentFile); FileRepositorySerializer.writeToFile(_fs, _roleFile, UTF8.encode("admin:neo4j\nreader:\n")); // When _roleRepository = new FileRoleRepository(_fs, _roleFile, _logProvider); _roleRepository.start(); RoleRecord role = _roleRepository.getRoleByName("admin"); assertTrue("neo4j should be assigned to 'admin'", role.Users().Contains("neo4j")); assertEquals("only one admin should exist", 1, role.Users().Count); role = _roleRepository.getRoleByName("reader"); assertTrue("no users should be assigned to 'reader'", role.Users().Count == 0); }
public override bool Equals(object o) { if (this == o) { return(true); } if (o == null || this.GetType() != o.GetType()) { return(false); } RoleRecord role = ( RoleRecord )o; if (!string.ReferenceEquals(_name, null) ?!_name.Equals(role._name) :!string.ReferenceEquals(role._name, null)) { return(false); } return(_users != null?_users.Equals(role._users) : role._users == null); }
public override void NewRole( string roleName, params string[] usernames ) { _roleRepository.assertValidRoleName( roleName ); foreach ( string username in usernames ) { _userRepository.assertValidUsername( username ); } SortedSet<string> userSet = new SortedSet<string>( Arrays.asList( usernames ) ); RoleRecord role = ( new RoleRecord.Builder() ).WithName(roleName).withUsers(userSet).build(); lock ( this ) { foreach ( string username in usernames ) { GetUser( username ); // assert that user exists } _roleRepository.create( role ); } }
public override bool DeleteRole( string roleName ) { AssertNotPredefinedRoleName( roleName ); bool result = false; lock ( this ) { RoleRecord role = GetRole( roleName ); // asserts role name exists if ( _roleRepository.delete( role ) ) { result = true; } else { // We should not get here, but if we do the assert will fail and give a nice error msg AssertRoleExists( roleName ); } } return result; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void update(RoleRecord existingRole, RoleRecord updatedRole) throws org.neo4j.server.security.auth.exception.ConcurrentModificationException, java.io.IOException public override void Update(RoleRecord existingRole, RoleRecord updatedRole) { // Assert input is ok if (!existingRole.Name().Equals(updatedRole.Name())) { throw new System.ArgumentException("The attempt to update the role from '" + existingRole.Name() + "' to '" + updatedRole.Name() + "' failed. Changing a roles name is not allowed."); } lock (this) { // Copy-on-write for the roles list IList <RoleRecord> newRoles = new List <RoleRecord>(); bool foundRole = false; foreach (RoleRecord other in RolesConflict) { if (other.Equals(existingRole)) { foundRole = true; newRoles.Add(updatedRole); } else { newRoles.Add(other); } } if (!foundRole) { throw new ConcurrentModificationException(); } RolesConflict = newRoles; PersistRoles(); _rolesByName[updatedRole.Name()] = updatedRole; RemoveFromUserMap(existingRole); PopulateUserMap(updatedRole); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowIfExistingRoleDoesNotMatch() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowIfExistingRoleDoesNotMatch() { // Given RoleRecord role = new RoleRecord("admin", "jake"); _roleRepository.create(role); RoleRecord modifiedRole = new RoleRecord("admin", "jake", "john"); // When RoleRecord updatedRole = new RoleRecord("admin", "john"); try { _roleRepository.update(modifiedRole, updatedRole); fail("expected exception not thrown"); } catch (ConcurrentModificationException) { // Then continue } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowIfUpdateChangesName() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowIfUpdateChangesName() { // Given RoleRecord role = new RoleRecord("admin", "steve", "bob"); _roleRepository.create(role); // When RoleRecord updatedRole = new RoleRecord("admins", "steve", "bob"); try { _roleRepository.update(role, updatedRole); fail("expected exception not thrown"); } catch (System.ArgumentException) { // Then continue } assertThat(_roleRepository.getRoleByName(role.Name()), equalTo(role)); }
public override void AddRoleToUser( string roleName, string username ) { _roleRepository.assertValidRoleName( roleName ); _userRepository.assertValidUsername( username ); lock ( this ) { GetUser( username ); RoleRecord role = GetRole( roleName ); RoleRecord newRole = role.Augment().withUser(username).build(); try { _roleRepository.update( role, newRole ); } catch ( ConcurrentModificationException ) { // Try again AddRoleToUser( roleName, username ); } } ClearCachedAuthorizationInfoForUser( username ); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void create(RoleRecord role) throws org.neo4j.kernel.api.exceptions.InvalidArgumentsException, java.io.IOException public override void Create(RoleRecord role) { AssertValidRoleName(role.Name()); lock (this) { // Check for existing role foreach (RoleRecord other in RolesConflict) { if (other.Name().Equals(role.Name())) { throw new InvalidArgumentsException("The specified role '" + role.Name() + "' already exists."); } } RolesConflict.Add(role); PersistRoles(); _rolesByName[role.Name()] = role; PopulateUserMap(role); } }
public Builder(RoleRecord @base) { Name = @base.name; Users = new SortedSet <string>(@base.users); }
public override ISet<string> SilentlyGetUsernamesForRole( string roleName ) { RoleRecord role = SilentlyGetRole( roleName ); return role == null ? emptySet() : role.Users(); }
public override ISet<string> GetUsernamesForRole( string roleName ) { RoleRecord role = GetRole( roleName ); return role.Users(); }