aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-lib')
-rw-r--r--pdf-as-lib/build.gradle56
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java3
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java16
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java6
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java27
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java4
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java63
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateAndRequestParameterResolver.java99
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateResolver.java17
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java38
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java14
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java22
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java6
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java7
-rw-r--r--pdf-as-lib/src/main/resources/config/config.zipbin1277320 -> 1277320 bytes
-rw-r--r--pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java51
16 files changed, 388 insertions, 41 deletions
diff --git a/pdf-as-lib/build.gradle b/pdf-as-lib/build.gradle
index 1ddc1f9a..634d7df4 100644
--- a/pdf-as-lib/build.gradle
+++ b/pdf-as-lib/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'java'
+apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'java-library-distribution'
@@ -13,7 +13,8 @@ buildscript {
mavenLocal()
mavenCentral()
}
- dependencies { classpath("commons-io:commons-io:2.4") }
+ dependencies { classpath("commons-io:commons-io:2.8.0") }
+
}
sourceSets {
@@ -22,6 +23,11 @@ sourceSets {
srcDirs = [ 'src/main/java', 'src/generated/java' ]
}
}
+ test {
+ java {
+ srcDirs = ["src/test/java"]
+ }
+ }
}
configurations {
@@ -41,6 +47,7 @@ project.ext {
task createConf(type: Zip, dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME) {
from 'src/configuration'
+ //archiveBaseName 'config'
archiveName 'config.zip'
destinationDir new File(projectDir, 'src/main/resources/config')
}
@@ -54,29 +61,30 @@ repositories {
}
dependencies {
- compile project (':pdf-as-common')
- compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
- compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.12'
- compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
- compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.65'
- compile group: 'javax.activation', name: 'activation', version: '1.1.1'
- compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
- compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
- compile group: 'org.bitbucket.b_c', name: 'jose4j', version: '0.7.0'
- compile group: 'commons-io', name: 'commons-io', version: '2.6'
- compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3'
- compile 'org.apache.commons:commons-collections4:4.4'
- compile group: 'ognl', name: 'ognl', version: '3.0.8'
- compile files('libs/iaik_eccelerate_cms.jar')
- compile files('libs/iaik_eccelerate.jar')
- compile files('libs/iaik_jce_full.jar')
- compile files('libs/iaik_cms.jar')
- compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
- compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: slf4jVersion
+ api project (':pdf-as-common')
+ api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
+ api group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.13'
+ api group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
+ api group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.68'
+ api group: 'javax.activation', name: 'activation', version: '1.1.1'
+ api group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
+ api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
+ api group: 'org.bitbucket.b_c', name: 'jose4j', version: '0.7.6'
+ api group: 'commons-io', name: 'commons-io', version: '2.8'
+ api group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3'
+ api 'org.apache.commons:commons-collections4:4.4'
+ api group: 'ognl', name: 'ognl', version: '3.2.19'
+ api files('libs/iaik_eccelerate_cms.jar')
+ api files('libs/iaik_eccelerate.jar')
+ api files('libs/iaik_jce_full.jar')
+ api files('libs/iaik_cms.jar')
+ api group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
+ api group: 'org.slf4j', name: 'jcl-over-slf4j', version: slf4jVersion
- compile group: 'com.google.zxing', name: 'core', version: '3.2.0'
- compile group: 'com.google.zxing', name: 'javase', version: '3.2.0'
- testCompile group: 'junit', name: 'junit', version: '4.+'
+ api group: 'com.google.zxing', name: 'core', version: '3.4.1'
+ api group: 'com.google.zxing', name: 'javase', version: '3.4.1'
+ testImplementation group: 'junit', name: 'junit', version: '4.+'
+ testCompile "junit:junit:4.11"
ws group: 'org.apache.cxf', name: 'cxf-tools', version: cxfVersion
ws group: 'org.apache.cxf', name: 'cxf-tools-wsdlto-databinding-jaxb', version: cxfVersion
ws group: 'org.apache.cxf', name: 'cxf-tools-wsdlto-frontend-jaxws', version: cxfVersion
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
index 610f5eba..4d6cef47 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
@@ -113,6 +113,9 @@ public interface IConfigurationConstants {
public static final String BG_COLOR_DETECTION = "sigblock.placement.bgcolor.detection.enabled";
public static final String SIG_PLACEMENT_DEBUG_OUTPUT = "sigblock.placement.debug.file";
+ public static final String SIG_BLOCK_PARAMETER_KEY_REGEX = "sigblockparameter.key.regex";
+ public static final String SIG_BLOCK_PARAMETER_VALUE_REGEX = "sigblockparameter.value.regex";
+
/**
* PADES Constants
*/
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java
index c2368255..5a646505 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java
@@ -23,6 +23,8 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.api;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+
import java.util.Map;
import javax.activation.DataSource;
@@ -80,4 +82,18 @@ public interface PdfAsParameter {
* @param map the map
*/
public void setPreprocessorArguments(Map<String, String> map);
+
+ /**
+ * Sets the dynamic signature-block values.
+ *
+ * @param map the map
+ */
+ public void setDynamicSignatureBlockArguments(Map<String, String> map) throws PdfAsException;
+
+ /**
+ * Gets the dynamic signature-block values.
+ *
+ * @return the dynamic signature-block values
+ */
+ public Map<String, String> getDynamicSignatureBlockArguments();
}
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 324712cb..bca1ff2b 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
@@ -23,6 +23,7 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl;
+import at.gv.egiz.pdfas.lib.impl.status.PDFObject;
import iaik.x509.X509Certificate;
import java.awt.Image;
@@ -144,7 +145,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants,
IPdfSigner signer = backend.getPdfSigner();
- status.setPdfObject(signer.buildPDFObject(status));
+
+ PDFObject pdfObject = signer.buildPDFObject(status);
+
+ status.setPdfObject(pdfObject);
// set Original PDF Document Data
status.getPdfObject()
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
index fb737c13..1929f95e 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
@@ -23,11 +23,16 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import javax.activation.DataSource;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.common.utils.CheckSignatureBlockParameters;
import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.IConfigurationConstants;
import at.gv.egiz.pdfas.lib.api.PdfAsParameter;
public class PdfAsParameterImpl implements PdfAsParameter {
@@ -36,7 +41,7 @@ protected Configuration configuration;
protected DataSource dataSource;
protected String transactionId;
protected Map<String, String> preProcessorProps;
-
+ protected Map<String, String> dynamicSignatureBlockArgumentsMap;
public PdfAsParameterImpl(Configuration configuration,
DataSource dataSource) {
this.configuration = configuration;
@@ -77,4 +82,24 @@ protected Configuration configuration;
public void setPreprocessorArguments(Map<String, String> map) {
this.preProcessorProps = map;
}
+
+ @Override
+ public void setDynamicSignatureBlockArguments(Map<String, String> map) throws PdfAsException {
+ if(map == null)
+ map = new HashMap<String, String>();
+ Map<String, String> tmpMap = Collections.unmodifiableMap(map);
+ String keyRegex = configuration.getValue(IConfigurationConstants.SIG_BLOCK_PARAMETER_KEY_REGEX);
+ String valueRegex = configuration.getValue(IConfigurationConstants.SIG_BLOCK_PARAMETER_VALUE_REGEX);
+ if( CheckSignatureBlockParameters.checkSignatureBlockParameterMapIsValid(tmpMap, keyRegex, valueRegex) == true) {
+ this.dynamicSignatureBlockArgumentsMap = tmpMap;
+ }else{
+ throw new PdfAsException("error.invalid.signature.parameter.01");
+ }
+
+ }
+
+ @Override
+ public Map<String, String> getDynamicSignatureBlockArguments() {
+ return this.dynamicSignatureBlockArgumentsMap;
+ }
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java
index 4c352b90..0a55b834 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractor.java
@@ -3,6 +3,10 @@ package at.gv.egiz.pdfas.lib.impl.placeholder;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.lib.impl.status.PDFObject;
+import java.util.List;
+
public interface PlaceholderExtractor {
SignaturePlaceholderData extract(PDFObject doc, String placeholderId, int matchMode) throws PdfAsException;
+
+ List<SignaturePlaceholderData> extractList(PDFObject pdfObject, String placeholderID, int placeholderMode) throws PdfAsException;
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java
index 500b9e24..99c09295 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java
@@ -24,6 +24,7 @@
package at.gv.egiz.pdfas.lib.impl.placeholder;
import java.io.IOException;
+import java.util.List;
import at.gv.egiz.pdfas.common.exceptions.PDFASError;
import at.gv.egiz.pdfas.common.exceptions.PdfAsErrorCarrier;
@@ -102,4 +103,66 @@ public class PlaceholderFilter implements IConfigurationConstants,
return null;
}
+ public static List<SignaturePlaceholderData> checkPlaceholderSignatureLocationList(OperationStatus status, ISettings settings, String signatureLocation) throws PdfAsException,
+ IOException {
+ String placeholderID;
+
+ if (status.getPlaceholderConfiguration().isGlobalPlaceholderEnabled()) {
+ PlaceholderExtractor extractor = status.getBackend().getPlaceholderExtractor();
+
+ if(StringUtils.isNotEmpty(signatureLocation)) {
+ placeholderID = signatureLocation;
+ } else {
+ placeholderID = PlaceholderWebConfiguration.getValue(PLACEHOLDER_WEB_ID);
+ if(StringUtils.isEmpty(placeholderID)) {
+ placeholderID = settings.getValue(PLACEHOLDER_ID);
+ }
+ }
+
+ String placeholderModeString = settings.getValue(PLACEHOLDER_MODE);
+ int placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE;
+ if (StringUtils.isNotEmpty(placeholderModeString)) {
+ try {
+ placeholderMode = Integer.parseInt(placeholderModeString);
+ if (placeholderMode < PLACEHOLDER_MODE_MIN
+ || placeholderMode > PLACEHOLDER_MODE_MAX) {
+ throw new PdfAsErrorCarrier(new PDFASError(
+ PDFASError.ERROR_INVALID_PLACEHOLDER_MODE));
+ }
+ } catch (NumberFormatException e) {
+ throw new PdfAsErrorCarrier(new PDFASError(
+ PDFASError.ERROR_INVALID_PLACEHOLDER_MODE, e));
+ }
+ }
+ return extractor.extractList(status.getPdfObject(), placeholderID,
+ placeholderMode);
+
+ } else if (status.getPlaceholderConfiguration().isProfileConfigurationEnabled(status.getRequestedSignature().getSignatureProfileID())) {
+ //filter for local placeholder in selected profiles
+ PlaceholderExtractor extractor = status.getBackend().getPlaceholderExtractor();
+ int placeholderMode = PLACEHOLDER_MATCH_MODE_SORTED;
+
+ placeholderID = status.getPlaceholderConfiguration().getProfilePlaceholderID(status.getRequestedSignature().getSignatureProfileID());
+ if(StringUtils.isNotEmpty(placeholderID)) {
+ placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE;
+ }
+ String placeholderModeString = settings.getValue(PLACEHOLDER_MODE);
+ if (StringUtils.isNotEmpty(placeholderModeString)) {
+ try {
+ placeholderMode = Integer.parseInt(placeholderModeString);
+ if (placeholderMode < PLACEHOLDER_MODE_MIN
+ || placeholderMode > PLACEHOLDER_MODE_MAX) {
+ throw new PdfAsErrorCarrier(new PDFASError(
+ PDFASError.ERROR_INVALID_PLACEHOLDER_MODE));
+ }
+ } catch (NumberFormatException e) {
+ throw new PdfAsErrorCarrier(new PDFASError(
+ PDFASError.ERROR_INVALID_PLACEHOLDER_MODE, e));
+ }
+ }
+ return extractor.extractList(status.getPdfObject(), placeholderID,
+ placeholderMode);
+ }
+ return null;
+ }
} \ No newline at end of file
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateAndRequestParameterResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateAndRequestParameterResolver.java
new file mode 100644
index 00000000..c53a9a4f
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateAndRequestParameterResolver.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * <copyright> Copyright 2014 by E-Government Innovation Center EGIZ, Graz, Austria </copyright>
+ * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
+ * joint initiative of the Federal Chancellery Austria and Graz University of
+ * Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * file for details on the various modules and licenses.
+ * The "NOTICE" text file is part of the distribution. Any derivative works
+ * that you distribute must include a readable copy of the "NOTICE" text file.
+ ******************************************************************************/
+package at.gv.egiz.pdfas.lib.impl.stamping;
+
+import at.gv.egiz.pdfas.common.settings.IProfileConstants;
+import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
+import at.gv.egiz.pdfas.common.utils.DNUtils;
+import at.gv.egiz.pdfas.common.utils.OgnlUtils;
+import at.gv.egiz.pdfas.lib.impl.status.OperationStatus;
+import iaik.x509.X509Certificate;
+import ognl.AbstractMemberAccess;
+import ognl.MemberAccess;
+import ognl.OgnlContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.InvalidNameException;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+public class CertificateAndRequestParameterResolver implements IResolver {
+
+ private static final Logger logger = LoggerFactory.getLogger(CertificateAndRequestParameterResolver.class);
+
+ private OgnlContext ctx;
+ private X509Certificate certificate;
+
+ public CertificateAndRequestParameterResolver(X509Certificate certificate, OperationStatus operationStatus) {
+ this.certificate = certificate;
+
+ MemberAccess memberAccess = new AbstractMemberAccess() {
+ @Override
+ public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
+ int modifiers = member.getModifiers();
+ return Modifier.isPublic(modifiers);
+ }
+ };
+
+ this.ctx = new OgnlContext(null, null, memberAccess);
+
+ this.ctx = new OgnlContext(null, null, memberAccess);
+ Map<String, String> map = operationStatus.getSignParamter().getDynamicSignatureBlockArguments();
+ if(map == null)
+ map = new HashMap<>();
+ this.ctx.put(IProfileConstants.SIGNATURE_BLOCK_PARAMETER, map);
+
+ this.ctx.put("sn", this.certificate.getSerialNumber().toString());
+
+ try {
+ Map<String, String> issuerDNMap = DNUtils.dnToMap(certificate.getIssuerDN().getName());
+ this.ctx.put("issuer", issuerDNMap);
+ } catch (InvalidNameException e) {
+ logger.warn("Failed to build issuer Map", e);
+ }
+
+ try {
+ Map<String, String> subjectDNMap = DNUtils.dnToMap(certificate.getSubjectDN().getName());
+ this.ctx.put("subject", subjectDNMap);
+ } catch (InvalidNameException e) {
+ logger.warn("Failed to build subject Map", e);
+ }
+
+ Map<String, String> iuiMap = new HashMap<String, String>();
+ try {
+ iuiMap.put("pdfVersion", operationStatus.getPdfObject().getPDFVersion());
+ } catch(Throwable e) {
+ logger.warn("Cannot determine pdfVersion: " + e.getMessage());
+ }
+ this.ctx.put("iui", iuiMap);
+ }
+
+ public String resolve(String key, String value, SignatureProfileSettings settings) {
+ return OgnlUtils.resolvsOgnlExpression(value, this.ctx);
+ }
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateResolver.java
index edb87eb2..d7d83b34 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateResolver.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/CertificateResolver.java
@@ -28,11 +28,17 @@ import at.gv.egiz.pdfas.common.utils.DNUtils;
import at.gv.egiz.pdfas.common.utils.OgnlUtils;
import at.gv.egiz.pdfas.lib.impl.status.OperationStatus;
import iaik.x509.X509Certificate;
+import ognl.AbstractMemberAccess;
+import ognl.MemberAccess;
+import ognl.Ognl;
import ognl.OgnlContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.naming.InvalidNameException;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
@@ -45,7 +51,16 @@ public class CertificateResolver implements IResolver {
public CertificateResolver(X509Certificate certificate, OperationStatus operationStatus) {
this.certificate = certificate;
- this.ctx = new OgnlContext();
+
+ MemberAccess memberAccess = new AbstractMemberAccess() {
+ @Override
+ public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
+ int modifiers = member.getModifiers();
+ return Modifier.isPublic(modifiers);
+ }
+ };
+
+ this.ctx = new OgnlContext(null, null, memberAccess);
this.ctx.put("sn", this.certificate.getSerialNumber().toString());
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java
new file mode 100644
index 00000000..a4e88682
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java
@@ -0,0 +1,38 @@
+package at.gv.egiz.pdfas.lib.impl.stamping;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.util.Map;
+
+import at.gv.egiz.pdfas.common.settings.IProfileConstants;
+import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
+import at.gv.egiz.pdfas.common.utils.OgnlUtils;
+import ognl.AbstractMemberAccess;
+import ognl.MemberAccess;
+import ognl.OgnlContext;
+
+
+public class RequestParameterResolver implements IResolver {
+
+ private OgnlContext ctx;
+
+ public RequestParameterResolver(Map<String, String> requestParameters) {
+
+ MemberAccess memberAccess = new AbstractMemberAccess() {
+ @Override
+ public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
+ int modifiers = member.getModifiers();
+ return Modifier.isPublic(modifiers);
+ }
+ };
+
+ this.ctx = new OgnlContext(null, null, memberAccess);
+ this.ctx.put(IProfileConstants.SIGNATURE_BLOCK_PARAMETER, requestParameters);
+ }
+
+ @Override
+ public String resolve(String key, String value, SignatureProfileSettings settings) {
+ return OgnlUtils.resolvsOgnlExpression(value, this.ctx);
+ }
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java
index 01a3a298..2908cfcd 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java
@@ -221,19 +221,23 @@ public class TableFactory implements IProfileConstants {
row.add(entry);
}
}
- if ((TYPE_VALUE + TYPE_CAPTION).equals(type) || (TYPE_CAPTION + TYPE_VALUE).equals(type))
+
+ if ((TYPE_VALUE + TYPE_CAPTION).equals(type) || (TYPE_CAPTION + TYPE_VALUE).equals(type) || "req".equals(type))
{
// add a caption value pair
String caption = profile.getCaption(key);
String value = profile.getValue(key);
//String caption = getSigCaption(key);
//String value = getSigValue(key);
- if (value != null)
- {
+
+ ValueResolver resolver = new ValueResolver(certProvider, operationStatus);
+
+ if (value != null) {
Entry c_entry = new Entry(Entry.TYPE_CAPTION, caption, key);
c_entry.setNoWrap(true); // dferbas fix bug #331
c_entry.setStyle(defaultCaptionStyle_);
- ValueResolver resolver = new ValueResolver(certProvider, operationStatus);
+
+
Entry v_entry = new Entry(Entry.TYPE_VALUE,
resolver.resolve(key, value, profile), key);
v_entry.setStyle(defaultValueStyle_);
@@ -248,8 +252,6 @@ public class TableFactory implements IProfileConstants {
c_entry.setNoWrap(true); // dferbas fix bug #331
c_entry.setStyle(defaultCaptionStyle_);
- ValueResolver resolver = new ValueResolver(certProvider, operationStatus);
-
Entry v_entry = new Entry(Entry.TYPE_VALUE,
resolver.resolve(key, value, profile), key);
v_entry.setStyle(defaultValueStyle_);
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java
index f7210036..ab118857 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java
@@ -27,12 +27,17 @@ import at.gv.egiz.pdfas.common.settings.IProfileConstants;
import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
import at.gv.egiz.pdfas.lib.impl.status.ICertificateProvider;
import at.gv.egiz.pdfas.lib.impl.status.OperationStatus;
+
+import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature;
+import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -56,13 +61,12 @@ public class ValueResolver implements IProfileConstants, IResolver {
private static final Charset UTF_8 = Charset.forName("UTF-8");
- private CertificateResolver certificateResolver;
-
+ private IResolver internalResolver;
public ValueResolver(ICertificateProvider certProvider, OperationStatus operationStatus) {
- certificateResolver = new CertificateResolver(
- certProvider.getCertificate(), operationStatus);
+ internalResolver = new CertificateAndRequestParameterResolver(certProvider.getCertificate(),
+ operationStatus);
}
-
+
public String resolve(String key, String value,
SignatureProfileSettings settings) {
@@ -102,10 +106,12 @@ public class ValueResolver implements IProfileConstants, IResolver {
do {
int idx = matcher.start(0);
int idxe = matcher.end(0);
- result += value.substring(curidx, idx);
+ String tmp1 = value.substring(curidx, idx);
+ result += tmp1;
curidx = idxe;
- result += certificateResolver.resolve(key,
- matcher.group(1), settings);
+ String tmpValue = matcher.group(1);
+ String tmp2 = internalResolver.resolve(key, tmpValue, settings);
+ result += tmp2;
} while (matcher.find());
} else {
result = value;
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java
index ecdddfa1..898b7a00 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java
@@ -56,6 +56,8 @@ public class OperationStatus implements Serializable {
private PDFASBackend backend;
private Map<String, String> metaInformations = new HashMap<String, String>();
+// private HashMap<String, String> requestParameters = new HashMap<String, String>();
+
public OperationStatus(ISettings configuration, SignParameter signParameter, PDFASBackend backend) {
this.configuration = configuration;
this.signParamter = signParameter;
@@ -174,4 +176,8 @@ public class OperationStatus implements Serializable {
public Map<String, String> getMetaInformations() {
return metaInformations;
}
+
+// public HashMap<String, String> getRequestParameters() {
+// return requestParameters;
+// }
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java
index de88f610..0b49aa90 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java
@@ -24,6 +24,8 @@
package at.gv.egiz.pdfas.lib.impl.status;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.activation.DataSource;
@@ -69,4 +71,9 @@ public abstract class PDFObject {
}
public abstract String getPDFVersion();
+
+ public Map<String, String> getRequestParameters() {
+ return status.getSignParamter().getDynamicSignatureBlockArguments();
+// return status.getRequestParameters();//TODO alex
+ }
}
diff --git a/pdf-as-lib/src/main/resources/config/config.zip b/pdf-as-lib/src/main/resources/config/config.zip
index 0c4be90c..38cc4f34 100644
--- a/pdf-as-lib/src/main/resources/config/config.zip
+++ b/pdf-as-lib/src/main/resources/config/config.zip
Binary files differ
diff --git a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java
new file mode 100644
index 00000000..3c76ce11
--- /dev/null
+++ b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java
@@ -0,0 +1,51 @@
+package at.gv.egiz.pdfas.lib.test.mains;
+
+import at.gv.egiz.pdfas.common.utils.CheckSignatureBlockParameters;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class SignatureBlockParameterTest {
+
+
+ @Test
+ public void testKeyInvalid() {
+ if(checkValid( "aaaaaaaaaaaaaaaaaaaaa" , "^([A-za-z]){1,20}$") == true){assert(false);}
+ if(checkValid( "" , "^([A-za-z]){1,20}$") == true){assert(false);}
+ if(checkValid( "a9" , "^([A-za-z]){1,20}$") == true){assert(false);}
+ }
+ @Test
+ public void testKeyValid() {
+ if(checkValid( "aaa" +"aa", "^([A-za-z]){1,20}$") == false){assert(false);}
+ if(checkValid( "aaa" , "^([A-za-z]){1,20}$") == false){assert(false);}
+ if(checkValid( "aaaaaaaaaaaaaaaaaaaa", "^([A-za-z]){1,20}$") == false){assert(false);}
+ if(checkValid( "AA", "^([A-za-z]){1,20}$") == false){assert(false);}
+ }
+ @Test
+ public void testValueValid() {
+ if(checkValid( "aaa" +"aa", "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "aaa" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "a!\"$%&/()[]=?aa" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "a!\"$%&/()[]=?aa-_,;.:[]|{}" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+// if(checkValid( "a!\"ยง$%&/()=?aa" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "aa!%&/()=?a" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "a{\"a!%&/()=?a" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "BB" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ if(checkValid( "BB " , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ }
+ @Test
+ public void testValueInvalid() {
+ if(checkValid((char) 13 +"aaa" +"aa", "^([\\p{Print}]){1,100}$") == true){assert(false);}
+ if(checkValid((char) 13 +"", "^([\\p{Print}]){1,100}$") == true){assert(false);}
+ if(checkValid( "aaa" +(char) 13, "^([\\p{Print}]){1,100}$") == true){assert(false);}
+ if(checkValid("", "^([\\p{Print}]){1,100}$") == true){assert(false);}
+ if(checkValid("a", "^([\\p{Print}]){2,100}$") == true){assert(false);}
+ if(checkValid("aaa"+(char) 13 +"aa", "^([\\p{Print}]){1,100}$") == true){assert(false);}
+
+ }
+
+ public boolean checkValid(String s, String regex) {
+ return CheckSignatureBlockParameters.isValid(s, regex);
+ }
+}