diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-02-25 11:47:07 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-02-25 11:47:07 +0100 |
commit | de87f168478445ffb2b018804ea46a834dffcfbf (patch) | |
tree | b32ae132e6659db1547dbd4af448217b9810a1f6 /pdf-as-web/src | |
parent | e3f2e6dd9bc750b279c28ecc4d026680dc17687b (diff) | |
download | pdf-as-4-de87f168478445ffb2b018804ea46a834dffcfbf.tar.gz pdf-as-4-de87f168478445ffb2b018804ea46a834dffcfbf.tar.bz2 pdf-as-4-de87f168478445ffb2b018804ea46a834dffcfbf.zip |
Added QR Code Content Parameter for PDF-As
Diffstat (limited to 'pdf-as-web/src')
5 files changed, 159 insertions, 3 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 5f8bfdcb..1869dbb5 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 @@ -49,6 +49,7 @@ import javax.xml.ws.WebServiceException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,6 +115,7 @@ public class PdfAsHelper { private static final String SIGNATURE_DATA_HASH = "SIGNATURE_DATA_HASH"; private static final String SIGNATURE_ACTIVE = "SIGNATURE_ACTIVE"; private static final String VERIFICATION_RESULT = "VERIFICATION_RESULT"; + private static final String QRCODE_CONTENT = "QR_CONT"; private static final Logger logger = LoggerFactory .getLogger(PdfAsHelper.class); @@ -357,7 +359,7 @@ public class PdfAsHelper { validatePdfSize(request, response, pdfData); Configuration config = pdfAs.getConfiguration(); - + ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Generate Sign Parameter @@ -426,9 +428,34 @@ public class PdfAsHelper { signParameter.setPlainSigner(signer); + String profileId = PdfAsParameterExtractor + .getSigType(request); + String qrCodeContent = PdfAsHelper.getQRCodeContent(request); + + if(qrCodeContent != null) { + if(profileId == null) { + // get default Profile + profileId = config.getValue("sig_obj.type.default"); + } + + if(profileId == null) { + logger.warn("Failed to determine default profile! Using hard coded!"); + profileId = "SIGNATURBLOCK_SMALL_DE"; + } + + ByteArrayOutputStream qrbaos = new ByteArrayOutputStream(); + try { + String key = "sig_obj." + profileId + ".value.SIG_LABEL"; + QRCodeGenerator.generateQRCode(qrCodeContent, qrbaos, 200); + String value = Base64.encodeBase64String(qrbaos.toByteArray()); + config.setValue(key, value); + } finally { + IOUtils.closeQuietly(qrbaos); + } + } + // set Signature Profile (null use default ...) - signParameter.setSignatureProfileId(PdfAsParameterExtractor - .getSigType(request)); + signParameter.setSignatureProfileId(profileId); // set Signature Position signParameter.setSignaturePosition(buildPosString(request, response)); @@ -1109,6 +1136,20 @@ public class PdfAsHelper { } return ""; } + + public static void setQRCodeContent(HttpServletRequest request, String value) { + HttpSession session = request.getSession(); + session.setAttribute(QRCODE_CONTENT, value); + } + + public static String getQRCodeContent(HttpServletRequest request) { + HttpSession session = request.getSession(); + Object obj = session.getAttribute(QRCODE_CONTENT); + if (obj != null) { + return obj.toString(); + } + return null; + } public static void setPDFFileName(HttpServletRequest request, String value) { HttpSession session = request.getSession(); 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 1737a2d1..3c7da05a 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 @@ -69,6 +69,8 @@ public class PdfAsParameterExtractor { public static final String PARAM_FILENAME = "filename"; public static final String PARAM_ORIGINAL_DIGEST = "origdigest"; public static final String PARAM_PREPROCESSOR_PREFIX = "pp:"; + public static final String PARAM_QRCODE_CONTENT = "qrcontent"; + public static String getConnector(HttpServletRequest request) { String connector = (String)request.getAttribute(PARAM_CONNECTOR); @@ -78,6 +80,11 @@ public class PdfAsParameterExtractor { return PARAM_CONNECTOR_DEFAULT; } + public static String getQRCodeContent(HttpServletRequest request) { + String qrcodeContent = (String)request.getAttribute(PARAM_QRCODE_CONTENT); + return qrcodeContent; + } + public static String getTransactionId(HttpServletRequest request) { String transactionId = (String)request.getAttribute(PARAM_TRANSACTION_ID); return transactionId; diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/QRCodeGenerator.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/QRCodeGenerator.java new file mode 100644 index 00000000..4f7dd632 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/QRCodeGenerator.java @@ -0,0 +1,28 @@ +package at.gv.egiz.pdfas.web.helper; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Hashtable; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +public class QRCodeGenerator { + + public static void generateQRCode(String content, OutputStream out, int size) + throws WriterException, IOException { + Hashtable hintMap = new Hashtable(); + hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); + QRCodeWriter qrCodeWriter = new QRCodeWriter(); + BitMatrix byteMatrix = qrCodeWriter.encode(content, + BarcodeFormat.QR_CODE, size, size, hintMap); + + MatrixToImageWriter.writeToStream(byteMatrix, "PNG", out); + } + +} 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 bd0bd935..32a60093 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 @@ -305,6 +305,9 @@ public class ExternSignServlet extends HttpServlet { SignatureVerificationLevel lvl = PdfAsParameterExtractor.getVerificationLevel(request); PdfAsHelper.setVerificationLevel(request, lvl); + String qrcodeContent = PdfAsParameterExtractor.getQRCodeContent(request); + PdfAsHelper.setQRCodeContent(request, qrcodeContent); + String invokeTarget = PdfAsParameterExtractor.getInvokeTarget(request); PdfAsHelper.setInvokeTarget(request, response, invokeTarget); diff --git a/pdf-as-web/src/main/webapp/testindex.jsp b/pdf-as-web/src/main/webapp/testindex.jsp new file mode 100644 index 00000000..8d49caeb --- /dev/null +++ b/pdf-as-web/src/main/webapp/testindex.jsp @@ -0,0 +1,77 @@ +<%@page import="at.gv.egiz.pdfas.web.config.WebConfiguration"%> +<%@page import="at.gv.egiz.pdfas.web.helper.PdfAsHelper"%> +<html> +<head> +<title>PDF-Signatur</title> +</head> +<body> + <form action="Sign" method="POST" + enctype="multipart/form-data"> + <input type="hidden" name="source" id="source" value="internal" /> + <input type="file" name="pdf-file" id="pdf-file" accept="application/pdf"> + <% + if (request.getAttribute("FILEERR") != null) { + %> + <p>Bitte die zu signierende PDF Datei angeben.</p> + <% + } + %> + + + <% + if (WebConfiguration.getLocalBKUURL() != null) { + %> + <img src="assets/img/onlineBKU.png" /> <button type="submit" + value="bku" name="connector" id="bku">Lokale BKU + </button> + <% + } + %> + <% + if (WebConfiguration.getOnlineBKUURL() != null) { + %> + <img src="assets/img/onlineBKU.png" /> + <button type="submit" value="onlinebku" name="connector" + id="onlinebku">Online BKU</button> + <% + } + %> + <% + if (WebConfiguration.getHandyBKUURL() != null) { + %> + <img src="assets/img/mobileBKU.png" /> + <button type="submit" value="mobilebku" name="connector" id="mobilebku">Handy</button> + <% + } + %> + <% + if (WebConfiguration.getKeystoreDefaultEnabled()) { + %> + <button type="submit" value="jks" name="connector" + id="jks">Server Keystore</button> + <% + } + %> + <% + if (WebConfiguration.getMOASSEnabled()) { + %> + <button type="submit" value="moa" name="connector" + id="moa">MOA-SS</button> + <% + } + %> + <p> + <select name="locale" id="locale" size="3"> + <option>EN</option> + <option>DE</option> + </select> + </p> + <p> + <label for="qrcontent">Content of QR Image:</label> + <input type="text" name="qrcontent" id="qrcontent" /> + </p> + </form> + + <p><small>Version: <%= PdfAsHelper.getVersion() %> - <%= PdfAsHelper.getSCMRevision() %></small></p> +</body> +</html>
\ No newline at end of file |