//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()); } }
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 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 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 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 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); } }
//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 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)); }