diff options
Diffstat (limited to 'pdf-as-common')
10 files changed, 298 insertions, 237 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/processing/DocumentToSign.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/processing/DocumentToSign.java index 6cc3a933..7d1928df 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/processing/DocumentToSign.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/processing/DocumentToSign.java @@ -19,4 +19,8 @@ public class DocumentToSign implements Serializable { String profile; + boolean placeholderSearchEnabled = true; + + String placeHolderId; + } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyEntry.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyEntry.java index d02c7bbc..0b9b21af 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyEntry.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyEntry.java @@ -1,11 +1,15 @@ package at.gv.egiz.pdfas.api.ws; +import java.io.Serializable; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; -@XmlType(name="PropertyEntry") -public class PDFASPropertyEntry { - String key; +@XmlType(name="PropertyEntry") +public class PDFASPropertyEntry implements Serializable { + private static final long serialVersionUID = -312145729002273058L; + + String key; String value; @XmlElement(required = true, nillable = false, name="key") diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyMap.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyMap.java index 34dca6d2..c3949849 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyMap.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASPropertyMap.java @@ -1,5 +1,6 @@ package at.gv.egiz.pdfas.api.ws; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -11,8 +12,10 @@ import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; @XmlType(name="PropertyMap") -public class PDFASPropertyMap { - List<PDFASPropertyEntry> propertyEntries; +public class PDFASPropertyMap implements Serializable { + private static final long serialVersionUID = -8099703140108251423L; + + List<PDFASPropertyEntry> propertyEntries; @XmlElement(required = true, nillable = false, name="propertyEntries") public List<PDFASPropertyEntry> getPropertyEntries() { diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/SLPdfAsException.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/SLPdfAsException.java index f22fc134..74462a03 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/SLPdfAsException.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/SLPdfAsException.java @@ -28,7 +28,7 @@ import java.util.List; public class SLPdfAsException extends PdfAsException { - private static final List<Integer> ERRORCODES_ON_INFO_LEVEL = Arrays.asList(6001, 6002); + private static final List<Integer> ERRORCODES_ON_INFO_LEVEL = Arrays.asList(6000, 6001, 6002); /** * diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java index 3f07f774..95eaa8ea 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java @@ -94,6 +94,7 @@ public interface IProfileConstants { public final static String SIG_PDFA1B_VALID = "SIG_PDFA1B_VALID"; public final static String SIG_PDFA_VALID = "SIG_PDFA_VALID"; public final static String SIG_PDFUA_FORCE = "SIG_PDFUA_FORCE"; + public final static String SIG_NEWPAGE_FORCE = "SIGNED_NEWPAGE_FORCE"; public final static String LATIN1_ENCODING = "latin1_encoding"; public final static String SIGNATURE_BLOCK_PARAMETER = "sbp"; diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java index 42cdb8ab..43139966 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java @@ -29,6 +29,22 @@ import java.util.Vector; public interface ISettings { public String getValue(String key); public boolean hasValue(String key); + + /** + * Get boolean configuration value. + * @param key Configuration key + * @return <code>true</code> if configuration exists and has value <code>true</code>, otherwise <code>false</code> + */ + public boolean isValue(String key); + + /** + * Get boolean configuration value. + * @param key Configuration key + * @param defaultValue Value if configuration does not exist + * @return <code>true</code> if configuration exists and has value <code>true</code>, otherwise default value + */ + public boolean isValue(String key, boolean defaultValue); + public boolean hasPrefix(String prefix); public Map<String, String> getValuesPrefix(String prefix); public Vector<String> getFirstLevelKeys(String prefix); diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java index 7f047278..65722f88 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java @@ -3,19 +3,19 @@ * 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 @@ -24,7 +24,6 @@ package at.gv.egiz.pdfas.common.settings; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.slf4j.Logger; @@ -35,241 +34,222 @@ import at.gv.egiz.pdfas.common.exceptions.PDFASError; public class SignatureProfileSettings implements IProfileConstants { - private static final Logger logger = LoggerFactory - .getLogger(SignatureProfileSettings.class); + private static final Logger logger = LoggerFactory + .getLogger(SignatureProfileSettings.class); - private Map<String, SignatureProfileEntry> profileInformations = new HashMap<String, SignatureProfileEntry>(); + private final Map<String, SignatureProfileEntry> profileInformations = + new HashMap<>(); - private Map<String, String> profileSettings = new HashMap<String, String>(); + private final Map<String, String> profileSettings = new HashMap<>(); - private String profileID; + private final String profileID; - private String pdfAVersion = null; + private String pdfAVersion = null; - private ISettings configuration; + private final ISettings configuration; - public SignatureProfileSettings(String profileID, ISettings configuration) throws PDFASError { - - if (!configuration.hasPrefix(SIG_OBJ + profileID)) { + public SignatureProfileSettings(String profileID, ISettings configuration) throws PDFASError { + + if (!configuration.hasPrefix(SIG_OBJ + profileID)) { throw new PDFASError(ErrorConstants.ERROR_SIG_INVALID_PROFILE, PDFASError.buildInfoString(ErrorConstants.ERROR_SIG_INVALID_PROFILE, profileID)); } - - this.profileID = profileID; - String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR; - String keysPrefix = profilePrefix + PROFILE_KEY; - String valuesPrefix = profilePrefix + PROFILE_VALUE; - String tablePrefix = profilePrefix + TABLE; - this.configuration = configuration; - - logger.debug("Reading Profile: " + profileID); - logger.debug("Keys Prefix: " + keysPrefix); - logger.debug("Values Prefix: " + valuesPrefix); - logger.debug("Table Prefix: " + tablePrefix); - - Map<String, String> keys = configuration.getValuesPrefix(keysPrefix); - Map<String, String> values = configuration.getValuesPrefix(valuesPrefix); - - if (keys != null) { - Iterator<String> keyIterator = keys.keySet().iterator(); - - while (keyIterator.hasNext()) { - String key = keyIterator.next(); - key = key.substring(key.lastIndexOf('.') + 1); - String valueKey = keys.get(keysPrefix + KEY_SEPARATOR + key); - - String valueValue = values.get(valuesPrefix + KEY_SEPARATOR - + key); - - // Lookup default values - if(valueKey == null) { - valueKey = DefaultSignatureProfileSettings.getDefaultKeyCaption(key); - } - - if(valueValue == null) { - valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key); - } - - SignatureProfileEntry entry = new SignatureProfileEntry(); - entry.setKey(key); - entry.setCaption(valueKey); - entry.setValue(valueValue); - profileInformations.put(key, entry); - logger.debug(" " + entry.toString()); - } - } - - if (values != null) { - // Find entries where only values exists - Iterator<String> valuesIterator = values.keySet().iterator(); - - while (valuesIterator.hasNext()) { - String key = valuesIterator.next(); - key = key.substring(key.lastIndexOf('.') + 1); - - String valueValue = values.get(valuesPrefix + KEY_SEPARATOR - + key); - - // Lookup default values - if(valueValue == null) { - valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key); - } - - SignatureProfileEntry entry = profileInformations.get(key); - if (entry == null) { - entry = new SignatureProfileEntry(); - entry.setKey(key); - entry.setCaption(null); - entry.setValue(valueValue); - profileInformations.put(key, entry); - } - - logger.debug(" " + entry.toString()); - } - } - - Map<String, String> others = configuration - .getValuesPrefix(profilePrefix); - - if(others != null) { - Iterator<String> otherIterator = others.keySet().iterator(); - - while (otherIterator.hasNext()) { - String key = otherIterator.next(); - - logger.trace("Checking key " + key); - if (key.startsWith(keysPrefix) || key.startsWith(valuesPrefix) - || key.startsWith(tablePrefix)) { - continue; - } - - String value = others.get(key); - key = key.substring(key.lastIndexOf('.') + 1); - - profileSettings.put(key, value); - - logger.debug(" Settings: " + key + " : " + value); - } - } - - Iterator<SignatureProfileEntry> dumpIterator = - profileInformations.values().iterator(); - - logger.debug("Settings for profile {}", profileID); - while(dumpIterator.hasNext()) { - SignatureProfileEntry entry = dumpIterator.next(); - logger.debug(" " + entry.toString()); - } - } - - public String getCaption(String key) { - SignatureProfileEntry entry = profileInformations.get(key); - if (entry != null) { - return entry.getCaption(); - } - return null; - } - - protected String getDefaultValue(String key) { - String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR; - logger.debug("Searching default value for: " + key); - if (key.startsWith(profilePrefix)) { - key = key.substring(profilePrefix.length()); - } - key = "default." + key; - logger.debug("Searching default value for: " + key); - return this.configuration.getValue(key); - } - - public String getValue(String key) { - logger.debug("Searching: " + key); - SignatureProfileEntry entry = profileInformations.get(key); - if (entry != null) { - String value = entry.getValue(); - - if (value == null) { - return getDefaultValue(key); - } - - return value; - } - String v = profileSettings.get(key); - if (v != null) { - return v; - } - return getDefaultValue(key); - } - - public String getProfileID() { - return profileID; - } - - public String getSigningReason() { - return this.getValue(SIGNING_REASON); - } - - public String getSignFieldValue() { - return this.getValue(SIGNFIELD_VALUE); - } - - public String getProfileTimeZone() { - return this.getValue(TIMEZONE_BASE); - } - - public void setPDFAVersion(String version) { - this.pdfAVersion = version; - } - - public boolean isPDFA() { - - if(this.pdfAVersion != null) { - return "1".equals(this.pdfAVersion); - } - - SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID); - if (entry != null) { - String value = entry.getCaption(); - return "true".equals(value); - } - - entry = profileInformations.get(SIG_PDFA1B_VALID); - if (entry != null) { - String value = entry.getCaption(); - return "true".equals(value); - } - return false; - } - - public boolean isPDFUA() { - SignatureProfileEntry entry = profileInformations.get(SIG_PDFUA_FORCE); - if (entry != null) { - String value = entry.getCaption(); - return "true".equals(value); - } - return false; - } - - - public boolean isLatin1Encoding() { - SignatureProfileEntry entry = profileInformations.get(LATIN1_ENCODING); - if (entry != null) { - String value = entry.getCaption(); - return "true".equals(value); - } - return false; - } - - public boolean isPDFA3() { - if(this.pdfAVersion != null) { - return "3".equals(this.pdfAVersion); - } - - SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID); - if (entry != null) { - String value = entry.getCaption(); - return "true".equals(value); - } - return false; - } + + this.profileID = profileID; + final String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR; + final String keysPrefix = profilePrefix + PROFILE_KEY; + final String valuesPrefix = profilePrefix + PROFILE_VALUE; + final String tablePrefix = profilePrefix + TABLE; + this.configuration = configuration; + + logger.debug("Reading Profile: " + profileID); + logger.debug("Keys Prefix: " + keysPrefix); + logger.debug("Values Prefix: " + valuesPrefix); + logger.debug("Table Prefix: " + tablePrefix); + + final Map<String, String> keys = configuration.getValuesPrefix(keysPrefix); + final Map<String, String> values = configuration.getValuesPrefix(valuesPrefix); + + for (String key : keys.keySet()) { + key = key.substring(key.lastIndexOf('.') + 1); + String valueKey = keys.get(keysPrefix + KEY_SEPARATOR + key); + + String valueValue = values.get(valuesPrefix + KEY_SEPARATOR + + key); + + // Lookup default values + if (valueKey == null) { + valueKey = DefaultSignatureProfileSettings.getDefaultKeyCaption(key); + } + + if (valueValue == null) { + valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key); + } + + final SignatureProfileEntry entry = new SignatureProfileEntry(); + entry.setKey(key); + entry.setCaption(valueKey); + entry.setValue(valueValue); + profileInformations.put(key, entry); + logger.debug(" " + entry.toString()); + } + + for (String key : values.keySet()) { + key = key.substring(key.lastIndexOf('.') + 1); + + String valueValue = values.get(valuesPrefix + KEY_SEPARATOR + + key); + + // Lookup default values + if (valueValue == null) { + valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key); + } + + SignatureProfileEntry entry = profileInformations.get(key); + if (entry == null) { + entry = new SignatureProfileEntry(); + entry.setKey(key); + entry.setCaption(null); + entry.setValue(valueValue); + profileInformations.put(key, entry); + } + + logger.debug(" " + entry.toString()); + } + + final Map<String, String> others = configuration + .getValuesPrefix(profilePrefix); + + if (others != null) { + for (String key : others.keySet()) { + logger.trace("Checking key " + key); + if (key.startsWith(keysPrefix) || key.startsWith(valuesPrefix) + || key.startsWith(tablePrefix)) { + continue; + } + + final String value = others.get(key); + key = key.substring(key.lastIndexOf('.') + 1); + + profileSettings.put(key, value); + + logger.debug(" Settings: " + key + " : " + value); + } + } + + logger.debug("Settings for profile {}", profileID); + for (final SignatureProfileEntry entry : profileInformations.values()) { + logger.debug(" " + entry.toString()); + } + } + + public String getCaption(String key) { + final SignatureProfileEntry entry = profileInformations.get(key); + if (entry != null) { + return entry.getCaption(); + } + return null; + } + + protected String getDefaultValue(String key) { + final String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR; + logger.debug("Searching default value for: " + key); + if (key.startsWith(profilePrefix)) { + key = key.substring(profilePrefix.length()); + } + key = "default." + key; + logger.debug("Searching default value for: " + key); + return this.configuration.getValue(key); + } + + public String getValue(String key) { + logger.debug("Searching: " + key); + final SignatureProfileEntry entry = profileInformations.get(key); + if (entry != null) { + final String value = entry.getValue(); + + if (value == null) { + return getDefaultValue(key); + } + + return value; + } + final String v = profileSettings.get(key); + if (v != null) { + return v; + } + return getDefaultValue(key); + } + + public String getProfileID() { + return profileID; + } + + public String getSigningReason() { + return this.getValue(SIGNING_REASON); + } + + public String getSignFieldValue() { + return this.getValue(SIGNFIELD_VALUE); + } + + public String getProfileTimeZone() { + return this.getValue(TIMEZONE_BASE); + } + + public void setPDFAVersion(String version) { + this.pdfAVersion = version; + } + + public boolean isPDFA() { + + if (this.pdfAVersion != null) { + return "1".equals(this.pdfAVersion); + } + + SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID); + if (entry != null) { + final String value = entry.getCaption(); + return "true".equals(value); + } + + entry = profileInformations.get(SIG_PDFA1B_VALID); + if (entry != null) { + final String value = entry.getCaption(); + return "true".equals(value); + } + return false; + } + + public boolean isPDFUA() { + final SignatureProfileEntry entry = profileInformations.get(SIG_PDFUA_FORCE); + if (entry != null) { + final String value = entry.getCaption(); + return "true".equals(value); + } + return false; + } + + public boolean isLatin1Encoding() { + final SignatureProfileEntry entry = profileInformations.get(LATIN1_ENCODING); + if (entry != null) { + final String value = entry.getCaption(); + return "true".equals(value); + } + return false; + } + + public boolean isPDFA3() { + if (this.pdfAVersion != null) { + return "3".equals(this.pdfAVersion); + } + + final SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID); + if (entry != null) { + final String value = entry.getCaption(); + return "true".equals(value); + } + return false; + } } diff --git a/pdf-as-common/src/main/resources/resources/messages/common.properties b/pdf-as-common/src/main/resources/resources/messages/common.properties index d8695619..f3baebad 100644 --- a/pdf-as-common/src/main/resources/resources/messages/common.properties +++ b/pdf-as-common/src/main/resources/resources/messages/common.properties @@ -1,3 +1,6 @@ +# Configuration errors +error.config.sl20.01=Signing of SL2.0 messages are enabled, but not Keystore available + # PDF Permission Errors error.pdf.perm.01=You do not have permission to extract images diff --git a/pdf-as-common/src/main/resources/resources/messages/error.properties b/pdf-as-common/src/main/resources/resources/messages/error.properties index 4f67fff6..dd873f1e 100644 --- a/pdf-as-common/src/main/resources/resources/messages/error.properties +++ b/pdf-as-common/src/main/resources/resources/messages/error.properties @@ -21,6 +21,8 @@ 11017=Failed to retrieve certificate 11018=Given Alias contains no private key 11019=Signature was created for wrong certificate +11020=Failed to process PDF document. Reason: {0} +11021=Signer certificate is not valid, because notBefore or notAfter does not match 13001=Invalid Configuration Objects 13002=Given certificate is invalid diff --git a/pdf-as-common/src/test/java/at/gv/egiz/pdfas/common/test/utils/CheckSignatureParametersTest.java b/pdf-as-common/src/test/java/at/gv/egiz/pdfas/common/test/utils/CheckSignatureParametersTest.java new file mode 100644 index 00000000..5ec0541b --- /dev/null +++ b/pdf-as-common/src/test/java/at/gv/egiz/pdfas/common/test/utils/CheckSignatureParametersTest.java @@ -0,0 +1,48 @@ +package at.gv.egiz.pdfas.common.test.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import at.gv.egiz.pdfas.common.settings.DefaultSignatureProfileSettings; +import at.gv.egiz.pdfas.common.utils.CheckSignatureBlockParameters; + +@RunWith(BlockJUnit4ClassRunner.class) +public class CheckSignatureParametersTest { + + @Test + public void singleTest() { + assertTrue("valid characters are not possilbe", + CheckSignatureBlockParameters.isValid("Güssing", + DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX)); + + } + + @Test + public void specialCharactersCompiletimeConfig() { + Map<String, String> toTest = new HashMap<>(); + toTest.put("test", "Güssing"); + + assertTrue("valid characters are not possilbe", + CheckSignatureBlockParameters.checkSignatureBlockParameterMapIsValid(toTest , null, null)); + + } + + @Test + public void specialCharactersExampleConfig() { + Map<String, String> toTest = new HashMap<>(); + toTest.put("test", "Güssing"); + + assertFalse("valid characters are not possilbe", + CheckSignatureBlockParameters.checkSignatureBlockParameterMapIsValid(toTest , + "^([A-za-z]){1,20}$", "^([\\p{Print}]){1,100}$")); + + } + +} |