aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas
diff options
context:
space:
mode:
authoremusic <emina.music@egiz.gv.at>2018-05-14 16:38:43 +0200
committeremusic <emina.music@egiz.gv.at>2018-05-14 16:38:43 +0200
commit797634c687c6f44d314e4baa3fed220d142eed73 (patch)
tree56dc1ce81e81ff100261aa779a68dcbc61ecc0e5 /pdf-as-web/src/main/java/at/gv/egiz/pdfas
parent0a59371516348ba36163128060e02e997099fcbd (diff)
downloadpdf-as-4-797634c687c6f44d314e4baa3fed220d142eed73.tar.gz
pdf-as-4-797634c687c6f44d314e4baa3fed220d142eed73.tar.bz2
pdf-as-4-797634c687c6f44d314e4baa3fed220d142eed73.zip
changes in pdf-as-lib4.1.3
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java13
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java37
2 files changed, 48 insertions, 2 deletions
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");