aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java26
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java28
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VisBlockServlet.java94
-rw-r--r--pdf-as-web/src/main/resources/qualified.cerbin0 -> 1257 bytes
-rw-r--r--pdf-as-web/src/main/webapp/WEB-INF/web.xml10
5 files changed, 136 insertions, 22 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
index b0a81341..28bd9151 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
@@ -499,6 +499,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
requestedSignature.setCertificate(cert);
if (!requestedSignature.isVisual()) {
+ logger.warn("Profile is invisible so not block image is generated");
return null;
}
@@ -511,9 +512,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
baos.close();
pdfObject.setOriginalDocument(baos.toByteArray());
-
-
-
+
SignatureProfileSettings signatureProfileSettings = TableFactory
.createProfile(requestedSignature.getSignatureProfileID(),
pdfObject.getStatus().getSettings());
@@ -556,7 +555,6 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
requestedSignature.setSignaturePosition(position);
-
PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties(
pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject,
positioningInstruction);
@@ -569,13 +567,6 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
PDPage firstPage = pages.get(0);
- //BufferedImage outputImage = new BufferedImage(
- // (int)Math.ceil(pageable.getPageFormat(position.getPage()-1).getImageableWidth()),
- // (int)Math.ceil(pageable.getPageFormat(position.getPage()-1).getImageableHeight()),
- // BufferedImage.TYPE_4BYTE_ABGR);
-
- //pageable.print(outputImage.getGraphics(), pageable.getPageFormat(position.getPage()-1), position.getPage()-1);
-
float stdRes = 72;
float targetRes = resolution;
float factor = targetRes / stdRes;
@@ -587,17 +578,6 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
Graphics2D graphics = (Graphics2D) cutOut.getGraphics();
- //float srcy_tmp = (float) ((position.getHeight() + position.getY()) - pageable.getPageFormat(position.getPage()-1).getImageableHeight());
-
- //int srcy1 = (int)(Math.floor(srcy_tmp));
- //int srcy2 = (int)(srcy1 + position.getHeight());
-
- /*logger.debug("Draw Image: SRC {} {} {} {}", 0, 0,cutOut.getWidth(), cutOut.getHeight() );
- logger.debug("Draw Image: DST {} {} {} {}", (int)position.getX(), srcy1, (int)(position.getX() + position.getWidth()),
- srcy2 );*/
- //ImageIO.write(outputImage, "png", new File("/tmp/test.png"));
- //logger.debug("Sig Position: {} {} {} {}", position.getX(), position.getY(), position.getWidth(), position.getHeight());
-
graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut.getHeight(),
(int)(1 * factor),
(int)(outputImage.getHeight() - ((position.getHeight() + 1) * factor)),
@@ -606,8 +586,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
null);
return cutOut;
} catch(PdfAsException e) {
+ logger.error("PDF-AS Exception", e);
throw e;
} catch(Throwable e) {
+ logger.error("Throwable Exception", e);
throw new PdfAsException("", e);
}
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 85a36e17..041c7df3 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
@@ -23,13 +23,21 @@
******************************************************************************/
package at.gv.egiz.pdfas.web.helper;
+import iaik.x509.X509Certificate;
+
+import java.awt.Image;
+import java.awt.image.RenderedImage;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.security.cert.CertificateException;
import java.util.Iterator;
import java.util.List;
+import javax.imageio.ImageIO;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -45,6 +53,7 @@ import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.api.ws.PDFASSignParameters;
import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.lib.api.ByteArrayDataSink;
import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource;
import at.gv.egiz.pdfas.lib.api.Configuration;
@@ -468,6 +477,25 @@ public class PdfAsHelper {
return data;
}
+ public static byte[] generateVisualBlock(String profile, int resolution) throws IOException, CertificateException, PdfAsException {
+ X509Certificate cert = new X509Certificate(PdfAsHelper.class.getResourceAsStream("/qualified.cer"));
+ Configuration config = pdfAs.getConfiguration();
+ SignParameter parameter = PdfAsFactory.createSignParameter(
+ config, null);
+ parameter.setSignatureProfileId(profile);
+ Image img = pdfAs.generateVisibleSignaturePreview(parameter,
+ cert, resolution);
+
+ if(img == null) {
+ return null;
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ImageIO.write((RenderedImage) img, "png", baos);
+ baos.close();
+ return baos.toByteArray();
+ }
+
public static void injectCertificate(HttpServletRequest request,
HttpServletResponse response,
InfoboxReadResponseType infoboxReadResponseType,
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VisBlockServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VisBlockServlet.java
new file mode 100644
index 00000000..3008c25e
--- /dev/null
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VisBlockServlet.java
@@ -0,0 +1,94 @@
+package at.gv.egiz.pdfas.web.servlets;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.security.cert.CertificateException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
+
+public class VisBlockServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(VisBlockServlet.class);
+
+ private static String PARAM_PROFILE = "p";
+ private static String PARAM_RESOLUTION = "r";
+
+ /**
+ * @see HttpServlet#HttpServlet()
+ */
+ public VisBlockServlet() {
+ super();
+ }
+
+ /**
+ * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
+ * response)
+ */
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+ this.process(request, response);
+ }
+
+ /**
+ * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
+ * response)
+ */
+ protected void doPost(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+ this.process(request, response);
+ }
+
+ protected void process(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+
+ try {
+
+ String profile = request.getParameter(PARAM_PROFILE);
+ String resolutionString = request.getParameter(PARAM_RESOLUTION);
+
+ int resolution = Integer.parseInt(resolutionString);
+
+ if (resolution < 16 || resolution > 512) {
+ throw new ServletException(PARAM_RESOLUTION
+ + " invalid value! Out of Range");
+ }
+
+ byte[] imageData = PdfAsHelper.generateVisualBlock(profile, resolution);
+
+ if (imageData != null) {
+
+ response.setHeader("Content-Disposition", "inline;filename="
+ + profile + "_" + resolution + ".png");
+ response.setContentType("image/png");
+ OutputStream os = response.getOutputStream();
+ os.write(imageData);
+ os.close();
+ } else {
+ logger.warn("generateVisualBlock returned null!");
+ throw new ServletException("Invalid profile id");
+ }
+ } catch (NumberFormatException e) {
+ throw new ServletException(PARAM_RESOLUTION
+ + " invalid value! Not a Number");
+ } catch (CertificateException e) {
+ logger.error("CERT Error", e);
+ throw new ServletException("Failed to find certificate");
+ } catch (PdfAsException e) {
+ logger.error("PDF_AS Error", e);
+ throw new ServletException("Generic Error");
+ }
+ }
+
+}
diff --git a/pdf-as-web/src/main/resources/qualified.cer b/pdf-as-web/src/main/resources/qualified.cer
new file mode 100644
index 00000000..b448abfb
--- /dev/null
+++ b/pdf-as-web/src/main/resources/qualified.cer
Binary files differ
diff --git a/pdf-as-web/src/main/webapp/WEB-INF/web.xml b/pdf-as-web/src/main/webapp/WEB-INF/web.xml
index 8373c195..0648ece4 100644
--- a/pdf-as-web/src/main/webapp/WEB-INF/web.xml
+++ b/pdf-as-web/src/main/webapp/WEB-INF/web.xml
@@ -59,6 +59,12 @@
<servlet-class>at.gv.egiz.pdfas.web.servlets.DataURLServlet</servlet-class>
</servlet>
<servlet>
+ <servlet-name>VisBlockServlet</servlet-name>
+ <display-name>VisBlockServlet</display-name>
+ <description></description>
+ <servlet-class>at.gv.egiz.pdfas.web.servlets.VisBlockServlet</servlet-class>
+ </servlet>
+ <servlet>
<servlet-name>VerifyServlet</servlet-name>
<display-name>VerifyServlet</display-name>
<description></description>
@@ -113,6 +119,10 @@
<url-pattern>/Sign</url-pattern>
</servlet-mapping>
<servlet-mapping>
+ <servlet-name>VisBlockServlet</servlet-name>
+ <url-pattern>/visblock</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
<servlet-name>ProvidePDF</servlet-name>
<url-pattern>/ProvidePDF</url-pattern>
</servlet-mapping>