diff options
author | tknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2008-06-12 08:19:49 +0000 |
---|---|---|
committer | tknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2008-06-12 08:19:49 +0000 |
commit | b5aefab37c25d5da114bb78768defc79fc709e29 (patch) | |
tree | 677e9b13167fd5087c4720218824abf06ac98847 /src | |
parent | 046cb5b235866e66ca9d2c55bd20ed7ec85ef12d (diff) | |
download | pdf-as-3-b5aefab37c25d5da114bb78768defc79fc709e29.tar.gz pdf-as-3-b5aefab37c25d5da114bb78768defc79fc709e29.tar.bz2 pdf-as-3-b5aefab37c25d5da114bb78768defc79fc709e29.zip |
A new check for the existence of a configuration has been implemented. The extraction is skipped if any files or folders would be overwritten. Files like log- or temp-files may exist and do not prevent the deployment of the default configuration.
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@283 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/gv/egiz/pdfas/test/APITest.java | 65 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/pdfas/test/JarExtractTest.java | 28 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java | 47 | ||||
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java | 2 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/web.xml | 2 | ||||
-rw-r--r-- | src/site/changes.xml | 4 |
6 files changed, 143 insertions, 5 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/test/APITest.java b/src/main/java/at/gv/egiz/pdfas/test/APITest.java new file mode 100644 index 0000000..9e52a41 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/test/APITest.java @@ -0,0 +1,65 @@ +package at.gv.egiz.pdfas.test;
+
+import java.io.File;
+import java.io.IOException;
+
+import at.gv.egiz.pdfas.PdfAsFactory;
+import at.gv.egiz.pdfas.api.PdfAs;
+import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.api.io.DataSource;
+import at.gv.egiz.pdfas.api.sign.SignParameters;
+import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning;
+import at.gv.egiz.pdfas.io.FileBasedDataSink;
+import at.gv.egiz.pdfas.io.FileBasedDataSource;
+
+public final class APITest {
+
+ private APITest() {
+ }
+
+ public static void main(String[] args) {
+ File configdir = new File("D:/downloads/testpdfas");
+ File unsignedFile = new File("./test-files/blindtext.pdf");
+ File signedFile = new File("d:/temp/blindtext_signed.pdf");
+ String signatureMode = Constants.SIGNATURE_TYPE_BINARY;
+ String signatureDevice = Constants.SIGNATURE_DEVICE_MOA;
+ String signatureProfile = "SIGNATURBLOCK_MINIMAL_DE";
+ SignaturePositioning signaturePos = null;
+
+ PdfAs pdfasAPI = null;
+
+ try {
+
+ // instantiate api
+ pdfasAPI = PdfAsFactory.createPdfAs(configdir);
+
+ // set source
+ DataSource dataSource = new FileBasedDataSource(unsignedFile, "application/pdf");
+
+ // set output
+ FileBasedDataSink dataSink = new FileBasedDataSink(signedFile);
+
+ // configure signature
+ SignParameters signParameters = new SignParameters();
+ signParameters.setDocument(dataSource);
+ signParameters.setOutput(dataSink);
+ signParameters.setSignatureType(signatureMode);
+ signParameters.setSignatureDevice(signatureDevice);
+ signParameters.setSignatureProfileId(signatureProfile);
+ signParameters.setSignaturePositioning(signaturePos);
+
+ // sign
+ pdfasAPI.sign(signParameters);
+
+ System.out.println("Successfully signed.");
+
+ } catch (PdfAsException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/test/JarExtractTest.java b/src/main/java/at/gv/egiz/pdfas/test/JarExtractTest.java new file mode 100644 index 0000000..e567452 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/test/JarExtractTest.java @@ -0,0 +1,28 @@ +package at.gv.egiz.pdfas.test;
+
+import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.utils.ConfigUtils;
+
+public final class JarExtractTest {
+
+ private JarExtractTest() {
+ }
+
+ public static void main(String[] args) {
+ try {
+
+ String sysProp = System.getProperty(Constants.CONFIG_DIR_SYSTEM_PROPERTY);
+ System.out.println("System property \"" + Constants.CONFIG_DIR_SYSTEM_PROPERTY + "\" = " + (sysProp != null ? ("\"" + sysProp + "\"") : null));
+
+ String deployedTo = ConfigUtils.deployDefaultConfiguration();
+ if (deployedTo != null) {
+ System.out.println("Configuration successfully deployed to \"" + deployedTo + "\".");
+ } else {
+ System.out.println("Configuration was NOT deployed. Maybe a configuration already exists.");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java index 627e611..a7bca3f 100644 --- a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java +++ b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java @@ -71,9 +71,11 @@ public final class ConfigUtils { */
private static boolean deployFromZIP(String destination, boolean overwriteExisting) throws ConfigUtilsException {
try {
- File destinationFolder = new File(destination);
- if (destinationFolder.exists() && !overwriteExisting) {
- return false;
+ if (!overwriteExisting) {
+ if (configurationAlreadyExists(destination)) {
+ logger_.debug("There is at least one file or folder that would be overwritten at destination path \"" + destination + "\". Skipping extraction.");
+ return false;
+ }
}
InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream(Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE);
if (in == null) {
@@ -81,6 +83,7 @@ public final class ConfigUtils { }
ZipInputStream zis = new ZipInputStream(in);
ZipEntry ze;
+ File destinationFolder = new File(destination);
destinationFolder.mkdirs();
logger_.debug("Extracting default configuration to folder \"" + destinationFolder.getCanonicalPath() + "\".");
while ((ze = zis.getNextEntry()) != null) {
@@ -102,6 +105,44 @@ public final class ConfigUtils { }
}
+ private static boolean configurationAlreadyExists(String destination) throws ConfigUtilsException, IOException {
+ logger_.debug("Checking configuration \"" + destination + "\" already exists (resp. if there are any directories or files that would be overwritten).");
+ File destinationFolder = new File(destination);
+ if (destinationFolder == null || !destinationFolder.exists()) {
+ return false;
+ }
+ InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream(Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE);
+ if (in == null) {
+ throw new ConfigUtilsException("Unable to find default configuration resource \"" + Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE + "\".");
+ }
+ ZipInputStream zis = new ZipInputStream(in);
+ ZipEntry ze;
+ while ((ze = zis.getNextEntry()) != null) {
+ if (ze.isDirectory()) {
+ File newFolder = new File(destinationFolder, ze.getName());
+ logger_.debug("Checking if folder \"" + newFolder.getPath() + "\" already exists.");
+ if (newFolder.exists()) {
+ logger_.debug("YES !");
+ return true;
+ } else {
+ logger_.debug("no");
+ }
+ } else {
+ File destFile = new File(destinationFolder, ze.getName());
+ logger_.trace("Checking if file \"" + destFile.getName() + "\" already exists.");
+ if (destFile.exists()) {
+ logger_.trace("YES !");
+ return true;
+ } else {
+ logger_.trace("no");
+ }
+ }
+ zis.closeEntry();
+ }
+ zis.close();
+ return false;
+ }
+
/**
* Deploys the default configuration to the given destination folder.
*
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index f6b74be..1b4a210 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -96,7 +96,7 @@ public abstract class PdfAS * The current version of the pdf-as library. This version string is logged on every invocation
* of the api or the web application.
*/
- public static final String PDFAS_VERSION = "3.0.5-20080611";
+ public static final String PDFAS_VERSION = "3.0.5-20080612";
/**
* The key of the strict mode setting.
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 6d675b4..2bcbdd2 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -127,7 +127,7 @@ </servlet-mapping>
<session-config>
- <session-timeout>30</session-timeout>
+ <session-timeout>10</session-timeout>
</session-config>
<welcome-file-list>
diff --git a/src/site/changes.xml b/src/site/changes.xml index fc2b488..dc2183b 100644 --- a/src/site/changes.xml +++ b/src/site/changes.xml @@ -13,6 +13,10 @@ </release>
-->
+ <release version="3.0.5" date="2008-06-12" description="subsequent release">
+ <action dev="tknall" type="update">A new check for the existence of a configuration has been implemented. The extraction is skipped if any files or folders would be overwritten. Files like log- or temp-files may exist and do not prevent the deployment of the default configuration.</action>
+ </release>
+
<release version="3.0.5" date="2008-06-11" description="subsequent release">
<action dev="tknall" type="fix">Serious bug solved. Method storeCertificate tried to fetch a certificate from store before storing it. If not found (within the store resp. via ldap) the certificate was not stored!!!</action>
</release>
|