@POST @Path("/account/disable/{param}") @Produces(MediaType.APPLICATION_JSON) public Response disableAccount(@PathParam("param") String pubKey) { Response response = null; DbHandler dbh = getDbh(); if (dbh != null) { SecurityDbHandler secdb = new SecurityDbHandler(); boolean disabled = secdb.disableUser(pubKey, getSubject()); if (disabled) { response = new Simple("Account " + pubKey + " has been disabled"); } else { response = new Error(Error.REQUEST_FAILED, "Unable to disable account"); } } else { response = httpResponseCode(FORBIDDEN); } return response; }
@POST @Path("/account/create/{param}") @Produces(MediaType.APPLICATION_JSON) public Response createNewAccount(@PathParam("param") String prefix) { Response response = null; DbHandler dbh = getDbh(); if (dbh != null) { SecurityDbHandler secdb = new SecurityDbHandler(); Set<Role> roles = new HashSet<>(); roles.add(Role.DATA_SHARING_PARTICIPANT); String apiKey = secdb.addUser(roles, prefix, getSubject()); String secret = (apiKey != null) ? secdb.getSecret(apiKey) : null; if (apiKey != null && secret != null) { response = new AccountInfo(apiKey, secret); } else { response = new Error(Error.REQUEST_FAILED, "Unable to create account"); } } else { response = httpResponseCode(FORBIDDEN); } return response; }