From 9440e26621193d138ebe26b32405b33d41b7c7ab Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 27 Jun 2016 16:06:53 +0200 Subject: added configuration entry for json API --- .../java/at/gv/egiz/pdfas/web/config/WebConfiguration.java | 11 +++++++++++ .../java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'pdf-as-web/src') diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java index 7fbed8d9..6c3b4a76 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java @@ -58,6 +58,7 @@ public class WebConfiguration implements IConfigurationConstants { public static final String RELOAD_PASSWORD = "reload.pwd"; public static final String RELOAD_ENABLED = "reload.enabled"; public static final String KEEP_SIGNED_DOCUMENT = "keep.signed"; + public static final String JSON_API_ENABLED = "json.enabled"; public static final String MOA_LIST = "moal"; public static final String MOA_URL = "url"; @@ -301,6 +302,16 @@ public class WebConfiguration implements IConfigurationConstants { return false; } + public static boolean isJSONAPIEnabled() { + String value = properties.getProperty(JSON_API_ENABLED); + if (value != null) { + if (value.equals("true")) { + return true; + } + } + return false; + } + public static boolean isKeepSignedDocument() { String value = properties.getProperty(KEEP_SIGNED_DOCUMENT); if (value != null) { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java index 1b9b4560..67b242d0 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java @@ -56,6 +56,11 @@ public class JSONAPIServlet extends HttpServlet { protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + if(!WebConfiguration.isJSONAPIEnabled()) { + logger.info("Access to JSON API, but JSON API is disabled. Returning 404 error."); + resp.sendError(404); + } + String jsonString = IOUtils.toString(req.getInputStream(), "UTF-8"); logger.debug("Reading json String {}", jsonString); -- cgit v1.2.3