@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); } }
@Override public void onError(Throwable exception) { PluginLogger.error( "Unable to check authentication permissions, are you sure the credentials are valid?"); PluginLogger.error("Username provided: {0}", Config.WEBSERVICE.USERNAME.get()); PluginLogger.error( "The network operations will be disabled", exception, Config.WEBSERVICE.URL.get()); ZBanque.get().setWebServiceEnabled(false); }