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);
}
}
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
}
}
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);
}
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);
}
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);
}
Aggregations