Beispiel #1
0
  public void create(List<UserSearchModel> userSearchModels, HttpLocalizedOperationResult result) {
    if (userSearchModels.isEmpty()) {
      result.badRequest(LocalizedMessage.string("NO_USERS_SELECTED"));
      return;
    }
    synchronized (enableUserMutex) {
      for (UserSearchModel userSearchModel : userSearchModels) {
        User user = userSearchModel.getUser();

        if (userExists(user)) {
          result.conflict(
              LocalizedMessage.string(
                  "USER_ALREADY_EXISTS", user.getName(), user.getDisplayName(), user.getEmail()));
          return;
        }

        if (user.isAnonymous()) {
          result.badRequest(LocalizedMessage.string("USERNAME_NOT_PERMITTED", user.getName()));
          return;
        }

        if (!userSearchModel.getUserSourceType().equals(UserSourceType.PASSWORD_FILE)
            && validateEmailAndMatcher(result, user)) {
          return;
        }
        userDao.saveOrUpdate(user);
        result.setMessage(LocalizedMessage.string("USER_SUCCESSFULLY_ADDED", user.getName()));
      }
    }
  }
Beispiel #2
0
 private boolean validateEmailAndMatcher(HttpLocalizedOperationResult result, User user) {
   try {
     validate(user);
   } catch (ValidationException e) {
     result.badRequest(LocalizedMessage.string("USER_FIELD_VALIDATIONS_FAILED", e.getMessage()));
     return true;
   }
   return false;
 }
Beispiel #3
0
 public void deleteUser(String username, HttpLocalizedOperationResult result) {
   try {
     userDao.deleteUser(username);
     result.setMessage(LocalizedMessage.string("USER_DELETE_SUCCESSFUL", username));
   } catch (UserNotFoundException e) {
     result.notFound(
         LocalizedMessage.string("USER_NOT_FOUND", username),
         HealthStateType.general(HealthStateScope.GLOBAL));
   } catch (UserEnabledException e) {
     result.badRequest(LocalizedMessage.string("USER_NOT_DISABLED", username));
   }
 }