aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web/src/main/java/at')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java47
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java7
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/QRCodeGenerator.java28
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java3
4 files changed, 82 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);