@POST
  @RequireApplicationAccess
  @Consumes(MediaType.APPLICATION_JSON)
  public JSONWithPadding executePost(
      @Context UriInfo ui,
      EntityHolder<Object> body,
      @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    logger.debug("ServiceResource.executePost");

    Object json = body.getEntity();

    ApiResponse response = createApiResponse();

    response.setAction("post");
    response.setApplication(services.getApplication());
    response.setParams(ui.getQueryParameters());

    ServicePayload payload = getPayload(json);

    executeServiceRequest(ui, response, ServiceAction.POST, payload);

    return new JSONWithPadding(response, callback);
  }
  @PUT
  @Path("password")
  public JSONWithPadding setUserPasswordPut(
      @Context UriInfo ui,
      Map<String, Object> json,
      @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    if (json == null) {
      return null;
    }

    String oldPassword = string(json.get("oldpassword"));
    String newPassword = string(json.get("newpassword"));

    if (isServiceAdmin()) {
      management.setAdminUserPassword(user.getUuid(), newPassword);
    } else {
      management.setAdminUserPassword(user.getUuid(), oldPassword, newPassword);
    }

    ApiResponse response = createApiResponse();
    response.setAction("set user password");

    return new JSONWithPadding(response, callback);
  }
  @GET
  @Path("reactivate")
  public JSONWithPadding reactivate(
      @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    logger.info("Send activation email for organization: " + organization.getUuid());

    ApiResponse response = createApiResponse();

    management.startOrganizationActivationFlow(organization);

    response.setAction("reactivate organization");
    return new JSONWithPadding(response, callback);
  }
  @RequireOrganizationAccess
  @GET
  @Path("feed")
  public JSONWithPadding getFeed(
      @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    ApiResponse response = createApiResponse();
    response.setAction("get organization feed");

    ServiceResults results = management.getOrganizationActivity(organization);
    response.setEntities(results.getEntities());
    response.setSuccess();

    return new JSONWithPadding(response, callback);
  }
  @DELETE
  @RequireApplicationAccess
  public JSONWithPadding executeDelete(
      @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    logger.debug("ServiceResource.executeDelete");

    ApiResponse response = createApiResponse();
    response.setAction("delete");
    response.setApplication(services.getApplication());
    response.setParams(ui.getQueryParameters());

    executeServiceRequest(ui, response, ServiceAction.DELETE, null);

    return new JSONWithPadding(response, callback);
  }
  @POST
  @Path("revoketokens")
  public JSONWithPadding revokeTokensPost(
      @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    UUID adminId = user.getUuid();

    logger.info("Revoking user tokens for {}", adminId);

    ApiResponse response = createApiResponse();

    management.revokeAccessTokensForAdminUser(adminId);

    response.setAction("revoked user tokens");
    return new JSONWithPadding(response, callback);
  }
  @RequireOrganizationAccess
  @POST
  @Path("credentials")
  public JSONWithPadding generateCredentials(
      @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    ApiResponse response = createApiResponse();
    response.setAction("generate organization client credentials");

    ClientCredentialsInfo credentials =
        new ClientCredentialsInfo(
            management.getClientIdForOrganization(organization.getUuid()),
            management.newClientSecretForOrganization(organization.getUuid()));

    response.setCredentials(credentials);
    return new JSONWithPadding(response, callback);
  }
  @RequireAdminUserAccess
  @GET
  public JSONWithPadding getUserData(
      @Context UriInfo ui,
      @QueryParam("ttl") long ttl,
      @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    ApiResponse response = createApiResponse();
    response.setAction("get admin user");

    String token = management.getAccessTokenForAdminUser(SubjectUtils.getUser().getUuid(), ttl);
    Map<String, Object> userOrganizationData =
        management.getAdminUserOrganizationData(user.getUuid());
    userOrganizationData.put("token", token);
    response.setData(userOrganizationData);
    response.setSuccess();

    return new JSONWithPadding(response, callback);
  }
  @PUT
  public JSONWithPadding setUserInfo(
      @Context UriInfo ui,
      Map<String, Object> json,
      @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    if (json == null) {
      return null;
    }

    setUserPasswordPut(ui, json, callback);

    String email = string(json.get("email"));
    String username = string(json.get("username"));
    String name = string(json.get("name"));

    management.updateAdminUser(user, username, name, email);

    ApiResponse response = createApiResponse();
    response.setAction("update user info");

    return new JSONWithPadding(response, callback);
  }