diff options
author | ferbas <ferbas@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2009-12-04 09:42:00 +0000 |
---|---|---|
committer | ferbas <ferbas@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2009-12-04 09:42:00 +0000 |
commit | 894ab866078b47cba7e73df3fd36af7d1b8c9efe (patch) | |
tree | fe29a6259ed1275de013da95fbc37c3359b7438e /src | |
parent | c7358ca0e6e14322a380d39b8d0d99bcd9575c09 (diff) | |
download | pdf-as-3-894ab866078b47cba7e73df3fd36af7d1b8c9efe.tar.gz pdf-as-3-894ab866078b47cba7e73df3fd36af7d1b8c9efe.tar.bz2 pdf-as-3-894ab866078b47cba7e73df3fd36af7d1b8c9efe.zip |
added config property adobeSignText
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@488 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java index 47bae56..ebf7d42 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java @@ -45,6 +45,7 @@ import at.gv.egiz.pdfas.exceptions.pdf.KZSettingNotFoundException; import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import at.gv.egiz.pdfas.framework.output.DataSink;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.utils.OgnlUtil;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException;
@@ -239,6 +240,8 @@ public abstract class BinarySignature * The number placeholder that is used to give numbers a fixed length.
*/
protected static final PdfNumber NUMBER_PLACEHOLDER = new PdfNumber(99999999);
+
+ public static final String ADOBE_SIG_TEXT_KEY = "adobeSignText";
/**
* Extracts the signature text only.
@@ -966,14 +969,7 @@ public abstract class BinarySignature XMLGregorianCalendar c = DatatypeFactory.newInstance().newXMLGregorianCalendar(si.getSignSignatureObject().date);
sig.setDate(new PdfDate(c.toGregorianCalendar()));
}
- String cn = null;
- if (si != null) {
- cn = si.getSignSignatureObject().certSubjectDNPart("CN");
- }
- if (cn == null) {
- cn = "PDF-AS";
- }
- sig.setName(cn);
+ sig.setName(getAdobeSigName(so.getSignatureTypeDefinition().getType(), si));
sap.setCryptoDictionary(sig);
// content element is mandatory but empty
@@ -988,9 +984,48 @@ public abstract class BinarySignature logger.error("error", ex);
throw new PresentableException(ErrorCode.CANNOT_WRITE_PDF, "Error creating adobe signature attribute", ex);
}
-
}
+ /**
+ * Evaluate name for adobe signature field. Get from config. Evaluate ognl if ok.
+ * @param sigProfile
+ * @param si
+ * @return
+ */
+ private static String getAdobeSigName(String sigProfile, SignatorInformation si) {
+ String defaultName = "PDF-AS";
+ try {
+ logger.debug("reading adobe sig name for profile: " + sigProfile);
+ String propKey = ADOBE_SIG_TEXT_KEY + ".textual";
+ if (si == null) {
+ propKey = propKey.replaceAll("textual", "binary");
+ }
+ String adobeStr = SettingsReader.getInstance().getSetting(
+ "sig_obj." +sigProfile+"."+propKey,
+ "default."+propKey, defaultName);
+
+ HashMap ognlCtx = new HashMap();
+ OgnlUtil ognl = new OgnlUtil(ognlCtx);
+ if (ognl.containsExpression(adobeStr)) {
+ if (si == null) {
+ logger.error( ADOBE_SIG_TEXT_KEY +
+ " ognl expressions not allowed for binary signatures (SignatorInformation not available)");
+ return defaultName;
+ }
+ ognlCtx.put("si", si);
+ ognlCtx.put("sso", si.getSignSignatureObject());
+ String res = ognl.compileMessage(adobeStr);
+ return res;
+ } else {
+ return adobeStr;
+ }
+
+ } catch (Exception ex) {
+ logger.warn("error creating adobe sign text, using default 'PDF-AS'", ex);
+ return defaultName;
+ }
+ }
+
private static Rectangle createRectangleFromTablePos(ActualTablePos pos) {
return new Rectangle(pos.x, pos.y, pos.x + pos.width, pos.y - pos.height);
}
|