diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-16 09:43:49 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-16 09:43:49 +0200 |
commit | 3c4eac027bfd68bfce63a2eed010ccc2b7310802 (patch) | |
tree | 507f8586045b57e4457da23ce7aedca6a497a913 /pdf-as-web/src/main/java/at/gv | |
parent | 00894355450179bea4b56e0abcf16243964ff286 (diff) | |
download | pdf-as-4-3c4eac027bfd68bfce63a2eed010ccc2b7310802.tar.gz pdf-as-4-3c4eac027bfd68bfce63a2eed010ccc2b7310802.tar.bz2 pdf-as-4-3c4eac027bfd68bfce63a2eed010ccc2b7310802.zip |
PreProcessor Interface added and API rebuild
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv')
7 files changed, 61 insertions, 12 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 3323a252..fc499f94 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 @@ -35,6 +35,7 @@ import java.net.URLEncoder; import java.security.cert.CertificateException; import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.imageio.ImageIO; import javax.servlet.RequestDispatcher; @@ -298,7 +299,7 @@ public class PdfAsHelper { } public static List<VerifyResult> synchornousVerify(byte[] pdfData, - int signIdx, SignatureVerificationLevel lvl) throws Exception { + int signIdx, SignatureVerificationLevel lvl, Map<String, String> preProcessor) throws Exception { logger.debug("Verifing Signature index: " + signIdx); Configuration config = pdfAs.getConfiguration(); @@ -308,6 +309,7 @@ public class PdfAsHelper { VerifyParameter verifyParameter = PdfAsFactory.createVerifyParameter( config, dataSource); + verifyParameter.setPreprocessorArguments(preProcessor); verifyParameter.setSignatureVerificationLevel(lvl); verifyParameter.setDataSource(dataSource); verifyParameter.setConfiguration(config); @@ -425,6 +427,11 @@ public class PdfAsHelper { // set Signature Position signParameter.setSignaturePosition(params.getPosition()); + // Set Preprocessor + if(params.getPreprocessor() != null) { + signParameter.setPreprocessorArguments(params.getPreprocessor().getMap()); + } + SignResult signResult = pdfAs.sign(signParameter); PDFASSignResponse signResponse = new PDFASSignResponse(); @@ -444,7 +451,7 @@ public class PdfAsHelper { public static void startSignature(HttpServletRequest request, HttpServletResponse response, ServletContext context, byte[] pdfData, String connector, String position, - String transactionId, String profile) throws Exception { + String transactionId, String profile, Map<String, String> preProcessor) throws Exception { // TODO: Protect session so that only one PDF can be signed during one // session @@ -483,7 +490,7 @@ public class PdfAsHelper { throw new PdfAsWebException( "Invalid connector (bku | onlinebku | mobilebku | moa | jks)"); } - + signParameter.setPreprocessorArguments(preProcessor); signParameter.setPlainSigner(signer); session.setAttribute(PDF_SIGNER, signer); session.setAttribute(PDF_SL_INTERACTIVE, connector); @@ -677,7 +684,7 @@ public class PdfAsHelper { PDFASVerificationResponse verResponse = new PDFASVerificationResponse(); List<VerifyResult> verResults = PdfAsHelper.synchornousVerify( signedPdf, -2, - PdfAsHelper.getVerificationLevel(request)); + PdfAsHelper.getVerificationLevel(request), null); if (verResults.size() != 1) { throw new WebServiceException( diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java index c8f35f3c..9c5f8cc6 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java @@ -23,6 +23,10 @@ ******************************************************************************/ package at.gv.egiz.pdfas.web.helper; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + import javax.servlet.http.HttpServletRequest; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel; @@ -63,6 +67,8 @@ public class PdfAsParameterExtractor { public static final String PARAM_SIG_IDX = "sig-idx"; public static final String PARAM_FILENAME = "filename"; + public static final String PARAM_PREPROCESSOR_PREFIX = "pp:"; + public static String getConnector(HttpServletRequest request) { String connector = (String)request.getAttribute(PARAM_CONNECTOR); if(connector != null) { @@ -85,6 +91,22 @@ public class PdfAsParameterExtractor { return (String)request.getAttribute(PARAM_INVOKE_URL); } + public static Map<String, String> getPreProcessorMap(HttpServletRequest request) { + Map<String, String> map = new HashMap<String, String>(); + + Enumeration<String> parameterNames = request.getAttributeNames(); + while(parameterNames.hasMoreElements()) { + String parameterName = parameterNames.nextElement(); + if(parameterName.startsWith(PARAM_PREPROCESSOR_PREFIX)) { + String key = parameterName.substring(PARAM_PREPROCESSOR_PREFIX.length()); + String value = (String)request.getAttribute(parameterName); + map.put(key, value); + } + } + + return map; + } + public static SignatureVerificationLevel getVerificationLevel(HttpServletRequest request) { String value = (String)request.getAttribute(PARAM_VERIFY_LEVEL); if(value != null) { 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 ce19f803..7900dfde 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 @@ -302,7 +302,7 @@ public class ExternSignServlet extends HttpServlet { PdfAsHelper.startSignature(request, response, getServletContext(), pdfData, connector, PdfAsHelper.buildPosString(request, response), transactionId, PdfAsParameterExtractor - .getSigType(request)); + .getSigType(request), PdfAsParameterExtractor.getPreProcessorMap(request)); return; } else if (connector.equals("jks") || connector.equals("moa")) { // start synchronous siganture creation 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 544f6c83..e602a8e0 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 @@ -24,6 +24,7 @@ package at.gv.egiz.pdfas.web.servlets; import java.io.IOException; +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -147,12 +148,17 @@ public class UIEntryPointServlet extends HttpServlet { "Invalid connector mobilebku is not supported"); } } - + Map<String, String> map = null; + if(pdfAsRequest.getParameters().getPreprocessor() != null) { + map = pdfAsRequest.getParameters().getPreprocessor().getMap(); + } + PdfAsHelper.startSignature(req, resp, getServletContext(), pdfAsRequest.getInputData(), connector.toString(), pdfAsRequest.getParameters().getPosition(), pdfAsRequest.getParameters().getTransactionId(), - pdfAsRequest.getParameters().getProfile()); + pdfAsRequest.getParameters().getProfile(), + map); } else { throw new PdfAsWebException("Invalid connector (" + Connector.BKU + " | " + Connector.ONLINEBKU + " | " diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java index 09af4357..aaa6afbb 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java @@ -254,7 +254,8 @@ public class VerifyServlet extends HttpServlet { logger.debug("Format: " + format); - List<VerifyResult> results = PdfAsHelper.synchornousVerify(pdfData, -1, lvl); + List<VerifyResult> results = PdfAsHelper.synchornousVerify(pdfData, -1, lvl, + PdfAsParameterExtractor.getPreProcessorMap(request)); PdfAsHelper.setVerificationResult(request, results); 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 6df63a3b..d15492b4 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 @@ -25,6 +25,7 @@ package at.gv.egiz.pdfas.web.ws; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.jws.WebService; import javax.xml.ws.WebServiceException; @@ -39,7 +40,6 @@ import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; import at.gv.egiz.pdfas.api.ws.PDFASSignResponse; import at.gv.egiz.pdfas.api.ws.PDFASSigning; -import at.gv.egiz.pdfas.api.ws.PDFASVerificationResponse; import at.gv.egiz.pdfas.api.ws.VerificationLevel; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; @@ -79,6 +79,11 @@ public class PDFASSigningImpl implements PDFASSigning { "Invalid connector value!"); } + Map<String, String> preProcessor = null; + if(request.getParameters().getPreprocessor() != null) { + preProcessor = request.getParameters().getPreprocessor().getMap(); + } + if (request.getParameters().getConnector().equals(Connector.MOA) || request.getParameters().getConnector() .equals(Connector.JKS)) { @@ -94,7 +99,8 @@ public class PDFASSigningImpl implements PDFASSigning { .synchornousVerify( response.getSignedPDF(), -1, - SignatureVerificationLevel.FULL_VERIFICATION); + SignatureVerificationLevel.FULL_VERIFICATION, + preProcessor); if (verResults.size() != 1) { throw new WebServiceException( @@ -106,7 +112,8 @@ public class PDFASSigningImpl implements PDFASSigning { .synchornousVerify( response.getSignedPDF(), -1, - SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION); + SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION, + preProcessor); if (verResults.size() != 1) { throw new WebServiceException( diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java index c6fb8cd7..0257f835 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASVerificationImpl.java @@ -4,6 +4,7 @@ import iaik.x509.X509Certificate; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.jws.WebService; import javax.xml.ws.WebServiceException; @@ -44,6 +45,11 @@ public class PDFASVerificationImpl implements PDFASVerification { sigIdx = request.getSignatureIndex().intValue(); } + Map<String, String> preProcessor = null; + if(request.getPreprocessor() != null) { + preProcessor = request.getPreprocessor().getMap(); + } + SignatureVerificationLevel lvl = SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION; if (request.getVerificationLevel().equals( @@ -55,7 +61,7 @@ public class PDFASVerificationImpl implements PDFASVerification { } List<VerifyResult> results = PdfAsHelper.synchornousVerify( - request.getInputData(), sigIdx, lvl); + request.getInputData(), sigIdx, lvl, preProcessor); for(int i = 0; i < results.size(); i++) { VerifyResult result = results.get(i); |