aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java53
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);
}