/** * Returns the list of the Users available * * @return List<User>: The list of Users available */ @ApiOperation(value = "Retrieve all Users", notes = "Returns all registered users") @RequestMapping(method = RequestMethod.GET) public List<User> findAll() { log.trace("Find all Users"); return (List<User>) userManagement.query(); }
/** * Returns the User selected by username * * @param username : The username of the User * @return User: The User selected */ @ApiOperation( value = "Retrieve a User", notes = "Retrieves a user based on the username specified in the URL") @RequestMapping(value = "{username}", method = RequestMethod.GET) public User findById(@PathVariable("username") String username) throws NotFoundException { log.trace("find User with username " + username); User user = userManagement.query(username); log.trace("Found User: " + user); return user; }
@ApiOperation( value = "Remove multiple Users", notes = "Removes all users part of the List of ids passed in the Request Body") @RequestMapping( value = "/multipledelete", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.NO_CONTENT) public void multipleDelete(@RequestBody @Valid List<String> ids) throws NotFoundException { if (userManagement != null) { for (String id : ids) { log.info("removing User with id " + id); userManagement.delete(userManagement.query(id)); } } }
/** * Removes the User from the Users repository * * @param id : the id of user to be removed */ @ApiOperation( value = "Remove a User", notes = "Removes the user with the id specified in the URL. Admin privileges needed!") @RequestMapping(value = "{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public void delete(@PathVariable("id") String id) throws NotAllowedException, NotFoundException { log.info("Removing user with id " + id); if (isAdmin()) { if (!userManagement.getCurrentUser().getId().equals(id)) { User user = userManagement.query(id); userManagement.delete(user); } else { throw new NotAllowedException("You can't delete yourself. Please ask another admin."); } } else { throw new NotAllowedException("Forbidden to delete a user"); } }
"Project " + projectToDelete.getName() + " has still some resources allocated"); for (User user : userManagement.query()) { Set<Role> rolesToRemove = new HashSet<>(); for (Role role : user.getRoles()) {