diff options
Diffstat (limited to 'pdf-as-web')
7 files changed, 84 insertions, 44 deletions
diff --git a/pdf-as-web/build.gradle b/pdf-as-web/build.gradle index d97ad500..ec6f9a45 100644 --- a/pdf-as-web/build.gradle +++ b/pdf-as-web/build.gradle @@ -3,11 +3,16 @@ apply plugin: 'eclipse' apply plugin: 'eclipse-wtp' apply plugin: 'war' +apply plugin: 'org.akhikhl.gretty' + buildscript { repositories { jcenter() // enable this to use snapshot versions of Gretty: // maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' } + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { @@ -15,7 +20,7 @@ buildscript { } } -apply plugin: 'org.akhikhl.gretty' + configurations { providedCompile pdfbox2 @@ -41,32 +46,30 @@ sourceSets.test.runtimeClasspath += configurations.providedCompile dependencies { - compile project (':pdf-as-lib') - compile project (':pdf-as-moa') - compile project (':signature-standards:sigs-pkcs7detached') - compile project (':signature-standards:sigs-pades') - pdfbox1 project (':pdf-as-pdfbox') - compile project (':pdf-as-web-status') - compile project (':pdf-as-web-statistic-api') - compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1' - compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.21' - compile group: 'org.apache.pdfbox', name: 'pdfbox-tools', version: '2.0.21' - compile group: 'org.apache.pdfbox', name: 'preflight', version: '2.0.21' - compile group: 'opensymphony', name: 'sitemesh', version: '2.4.2' - compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' - compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' - compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3' - compile "commons-codec:commons-codec:1.9" - compile 'org.apache.commons:commons-lang3:3.3.2' - compile 'org.apache.cxf:cxf-rt-transports-http:3.0.1' - compile 'org.apache.cxf:cxf-rt-frontend-jaxws:3.0.1' - compile 'com.thetransactioncompany:cors-filter:2.3' - compile 'ch.qos.logback:logback-classic:1.1.3' - compile 'ch.qos.logback:logback-core:1.1.3' - compile 'org.json:json:20160212' + api project (':pdf-as-lib') + api project (':pdf-as-moa') + api project (':signature-standards:sigs-pkcs7detached') + api project (':signature-standards:sigs-pades') + // pdfbox1 project (':pdf-as-pdfbox') + api project (':pdf-as-web-status') + api project (':pdf-as-web-statistic-api') + api group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1' + api group: 'opensymphony', name: 'sitemesh', version: '2.4.2' + api group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' + api group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' + api group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3' + api "commons-codec:commons-codec:1.15" + api 'org.apache.commons:commons-lang3:3.12.0' + api 'org.apache.cxf:cxf-rt-transports-http:3.4.1' + api 'org.apache.cxf:cxf-rt-frontend-jaxws:3.4.1' + api 'com.thetransactioncompany:cors-filter:2.9.1' + api 'ch.qos.logback:logback-classic:1.2.3' + api 'ch.qos.logback:logback-core:1.2.3' + api 'org.json:json:20210307' + api group: 'javax.jws', name: 'javax.jws-api', version: '1.1' pdfbox2 project (':pdf-as-pdfbox-2') - providedCompile 'javax.servlet:javax.servlet-api:3.0.1' - testCompile group: 'junit', name: 'junit', version: '4.+' + compileOnly 'javax.servlet:javax.servlet-api:3.0.1' + testImplementation group: 'junit', name: 'junit', version: '4.+' } gretty { 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 3262c102..2f7c9323 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); @@ -523,7 +527,8 @@ public class PdfAsHelper { * @throws Exception */ public static PDFASSignResponse synchronousServerSignature(byte[] pdfData, - PDFASSignParameters params) throws Exception { + PDFASSignParameters params, Map<String, String> dynamicSignatureBlockArguments) throws Exception { + Configuration config = pdfAs.getConfiguration(); if (WebConfiguration.isAllowExtOverwrite() && params.getOverrides() != null) { @@ -658,6 +663,8 @@ public class PdfAsHelper { signParameter.setPreprocessorArguments(params.getPreprocessor() .getMap()); } + //TODO alex + signParameter.setDynamicSignatureBlockArguments(dynamicSignatureBlockArguments); SignResult signResult = pdfAs.sign(signParameter); @@ -771,7 +778,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 +863,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 7d01cdcc..641c09e7 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 @@ -15,6 +15,7 @@ import at.gv.egiz.pdfas.web.stats.StatisticEvent; import at.gv.egiz.pdfas.web.stats.StatisticFrontend; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; +import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +25,9 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Created by Andreas Fitzek on 6/23/16. @@ -42,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 @@ -132,11 +135,27 @@ 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.synchronousServerSignature( - inputDocument, parameters); + 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 5f8fc343..531abdf1 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 @@ -105,7 +105,8 @@ public class PDFASSigningImpl implements PDFASSigning { .equals(Connector.JKS)) { // Plain server based signatures!! response = PdfAsHelper.synchronousServerSignature( - request.getInputData(), request.getParameters()); + request.getInputData(), request.getParameters(), request.getSignatureBlockParameters()); + VerifyResult verifyResult = null; if (request.getVerificationLevel() != null && |