aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java17
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java19
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/JSONAPIServlet.java31
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java8
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java4
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java4
6 files changed, 56 insertions, 27 deletions
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 11ee4790..34781461 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
@@ -364,11 +364,13 @@ public class PdfAsHelper {
* The Web response
* @param pdfData
* The pdf data
+ * @param dynamicSignatureBlockArguments
* @return The signed pdf data
* @throws Exception
*/
- public static byte[] synchornousSignature(HttpServletRequest request,
- HttpServletResponse response, byte[] pdfData) throws Exception {
+ public static byte[] synchronousSignature(HttpServletRequest request,
+ HttpServletResponse response, byte[] pdfData,
+ Map<String, String> dynamicSignatureBlockArguments) throws Exception {
validatePdfSize(request, response, pdfData);
Configuration config = pdfAs.getConfiguration();
@@ -506,6 +508,8 @@ public class PdfAsHelper {
// set Signature Position
signParameter.setSignaturePosition(buildPosString(request, response));
+ //set signature block parameters
+ signParameter.setDynamicSignatureBlockArguments(dynamicSignatureBlockArguments);
@SuppressWarnings("unused")
SignResult result = pdfAs.sign(signParameter);
@@ -522,8 +526,8 @@ public class PdfAsHelper {
* @return The signed pdf data
* @throws Exception
*/
- public static PDFASSignResponse synchornousServerSignature(byte[] pdfData,
- PDFASSignParameters params) throws Exception {
+ public static PDFASSignResponse synchronousServerSignature(byte[] pdfData,
+ PDFASSignParameters params, Map<String, String> dynamicSignatureBlockArguments) throws Exception {
Configuration config = pdfAs.getConfiguration();
if (WebConfiguration.isAllowExtOverwrite() && params.getOverrides() != null) {
@@ -658,6 +662,8 @@ public class PdfAsHelper {
signParameter.setPreprocessorArguments(params.getPreprocessor()
.getMap());
}
+ //TODO alex
+ signParameter.setDynamicSignatureBlockArguments(dynamicSignatureBlockArguments);
SignResult signResult = pdfAs.sign(signParameter);
@@ -771,7 +777,7 @@ public class PdfAsHelper {
HttpServletResponse response, ServletContext context,
byte[] pdfData, String connector, String position,
String transactionId, String profile,
- Map<String, String> preProcessor, Map<String, String> overwrite) throws Exception {
+ Map<String, String> preProcessor, Map<String, String> overwrite, Map<String, String> dynamicSignatureBlockArguments) throws Exception {
// TODO: Protect session so that only one PDF can be signed during one
// session
@@ -856,6 +862,7 @@ public class PdfAsHelper {
// set Signature Position
signParameter.setSignaturePosition(position);
+ signParameter.setDynamicSignatureBlockArguments(dynamicSignatureBlockArguments);
StatusRequest statusRequest = pdfAs.startSign(signParameter);
session.setAttribute(PDF_STATUS, statusRequest);
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 2c2af9a9..841b8428 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
@@ -27,7 +27,6 @@ import at.gv.egiz.pdfas.common.exceptions.PDFASError;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsValidationException;
import at.gv.egiz.pdfas.common.settings.ISettings;
-import at.gv.egiz.pdfas.common.utils.StringUtils;
import at.gv.egiz.pdfas.lib.api.IConfigurationConstants;
import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel;
@@ -57,6 +56,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
/**
* Servlet implementation class Sign
@@ -366,7 +366,11 @@ public class ExternSignServlet extends HttpServlet {
PdfAsHelper.setSignatureDataHash(request, pdfDataHash);
logger.debug("Storing signatures data hash: " + pdfDataHash);
-
+
+ //TODO alex parse??
+ Map<String, String> dynamicSignatureBlockArguments = null;
+
+
logger.debug("Starting signature creation with: " + connector);
//IPlainSigner signer;
@@ -396,11 +400,12 @@ public class ExternSignServlet extends HttpServlet {
}
PdfAsHelper.setStatisticEvent(request, response, statisticEvent);
-
- PdfAsHelper.startSignature(request, response, getServletContext(), pdfData, connector,
+
+
+ PdfAsHelper.startSignature(request, response, getServletContext(), pdfData, connector,
PdfAsHelper.buildPosString(request, response), transactionId, PdfAsParameterExtractor
.getSigType(request), PdfAsParameterExtractor.getPreProcessorMap(request),
- PdfAsParameterExtractor.getOverwriteMap(request));
+ PdfAsParameterExtractor.getOverwriteMap(request), dynamicSignatureBlockArguments);
return;
} else if (connector.equals("jks") || connector.equals("moa")) {
// start synchronous siganture creation
@@ -432,8 +437,8 @@ public class ExternSignServlet extends HttpServlet {
}
}
- byte[] pdfSignedData = PdfAsHelper.synchornousSignature(request,
- response, pdfData);
+ byte[] pdfSignedData = PdfAsHelper.synchronousSignature(request,
+ response, pdfData, dynamicSignatureBlockArguments);
PdfAsHelper.setSignedPdf(request, response, pdfSignedData);
statisticEvent.setStatus(Status.OK);
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 13d874e8..78bb3c69 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
@@ -1,9 +1,7 @@
package at.gv.egiz.pdfas.web.servlets;
import at.gv.egiz.pdfas.api.ws.PDFASSignParameters;
-import at.gv.egiz.pdfas.api.ws.PDFASSignRequest;
import at.gv.egiz.pdfas.api.ws.PDFASSignResponse;
-import at.gv.egiz.pdfas.api.ws.VerificationLevel;
import at.gv.egiz.pdfas.common.exceptions.PDFASError;
import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
import at.gv.egiz.pdfas.lib.api.verify.VerifyResult;
@@ -15,10 +13,9 @@ import at.gv.egiz.pdfas.web.helper.JSONStartResponse;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
import at.gv.egiz.pdfas.web.stats.StatisticEvent;
import at.gv.egiz.pdfas.web.stats.StatisticFrontend;
-import at.gv.egiz.pdfas.web.store.RequestStore;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
-import org.json.HTTP;
+import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,9 +24,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.ws.WebServiceException;
-import java.io.BufferedReader;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -49,7 +45,7 @@ public class JSONAPIServlet extends HttpServlet {
private static final String JSON_DATAURL = "dataUrl";
private static final String JSON_BKUURL = "bkuUrl";
private static final String JSON_SLREQUEST = "slRequest";
-
+ private static final String JSON_SBP = "sbp";
private static final Logger logger = LoggerFactory.getLogger(JSONAPIServlet.class);
@Override
@@ -139,11 +135,28 @@ public class JSONAPIServlet extends HttpServlet {
parameters.setPosition(position);
parameters.setProfile(profile);
+ Map<String, String> signatureBlockParametersMap = new HashMap<>();
+ try {
+ JSONArray jsonArray = jsonObject.getJSONArray(JSON_SBP);
+ if (jsonArray != null) {
+ for (int i = 0; i < jsonArray.length(); i++) {
+ String s = jsonArray.getString(0);
+ if (!s.contains("=")) {//TODO or pass as map?
+ throw new Exception("Invalid parameter: " + s);
+ }
+ String[] values = s.split("=", 2);
+ signatureBlockParametersMap.put(values[0], values[1]);
+ }
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ }
if (PDFASSignParameters.Connector.MOA.equals(connectorEnum)
|| PDFASSignParameters.Connector.JKS.equals(connectorEnum)) {
// Plain server based signatures!!
- PDFASSignResponse pdfasSignResponse = PdfAsHelper.synchornousServerSignature(
- inputDocument, parameters);
+
+ PDFASSignResponse pdfasSignResponse = PdfAsHelper.synchronousServerSignature(
+ inputDocument, parameters, signatureBlockParametersMap);
VerifyResult verifyResult = null;
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java
index 5f2dc95c..6e80fad8 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PlaceholderGeneratorServlet.java
@@ -73,9 +73,11 @@ public class PlaceholderGeneratorServlet extends HttpServlet implements Placehol
String filename = "placeholder";
if(id != null && !id.isEmpty()) {
- id = id.replaceAll("[^a-zA-Z0-9]", "_");
- buildString = buildString + ";" + SignaturePlaceholderData.ID_KEY + "=" + id;
- filename = filename + "_" + id;
+ id = id.replaceAll("[^0-9]", "");
+ if(id != null && !id.isEmpty()) {
+ buildString = buildString + ";" + SignaturePlaceholderData.ID_KEY + "=" + id;
+ filename = filename + "_" + id;
+ }
}
if(profile != null && !profile.isEmpty()) {
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java
index 73f8299c..664dd9b3 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java
@@ -174,13 +174,15 @@ public class UIEntryPointServlet extends HttpServlet {
overwrite = pdfAsRequest.getParameters().getOverrides()
.getMap();
}
+ //TODO alex
+ Map<String, String> dynamicSignatureBlockArguments = pdfAsRequest.getSignatureBlockParameters();
PdfAsHelper.startSignature(req, resp, getServletContext(),
pdfAsRequest.getInputData(), connector.toString(),
pdfAsRequest.getParameters().getPosition(),
pdfAsRequest.getParameters().getTransactionId(),
pdfAsRequest.getParameters().getProfile(), map,
- overwrite);
+ overwrite, dynamicSignatureBlockArguments);
} else {
throw new PdfAsWebException("Invalid connector ("
+ Connector.BKU + " | " + Connector.ONLINEBKU + " | "
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java
index f850c5ae..ccbaf4fb 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java
@@ -104,8 +104,8 @@ public class PDFASSigningImpl implements PDFASSigning {
|| request.getParameters().getConnector()
.equals(Connector.JKS)) {
// Plain server based signatures!!
- response = PdfAsHelper.synchornousServerSignature(
- request.getInputData(), request.getParameters());
+ response = PdfAsHelper.synchronousServerSignature(
+ request.getInputData(), request.getParameters(), request.getSignatureBlockParameters());
VerifyResult verifyResult = null;
if (request.getVerificationLevel() != null &&