@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; }
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"; } }
/** * 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"); } }
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;