aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-01-21 09:57:16 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-01-21 09:57:16 +0100
commit2436aa273f00dafb465c2342ea8e7297898915d2 (patch)
tree27cf115b4ec6d36f84b01b50acc403cf31b3ab6b /pdf-as-web
parent8d801ab37834b0f11c6a16c240d77da71a6ab816 (diff)
downloadpdf-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')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java101
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java24
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java5
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java28
-rw-r--r--pdf-as-web/src/main/webapp/WEB-INF/web.xml2
-rw-r--r--pdf-as-web/src/main/webapp/assets/img/mobileBKU.pngbin0 -> 9742 bytes
-rw-r--r--pdf-as-web/src/main/webapp/assets/img/onlineBKU.pngbin0 -> 6650 bytes
-rw-r--r--pdf-as-web/src/main/webapp/index.jsp59
-rw-r--r--pdf-as-web/src/test/pdf-as-web.properties27
9 files changed, 207 insertions, 39 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");
}
diff --git a/pdf-as-web/src/main/webapp/WEB-INF/web.xml b/pdf-as-web/src/main/webapp/WEB-INF/web.xml
index 81fa6dad..40642fcc 100644
--- a/pdf-as-web/src/main/webapp/WEB-INF/web.xml
+++ b/pdf-as-web/src/main/webapp/WEB-INF/web.xml
@@ -35,7 +35,7 @@
The Sign Servlet allows Users to Sign PDF Documents ...
</description>
<servlet-class>at.gv.egiz.pdfas.web.servlets.ExternSignServlet</servlet-class>
- <load-on-startup>5</load-on-startup>
+ <load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>ProvidePDF</servlet-name>
diff --git a/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png b/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png
new file mode 100644
index 00000000..48e77934
--- /dev/null
+++ b/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png
Binary files differ
diff --git a/pdf-as-web/src/main/webapp/assets/img/onlineBKU.png b/pdf-as-web/src/main/webapp/assets/img/onlineBKU.png
new file mode 100644
index 00000000..2ec41892
--- /dev/null
+++ b/pdf-as-web/src/main/webapp/assets/img/onlineBKU.png
Binary files differ
diff --git a/pdf-as-web/src/main/webapp/index.jsp b/pdf-as-web/src/main/webapp/index.jsp
index 2dd79101..8aba0dff 100644
--- a/pdf-as-web/src/main/webapp/index.jsp
+++ b/pdf-as-web/src/main/webapp/index.jsp
@@ -1,21 +1,52 @@
+<%@page import="at.gv.egiz.pdfas.web.config.WebConfiguration"%>
<html>
<head>
<title>PDF-Signatur</title>
</head>
<body>
-<form role="form" action="Sign" method="POST" enctype="multipart/form-data">
- <div class="form-group">
- <label for="exampleInputFile">Signieren: </label>
- <input type="file" name="pdfFile" id="pdfFile">
- <p class="help-block">Zu signierende PDF Datei</p>
- </div>
- <div class="form-group">
- <button type="submit" value="jks" name="connector" class="btn btn-primary">JKS</button>
- <button type="submit" value="bku" name="connector" class="btn btn-primary">Lokale BKU</button>
- <button type="submit" value="onlinebku" name="connector" class="btn btn-primary">Online BKU</button>
- <button type="submit" value="mobilebku" name="connector" class="btn btn-primary">Handy</button>
- <button type="submit" value="moa" name="connector" class="btn btn-primary">MOA-SS</button>
- </div>
-</form>
+ <form role="form" action="Sign" method="POST"
+ enctype="multipart/form-data">
+ <input type="hidden" name="source" id="source" value="internal"/>
+ <div class="form-group <% if(request.getAttribute("FILEERR") != null) { %> has-error <% } %>">
+ <label for="exampleInputFile">Signieren: </label> <input type="file"
+ name="pdfFile" id="pdfFile" accept="application/pdf">
+ <p class="help-block">
+ <% if(request.getAttribute("FILEERR") != null) { %>
+ Bitte die zu signierende PDF Datei angeben.
+ <% } else { %>
+ Zu signierende PDF Datei
+ <% } %></p>
+ </div>
+ <% if(WebConfiguration.getOnlineBKUURL() != null ||
+ WebConfiguration.getLocalBKUURL() != null) { %>
+ <div class="form-group">
+ <!-- button type="submit" value="jks" name="connector" class="btn btn-primary">JKS</button-->
+ <label for="bku"><img src="assets/img/onlineBKU.png" /></label>
+ <% if(WebConfiguration.getLocalBKUURL() != null) { %>
+ <button type="submit" value="bku" name="connector"
+ class="btn btn-primary" id="bku">Lokale BKU</button>
+ <% } %>
+ <% if(WebConfiguration.getOnlineBKUURL() != null) { %>
+ <button type="submit" value="onlinebku" name="connector"
+ class="btn btn-primary" id="onlinebku">Online BKU</button>
+ <% } %>
+ </div>
+ <% } %>
+ <% if(WebConfiguration.getHandyBKUURL() != null) { %>
+ <div class="form-group">
+ <label for="mobilebku"><img src="assets/img/mobileBKU.png" /></label>
+ <button type="submit" value="mobilebku" name="connector"
+ class="btn btn-primary" id="mobilebku">Handy</button>
+ <!-- button type="submit" value="moa" name="connector" class="btn btn-primary">MOA-SS</button -->
+ </div>
+ <% } %>
+ <% if(WebConfiguration.getKeystoreEnabled()) { %>
+ <div class="form-group">
+ <button type="submit" value="jks" name="connector"
+ class="btn btn-primary" id="jks">Server Keystore</button>
+ <!-- button type="submit" value="moa" name="connector" class="btn btn-primary">MOA-SS</button -->
+ </div>
+ <% } %>
+ </form>
</body>
</html> \ No newline at end of file
diff --git a/pdf-as-web/src/test/pdf-as-web.properties b/pdf-as-web/src/test/pdf-as-web.properties
new file mode 100644
index 00000000..8f60c63f
--- /dev/null
+++ b/pdf-as-web/src/test/pdf-as-web.properties
@@ -0,0 +1,27 @@
+
+# Define Public URL prefix for PDF-AS Web. For example if behind a proxy, or in a cluster
+#public.url=
+
+error.showdetails=true
+
+pdfas.dir=
+
+#BKU URLs. To deactivate a BKU, just uncomment it.
+
+# URL for Local BKU
+bku.local.url=http://127.0.0.1:3495/http-security-layer-request
+
+# URL for Online BKU
+bku.online.url=http://abyss.iaik.tugraz.at/bkuonline/http-security-layer-request
+
+# URL for Mobile BKU
+#bku.mobile.url=
+
+
+# Support Keystore
+ks.enabled=true
+ks.file=/home/afitzek/devel/pdfas_neu/test.p12
+ks.type=PKCS12
+ks.pass=123456
+ks.key.alias=ecc_test
+ks.key.pass=123456 \ No newline at end of file