@PreAuthorize("hasRole('ROLE_USER')") @Transactional(readOnly = false) public ResultClass<Integer> numberOfPages() { ResultClass<Integer> result = new ResultClass<>(); result.setSingleElement(repositoryUser.numberOfPages()); return result; }
@PreAuthorize("hasRole('ROLE_USER')") @Transactional(readOnly = true) public ResultClass<User> getUser(Long id_user) { ResultClass<User> result = new ResultClass<>(); result.setSingleElement(repositoryUser.getUser(id_user)); return result; }
@PreAuthorize("hasRole('ROLE_ADMIN')") @Transactional(propagation = Propagation.REQUIRED) public ResultClass<Boolean> deleteUser(Long id) { ResultClass<Boolean> result = new ResultClass<>(); result.setSingleElement(repositoryUser.deleteUser(id)); return result; }
@PreAuthorize("#user.username == principal.username or hasRole('ROLE_ADMIN')") @Transactional(readOnly = false) public ResultClass<Boolean> saveUser(User user) { ResultClass<Boolean> result = new ResultClass<>(); result.setSingleElement(repositoryUser.saveUser(user)); return result; }
@PreAuthorize("permitAll") @Transactional(readOnly = true) public ResultClass<User> findByUsername(String username) { ResultClass<User> result = new ResultClass<>(); result.setSingleElement(repositoryUser.findByUsername(username)); return result; }
@PreAuthorize("hasRole('ROLE_USER')") @Transactional(readOnly = true) public ResultClass<User> getAll(Integer pageIndex, Boolean showAll, String typeOfUser) { ResultClass<User> result = new ResultClass<>(); result.addAll(repositoryUser.getAll(pageIndex, showAll, typeOfUser)); return result; }
@PreAuthorize("hasRole('ROLE_ADMIN')") @Transactional(readOnly = true) public ResultClass<User> getAll() { ResultClass<User> result = new ResultClass<>(); result.addAll(repositoryUser.getAllUsers()); return result; }
@PreAuthorize("hasPermission(#group, 'WRITE') or hasPermission(#group, 'ADMINISTRATION')") public Collection<User> getListUsersWithId(Group group, List<User> list) { // TODO Auto-generated method stub Collection<User> usersId = new ArrayList<User>(); for (User u : list) { usersId.add(repositoryUser.findByUsername(u.getUsername())); } return usersId; }
@PreAuthorize("hasRole('ROLE_ADMIN')") @Transactional(readOnly = true) public void downloadCSV(HttpServletResponse response) throws IOException { Collection<User> users = new ArrayList<User>(); users = repositoryUser.getAllUsers(); if (!users.isEmpty()) { UserCSV userCSV = new UserCSV(); userCSV.downloadCSV(response, users); } }
@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; }
@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; }
@PreAuthorize("hasPermission(#group, 'WRITE') or hasPermission(#group, 'ADMINISTRATION')") public ResultClass<Boolean> persistListUsers(Group group, List<User> list) { ResultClass<Boolean> result = new ResultClass<>(); result.setSingleElement(repositoryUser.persistListUsers(list)); return result; }
@PreAuthorize("hasRole('ROLE_USER')") public ResultClass<String> getAllByRole(String user_role) { ResultClass<String> result = new ResultClass<>(); result.addAll(repositoryUser.getAllByRole(user_role)); return result; }