@ApiOperation(value = "Retrieve the current User", notes = "Returns the user currently accessing") @RequestMapping(value = "current", method = RequestMethod.GET) public User findCurrentUser() throws NotFoundException { User user = userManagement.getCurrentUser(); 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)); } } }
/** * Updates the User * * @param new_user : The User to be updated * @return User The User updated */ @ApiOperation( value = "Update a User", notes = "Updates a user based on the username specified in the url and the updated user body in the request") @RequestMapping( value = "{username}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public User update(@RequestBody @Valid User new_user) throws NotAllowedException, BadRequestException, NotFoundException { return userManagement.update(new_user); }
/** * 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"); } }
/** * 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(); }
public BaseUser getCurrentUser() throws NotFoundException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new NotFoundException("authentication invalid"); } String currentUserName = authentication.getName(); User user; try { user = userManagement.queryByName(currentUserName); } catch (NotFoundException e) { return serviceRepository.findByName(currentUserName); } return user; }
@ApiOperation( value = "Changing the current User's password", notes = "The current user can change his password by providing a new one") @RequestMapping( value = "changepwd", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public void changePassword(@RequestBody /*@Valid*/ JsonObject newPwd) throws UnauthorizedUserException, PasswordWeakException { log.debug("Changing password"); JsonObject jsonObject = gson.fromJson(newPwd, JsonObject.class); userManagement.changePassword( jsonObject.get("old_pwd").getAsString(), jsonObject.get("new_pwd").getAsString()); }
@ApiOperation( value = "Changing a User's password", notes = "If you want to change another User's password, you have to be an admin") @RequestMapping( value = "changepwd/{username}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public void changePasswordOf( @PathVariable("username") String username, @RequestBody /*@Valid*/ JsonObject newPwd) throws UnauthorizedUserException, PasswordWeakException, NotFoundException, NotAllowedException { log.debug("Changing password of user " + username); if (isAdmin()) { JsonObject jsonObject = gson.fromJson(newPwd, JsonObject.class); userManagement.changePasswordOf(username, jsonObject.get("new_pwd").getAsString()); } else { throw new NotAllowedException( "Forbidden to change password of other users. Only admins can do this."); } }
/** * Adds a new User to the Users repository * * @param user * @return user */ @ApiOperation( value = "Adding a User", notes = "The User data is passed as JSON in the Request Body") @RequestMapping( method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public User create(@RequestBody @Valid User user) throws PasswordWeakException, NotAllowedException, BadRequestException, NotFoundException { log.info("Adding user: " + user.getUsername()); if (isAdmin()) { user = userManagement.add(user); // user.setPassword(null); } else { throw new NotAllowedException("Forbidden to create a new user"); } return user; }
/** * 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; }
BaseUser baseUser; try { baseUser = userManagement.queryByName(currentUserName); } catch (NotFoundException e) { log.trace("User not found for name: " + currentUserName + " maybe a service?");
private String getOpenRcFile(String projectId) throws NotFoundException { return "#!/bin/bash\n" + "\n" + "unset OB_NFVO_IP\n" + "unset OB_NFVO_PORT\n" + "unset OB_PROJECT_ID\n" + "unset OB_USERNAME\n" + "unset OB_PASSWORD\n\n" + "export OB_NFVO_IP=" + nfvoIp + "\n" + "export OB_NFVO_PORT=" + nfvoPort + "\n" + "export OB_PROJECT_ID=" + projectId + "\n" + "export OB_USERNAME=" + userManagement.getCurrentUser().getUsername() + "\n" + "echo -n Insert Open Baton Password: \n" + "read -s password\n" + "export OB_PASSWORD=$password\n"; } }
public boolean isAdmin() throws NotFoundException { User currentUser = userManagement.getCurrentUser(); log.trace("Check user if admin: " + currentUser.getUsername()); for (Role role : currentUser.getRoles()) { if (role.getRole().ordinal() == Role.RoleEnum.ADMIN.ordinal()) { return true; } } return false; } }
user = userManagement.getCurrentUser(); } catch (org.openbaton.exceptions.NotFoundException ex) { return;