diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-01-21 09:57:16 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-01-21 09:57:16 +0100 |
commit | 2436aa273f00dafb465c2342ea8e7297898915d2 (patch) | |
tree | 27cf115b4ec6d36f84b01b50acc403cf31b3ab6b /pdf-as-web/src/main/java | |
parent | 8d801ab37834b0f11c6a16c240d77da71a6ab816 (diff) | |
download | pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.tar.gz pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.tar.bz2 pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.zip |
Implementations for pdf-as-web and pdf-as-legacy
Diffstat (limited to 'pdf-as-web/src/main/java')
4 files changed, 134 insertions, 24 deletions
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 eb04dde8..3c6a7f21 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 @@ -1,24 +1,111 @@ package at.gv.egiz.pdfas.web.config; +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class WebConfiguration { + + public static final String PUBLIC_URL = "public.url"; + public static final String LOCAL_BKU_URL = "bku.local.url"; + public static final String ONLINE_BKU_URL = "bku.online.url"; + public static final String MOBILE_BKU_URL = "bku.mobile.url"; + public static final String ERROR_DETAILS = "error.showdetails"; + public static final String PDF_AS_WORK_DIR = "pdfas.dir"; + + public static final String KEYSTORE_ENABLED = "ks.enabled"; + public static final String KEYSTORE_FILE = "ks.file"; + public static final String KEYSTORE_TYPE = "ks.type"; + public static final String KEYSTORE_PASS = "ks.pass"; + public static final String KEYSTORE_ALIAS = "ks.key.alias"; + public static final String KEYSTORE_KEY_PASS = "ks.key.pass"; + + private static Properties properties = new Properties(); + + private static final Logger logger = LoggerFactory + .getLogger(WebConfiguration.class); + + public static void configure(String config) { + try { + properties.load(new FileInputStream(config)); + } catch(Exception e) { + logger.error("Failed to load configuration: " + e.getMessage()); + throw new RuntimeException(e); + } + + String pdfASDir = getPdfASDir(); + if(pdfASDir == null) { + logger.error("Please configure pdf as working directory in the web configuration"); + throw new RuntimeException("Please configure pdf as working directory in the web configuration"); + } + + File f = new File(pdfASDir); + + if(!f.exists() || !f.isDirectory()) { + logger.error("Pdf As working directory does not exists or is not a directory!: " + pdfASDir); + throw new RuntimeException("Pdf As working directory does not exists or is not a directory!"); + } + } + public static String getPublicURL() { - return null; + return properties.getProperty(PUBLIC_URL); } public static String getLocalBKUURL() { - // TODO: Read URL from config - return "http://127.0.0.1:3495/http-security-layer-request"; + return properties.getProperty(LOCAL_BKU_URL); } public static String getOnlineBKUURL() { - // TODO: Read URL from config - return "http://abyss.iaik.tugraz.at/bkuonline/http-security-layer-request"; + return properties.getProperty(ONLINE_BKU_URL); } public static String getHandyBKUURL() { - // TODO: Read URL from config - return "http://127.0.0.1:3495/http-security-layer-request"; + return properties.getProperty(MOBILE_BKU_URL); + } + + public static String getPdfASDir() { + return properties.getProperty(PDF_AS_WORK_DIR); + } + + public static String getKeystoreFile() { + return properties.getProperty(KEYSTORE_FILE); + } + public static String getKeystoreType() { + return properties.getProperty(KEYSTORE_TYPE); + } + public static String getKeystorePass() { + return properties.getProperty(KEYSTORE_PASS); + } + public static String getKeystoreAlias() { + return properties.getProperty(KEYSTORE_ALIAS); + } + public static String getKeystoreKeyPass() { + return properties.getProperty(KEYSTORE_KEY_PASS); + } + + + public static boolean getKeystoreEnabled() { + String value = properties.getProperty(KEYSTORE_ENABLED); + if(value != null) { + if(value.equals("true")) { + return true; + } + } + return false; + } + + public static boolean isShowErrorDetails() { + String value = properties.getProperty(ERROR_DETAILS); + if(value != null) { + if(value.equals("true")) { + return true; + } + } + return false; } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index daf18108..e61a113a 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -66,14 +66,6 @@ public class PdfAsHelper { private static final String PDF_INVOKE_URL = "PDF_INVOKE_URL"; private static final String REQUEST_FROM_DU = "REQ_DATA_URL"; - // For development only: - public static final String keyStoreFile = "/home/afitzek/devel/pdfas_neu/test.p12"; - public static final String keyStoreType = "PKCS12"; - public static final String keyStorePass = "123456"; - // public static final String keyAlias = "pdf"; - public static final String keyAlias = "ecc_test"; - public static final String keyPass = "123456"; - private static final Logger logger = LoggerFactory .getLogger(PdfAsHelper.class); @@ -83,9 +75,14 @@ public class PdfAsHelper { static { // TODO: read from config file logger.debug("Creating PDF-AS"); - pdfAs = PdfAsFactory.createPdfAs(new File("/home/afitzek/.pdfas")); + pdfAs = PdfAsFactory.createPdfAs(new File(WebConfiguration.getPdfASDir())); logger.debug("Creating PDF-AS done"); } + + public static void init() { + logger.debug("PDF-AS Helper initialized"); + } + private static void validatePdfSize(HttpServletRequest request, HttpServletResponse response, byte[] pdfData) @@ -218,11 +215,10 @@ public class PdfAsHelper { if (connector.equals("moa")) { signer = new PAdESSigner(new MOAConnector(config)); } else { - // TODO: - // signer = new PAdESSignerKeystore(file, alias, kspassword, - // keypassword, type) - signer = new PKCS7DetachedSigner(keyStoreFile, keyAlias, - keyStorePass, keyPass, keyStoreType); + signer = new PKCS7DetachedSigner(WebConfiguration.getKeystoreFile(), + WebConfiguration.getKeystoreAlias(), + WebConfiguration.getKeystorePass(), WebConfiguration.getKeystoreKeyPass(), + WebConfiguration.getKeystoreType()); } signParameter.setPlainSigner(signer); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java index fceeed85..fe436566 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java @@ -12,6 +12,7 @@ import javax.swing.text.html.HTML; import org.apache.commons.lang3.StringEscapeUtils; +import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.helper.HTMLFormater; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; @@ -64,7 +65,7 @@ public class ErrorPage extends HttpServlet { String template = PdfAsHelper.getErrorRedirectTemplateSL(); template = template.replace("##ERROR_URL##", errorURL); - if (e != null) { + if (e != null && WebConfiguration.isShowErrorDetails()) { template = template.replace("##CAUSE##", URLEncoder.encode(e.getMessage(), "UTF-8")); } else { @@ -88,7 +89,7 @@ public class ErrorPage extends HttpServlet { pw.write("<p>" + message + "</p>"); } - if (e != null) { + if (e != null && WebConfiguration.isShowErrorDetails()) { pw.write("<p>" + HTMLFormater.formatStackTrace(e.getStackTrace()) + "</p>"); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java index 90c77320..c96225bd 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java @@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; import at.gv.egiz.pdfas.sigs.pades.PAdESSigner; +import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.exception.PdfAsWebException; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.helper.PdfAsParameterExtractor; @@ -33,6 +34,8 @@ public class ExternSignServlet extends HttpServlet { private static final long serialVersionUID = 1L; + public static final String PDF_AS_WEB_CONF = "pdf-as-web.conf"; + private static final String UPLOAD_PDF_DATA = "pdfFile"; private static final String UPLOAD_DIRECTORY = "upload"; private static final int THRESHOLD_SIZE = 1024 * 1024 * 3; // 3MB @@ -46,6 +49,15 @@ public class ExternSignServlet extends HttpServlet { * Default constructor. */ public ExternSignServlet() { + String webconfig = System.getProperty(PDF_AS_WEB_CONF); + + if(webconfig == null) { + logger.error("No web configuration provided! Please specify: " + PDF_AS_WEB_CONF); + throw new RuntimeException("No web configuration provided! Please specify: " + PDF_AS_WEB_CONF); + } + + WebConfiguration.configure(webconfig); + PdfAsHelper.init(); } protected void doGet(HttpServletRequest request, @@ -142,7 +154,12 @@ public class ExternSignServlet extends HttpServlet { FileItem item = (FileItem) obj; if(item.getFieldName().equals(UPLOAD_PDF_DATA)) { filecontent = item.get(); - logger.debug("Found pdf Data!"); + + if(filecontent.length < 10) { + filecontent = null; + } else { + logger.debug("Found pdf Data! Size: " + filecontent.length); + } } else { request.setAttribute(item.getFieldName(), item.getString()); logger.debug("Setting " + item.getFieldName() + " = " + item.getString()); @@ -161,6 +178,15 @@ public class ExternSignServlet extends HttpServlet { } if(filecontent == null) { + Object sourceObj = request.getAttribute("source"); + if(sourceObj != null) { + String source = sourceObj.toString(); + if(source.equals("internal")) { + request.setAttribute("FILEERR", true); + request.getRequestDispatcher("index.jsp").forward(request, response); + return; + } + } throw new PdfAsException("No Signature data available"); } |