@Override
  public void onResponse(JsonElement data) {
    boolean invalidResponse = false;

    if (!data.isJsonObject()) invalidResponse = true;

    JsonObject object = data.getAsJsonObject();

    if ((!object.has("username") || !object.get("username").isJsonPrimitive())
        || (!object.has("permissions") || !object.get("permissions").isJsonObject()))
      invalidResponse = true;

    if (invalidResponse) {
      PluginLogger.error("Strange response received from the /check_auth endpoint: {0}", data);
      PluginLogger.warning(
          "You are authenticated, but the permissions cannot be checked. Requests may fail!");
      return;
    }

    final JsonObject permissions = object.get("permissions").getAsJsonObject();

    final String username = object.get("username").getAsString();
    final Boolean canPost = isPermissionGranted(permissions, "can_post");

    PluginLogger.info("Authentication successful against the webservice as {0}", username);

    if (!canPost) {
      PluginLogger.error(
          "The user {0} is not allowed to send POST request. Disabling webservice integration.");
      ZBanque.get().setWebServiceEnabled(false);
    } else {
      ZBanque.get().setWebServiceEnabled(true);
    }
  }
Exemple #2
0
 @Override
 public void onEnable() {
   if (thread != null && thread.isAlive()) {
     PluginLogger.warning("Restarting thread '{0}'.", name);
     onDisable();
   }
   callbackManager.init();
   if (mainThreadExecutor != null) mainThreadExecutor.init();
   runningWorkers.put(getClass(), this);
   thread = createThread();
   thread.start();
 }