Search in sources :

Example 6 with ConcurrentModificationException

use of org.neo4j.server.security.auth.exception.ConcurrentModificationException in project neo4j by neo4j.

the class AbstractUserRepository method update.

@Override
public void update(User existingUser, User updatedUser) throws ConcurrentModificationException, IOException, InvalidArgumentsException {
    // Assert input is ok
    if (!existingUser.name().equals(updatedUser.name())) {
        throw new IllegalArgumentException("The attempt to update the role from '" + existingUser.name() + "' to '" + updatedUser.name() + "' failed. Changing a roles name is not allowed.");
    }
    synchronized (this) {
        // Copy-on-write for the users list
        List<User> newUsers = new ArrayList<>();
        boolean foundUser = false;
        for (User other : users) {
            if (other.equals(existingUser)) {
                foundUser = true;
                newUsers.add(updatedUser);
            } else {
                newUsers.add(other);
            }
        }
        if (!foundUser) {
            throw new ConcurrentModificationException();
        }
        users = newUsers;
        usersByName.put(updatedUser.name(), updatedUser);
        persistUsers();
    }
}
Also used : ConcurrentModificationException(org.neo4j.server.security.auth.exception.ConcurrentModificationException) User(org.neo4j.kernel.impl.security.User) ArrayList(java.util.ArrayList)

Aggregations

User (org.neo4j.kernel.impl.security.User)6 ConcurrentModificationException (org.neo4j.server.security.auth.exception.ConcurrentModificationException)6 InvalidArgumentsException (org.neo4j.kernel.api.exceptions.InvalidArgumentsException)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1