use of org.neo4j.kernel.api.exceptions.InvalidArgumentsException in project neo4j by neo4j.
the class BasicAuthentication method update.
private AuthenticationResult update(Map<String, Object> authToken, boolean requiresPasswordChange) throws AuthenticationException {
try {
SecurityContext securityContext = authManager.login(authToken);
switch(securityContext.subject().getAuthenticationResult()) {
case SUCCESS:
case PASSWORD_CHANGE_REQUIRED:
String newPassword = AuthToken.safeCast(NEW_CREDENTIALS, authToken);
String username = AuthToken.safeCast(PRINCIPAL, authToken);
userManagerSupplier.getUserManager(securityContext).setUserPassword(username, newPassword, requiresPasswordChange);
securityContext.subject().setPasswordChangeNoLongerRequired();
break;
default:
throw new AuthenticationException(Status.Security.Unauthorized);
}
return new BasicAuthenticationResult(securityContext);
} catch (AuthorizationViolationException | InvalidArgumentsException | InvalidAuthTokenException e) {
throw new AuthenticationException(e.status(), e.getMessage(), e);
} catch (IOException e) {
throw new AuthenticationException(Status.Security.Unauthorized, e.getMessage(), e);
}
}
use of org.neo4j.kernel.api.exceptions.InvalidArgumentsException 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.kernel.api.exceptions.InvalidArgumentsException in project neo4j by neo4j.
the class UserService method getUser.
@GET
@Path("/{username}")
public Response getUser(@PathParam("username") String username, @Context HttpServletRequest req) {
Principal principal = req.getUserPrincipal();
if (principal == null || !principal.getName().equals(username)) {
return output.notFound();
}
SecurityContext securityContext = getSecurityContextFromUserPrincipal(principal);
UserManager userManager = userManagerSupplier.getUserManager(securityContext);
try {
User user = userManager.getUser(username);
return output.ok(new AuthorizationRepresentation(user));
} catch (InvalidArgumentsException e) {
return output.notFound();
}
}
use of org.neo4j.kernel.api.exceptions.InvalidArgumentsException in project neo4j by neo4j.
the class PersonalUserManager method newUser.
@Override
public User newUser(String username, String initialPassword, boolean requirePasswordChange) throws IOException, InvalidArgumentsException, AuthorizationViolationException {
try {
assertAdmin();
User user = userManager.newUser(username, initialPassword, requirePasswordChange);
securityLog.info(securityContext, "created user `%s`%s", username, requirePasswordChange ? ", with password change required" : "");
return user;
} catch (AuthorizationViolationException | IOException | InvalidArgumentsException e) {
securityLog.error(securityContext, "tried to create user `%s`: %s", username, e.getMessage());
throw e;
}
}
use of org.neo4j.kernel.api.exceptions.InvalidArgumentsException 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);
}
Aggregations