From 797634c687c6f44d314e4baa3fed220d142eed73 Mon Sep 17 00:00:00 2001 From: emusic Date: Mon, 14 May 2018 16:38:43 +0200 Subject: changes in pdf-as-lib --- .../gv/egiz/pdfas/web/config/WebConfiguration.java | 13 ++++++++ .../at/gv/egiz/pdfas/web/servlets/PDFData.java | 37 +++++++++++++++++++-- pdf-as-web/src/main/webapp/assets/img/localBKU.png | Bin 6650 -> 1750 bytes .../src/main/webapp/assets/img/mobileBKU.png | Bin 6269 -> 1811 bytes 4 files changed, 48 insertions(+), 2 deletions(-) (limited to 'pdf-as-web/src/main') diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java index 9b14df16..d63f698f 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java @@ -586,4 +586,17 @@ public class WebConfiguration implements IConfigurationConstants { } return ivalue; } + + + public static boolean isPdfProtected() + { + String value = properties.getProperty(DEFAULT_CONFIG_PROTECT_PDF); + if (value != null) { + if (value.equals("true")) { + return true; + } + } + return false; + } + } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java index abbfc639..4d3d1872 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java @@ -23,8 +23,11 @@ ******************************************************************************/ package at.gv.egiz.pdfas.web.servlets; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.SecureRandom; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -32,6 +35,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import at.gv.egiz.pdfas.web.config.WebConfiguration; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.encryption.AccessPermission; +import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,6 +95,31 @@ public class PDFData extends HttpServlet { if (signedData != null) { + /*if (WebConfiguration.isPdfProtected()) { + File tempFile = new File(System.getProperty("java.io.tmpdir"),"protect.pdf"); + FileUtils.writeByteArrayToFile(tempFile, signedData); + Path tempPath = tempFile.toPath(); + SecureRandom random = new SecureRandom(); + byte seed[] = random.generateSeed(50); + String ownerPassword = new String(seed, StandardCharsets.UTF_8); + PDDocument document = PDDocument.load(tempFile); + AccessPermission accessPermission = new AccessPermission(); + accessPermission.setCanExtractContent(false); + accessPermission.setCanExtractForAccessibility(true); + StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword, "", accessPermission); + spp.setEncryptionKeyLength(128); + spp.setPermissions(accessPermission); + document.protect(spp); + document.save(tempFile); + document.close(); + //accessPermission.setCanModify(false); + signedData = Files.readAllBytes(tempPath); + logger.info("Added Protection Parameters"); + if (tempFile.exists()) { + tempFile.delete(); + } + }*/ + if(WebConfiguration.isKeepSignedDocument()) { if(PdfAsHelper.isSignedDataExpired(request, response)) { logger.info("Destroying expired signed data in session"); diff --git a/pdf-as-web/src/main/webapp/assets/img/localBKU.png b/pdf-as-web/src/main/webapp/assets/img/localBKU.png index 2ec41892..cd5069b5 100644 Binary files a/pdf-as-web/src/main/webapp/assets/img/localBKU.png and b/pdf-as-web/src/main/webapp/assets/img/localBKU.png differ diff --git a/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png b/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png index daa8fa3f..037de1bb 100644 Binary files a/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png and b/pdf-as-web/src/main/webapp/assets/img/mobileBKU.png differ -- cgit v1.2.3