Search in sources :

Example 1 with ConcurrentModificationException

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

the class BasicAuthManager method setUserPassword.

@Override
public void setUserPassword(String username, String password, boolean requirePasswordChange) throws IOException, InvalidArgumentsException {
    User existingUser = getUser(username);
    passwordPolicy.validatePassword(password);
    if (existingUser.credentials().matchesPassword(password)) {
        throw new InvalidArgumentsException("Old password and new password cannot be the same.");
    }
    try {
        User updatedUser = existingUser.augment().withCredentials(Credential.forPassword(password)).withRequiredPasswordChange(requirePasswordChange).build();
        userRepository.update(existingUser, updatedUser);
    } catch (ConcurrentModificationException e) {
        // try again
        setUserPassword(username, password, requirePasswordChange);
    }
}
Also used : ConcurrentModificationException(org.neo4j.server.security.auth.exception.ConcurrentModificationException) User(org.neo4j.kernel.impl.security.User) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException)

Example 2 with ConcurrentModificationException

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

the class FileUserRepositoryTest method shouldThrowIfExistingUserDoesNotMatch.

@Test
public void shouldThrowIfExistingUserDoesNotMatch() throws Throwable {
    // Given
    FileUserRepository users = new FileUserRepository(fs, authFile, logProvider);
    User user = new User.Builder("jake", Credential.INACCESSIBLE).withRequiredPasswordChange(true).build();
    users.create(user);
    User modifiedUser = user.augment().withCredentials(Credential.forPassword("foo")).build();
    // When
    User updatedUser = user.augment().withCredentials(Credential.forPassword("bar")).build();
    try {
        users.update(modifiedUser, updatedUser);
        fail("expected exception not thrown");
    } catch (ConcurrentModificationException e) {
    // Then continue
    }
}
Also used : ConcurrentModificationException(org.neo4j.server.security.auth.exception.ConcurrentModificationException) User(org.neo4j.kernel.impl.security.User) Test(org.junit.Test)

Example 3 with ConcurrentModificationException

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

the class InternalFlatFileRealm method activateUser.

@Override
public void activateUser(String username, boolean requirePasswordChange) throws IOException, InvalidArgumentsException {
    User user = getUser(username);
    if (user.hasFlag(IS_SUSPENDED)) {
        User activatedUser = user.augment().withoutFlag(IS_SUSPENDED).withRequiredPasswordChange(requirePasswordChange).build();
        try {
            synchronized (this) {
                userRepository.update(user, activatedUser);
            }
        } catch (ConcurrentModificationException e) {
            // Try again
            activateUser(username, requirePasswordChange);
        }
    }
    clearCacheForUser(username);
}
Also used : ConcurrentModificationException(org.neo4j.server.security.auth.exception.ConcurrentModificationException) User(org.neo4j.kernel.impl.security.User)

Example 4 with ConcurrentModificationException

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

the class InternalFlatFileRealm method setUserPassword.

@Override
public void setUserPassword(String username, String password, boolean requirePasswordChange) throws IOException, InvalidArgumentsException {
    User existingUser = getUser(username);
    passwordPolicy.validatePassword(password);
    if (existingUser.credentials().matchesPassword(password)) {
        throw new InvalidArgumentsException("Old password and new password cannot be the same.");
    }
    try {
        User updatedUser = existingUser.augment().withCredentials(Credential.forPassword(password)).withRequiredPasswordChange(requirePasswordChange).build();
        synchronized (this) {
            userRepository.update(existingUser, updatedUser);
        }
    } catch (ConcurrentModificationException e) {
        // try again
        setUserPassword(username, password, requirePasswordChange);
    }
    clearCacheForUser(username);
}
Also used : ConcurrentModificationException(org.neo4j.server.security.auth.exception.ConcurrentModificationException) User(org.neo4j.kernel.impl.security.User) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException)

Example 5 with ConcurrentModificationException

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

the class InternalFlatFileRealm method suspendUser.

@Override
public void suspendUser(String username) throws IOException, InvalidArgumentsException {
    User user = getUser(username);
    if (!user.hasFlag(IS_SUSPENDED)) {
        User suspendedUser = user.augment().withFlag(IS_SUSPENDED).build();
        try {
            synchronized (this) {
                userRepository.update(user, suspendedUser);
            }
        } catch (ConcurrentModificationException e) {
            // Try again
            suspendUser(username);
        }
    }
    clearCacheForUser(username);
}
Also used : ConcurrentModificationException(org.neo4j.server.security.auth.exception.ConcurrentModificationException) User(org.neo4j.kernel.impl.security.User)

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