Ejemplo n.º 1
0
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @Transactional(readOnly = false)
  public ResultClass<Boolean> addUser(User user) {
    ResultClass<Boolean> result = new ResultClass<>();
    StringSHA sha = new StringSHA();
    String pass = sha.getStringMessageDigest(user.getPassword());
    user.setPassword(pass);
    if (repositoryUser.addUser(user)) {
      User u = findByUsername(user.getUsername()).getSingleElement();
      manageAclService.addACLToObject(u.getId(), u.getClass().getName());

      manageAclService.addPermissionToAnObject_WRITE(u, u.getId(), u.getClass().getName());
      result.setSingleElement(true);
    } else result.setSingleElement(false);

    return result;
  }
Ejemplo n.º 2
0
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @Transactional(readOnly = false)
  public ResultClass<Boolean> uploadCVS(UploadForm upload, String typeOfUser, Locale locale) {
    ResultClass<Boolean> result = new ResultClass<>();
    if (!upload.getFileData().isEmpty()) {
      CsvPreference prefers =
          new CsvPreference.Builder(
                  upload.getQuoteChar().charAt(0),
                  upload.getDelimiterChar().charAt(0),
                  upload.getEndOfLineSymbols())
              .build();

      List<User> list = null;
      try {
        FileItem fileItem = upload.getFileData().getFileItem();
        UserCSV userUpload = new UserCSV();
        list =
            userUpload.readCSVUserToBean(
                fileItem.getInputStream(), upload.getCharset(), prefers, typeOfUser);
        if (list == null) {
          result.setHasErrors(true);
          result.getErrorsList().add(messageSource.getMessage("error.params", null, locale));
        } else {
          if (repositoryUser.persistListUsers(list)) {
            for (User u : list) {
              User aux = findByUsername(u.getUsername()).getSingleElement();
              manageAclService.addACLToObject(u.getId(), u.getClass().getName());
              manageAclService.addPermissionToAnObject_WRITE(
                  aux, aux.getId(), aux.getClass().getName());
            }
            result.setSingleElement(true);
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
        result.setSingleElement(false);
      }
    } else {
      result.setHasErrors(true);
      result.getErrorsList().add(messageSource.getMessage("error.fileEmpty", null, locale));
    }
    return result;
  }