diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2013-10-01 15:27:32 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2013-10-01 15:27:32 +0200 |
commit | add4460d9619f3586a02ae0d8c028f01903494bc (patch) | |
tree | 244ef6d0f0af028da98f9cecd3ee9a3424223889 /pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping | |
parent | 25f5495b60fb0fb089c7af216986d2f3abf92375 (diff) | |
download | pdf-as-4-add4460d9619f3586a02ae0d8c028f01903494bc.tar.gz pdf-as-4-add4460d9619f3586a02ae0d8c028f01903494bc.tar.bz2 pdf-as-4-add4460d9619f3586a02ae0d8c028f01903494bc.zip |
+ Extracting information from Certificate (Ognl)
+ CMS KeyStore Signer (still wrong format)
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping')
4 files changed, 53 insertions, 19 deletions
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 f30c326d..78dcbe23 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 @@ -3,13 +3,16 @@ package at.gv.egiz.pdfas.lib.impl.stamping; 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.RequestedSignature; import iaik.x509.X509Certificate; import ognl.OgnlContext; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; + import java.util.Map; public class CertificateResolver implements IResolver { @@ -39,7 +42,8 @@ public class CertificateResolver implements IResolver { } - public String resolve(String key, String value, SignatureProfileSettings settings) { + public String resolve(String key, String value, SignatureProfileSettings settings, + RequestedSignature signature) { return OgnlUtils.resolvsOgnlExpression(value, this.ctx); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IResolver.java index 040daf33..921d9eca 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IResolver.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/IResolver.java @@ -1,6 +1,7 @@ package at.gv.egiz.pdfas.lib.impl.stamping; import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; +import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; /** * Created with IntelliJ IDEA. @@ -10,5 +11,6 @@ import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; * To change this template use File | Settings | File Templates. */ public interface IResolver { - public String resolve(String key, String value, SignatureProfileSettings settings); + public String resolve(String key, String value, SignatureProfileSettings settings, + RequestedSignature signature); } 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 45b8b711..9d574af7 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 @@ -3,6 +3,7 @@ package at.gv.egiz.pdfas.lib.impl.stamping; import at.gv.egiz.pdfas.common.settings.IProfileConstants; import at.gv.egiz.pdfas.common.settings.ISettings; import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; +import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; import at.knowcenter.wag.egov.egiz.pdf.sig.SignatureEntry; import at.knowcenter.wag.egov.egiz.table.Entry; import at.knowcenter.wag.egov.egiz.table.Style; @@ -71,7 +72,8 @@ public class TableFactory implements IProfileConstants { * @see at.knowcenter.wag.egov.egiz.table.Table * @see at.knowcenter.wag.egov.egiz.table.Entry */ - public static Table createSigTable(SignatureProfileSettings profile, String tableID, ISettings configuration ) + public static Table createSigTable(SignatureProfileSettings profile, String tableID, ISettings configuration, + RequestedSignature requestedSignature) { String table_key_prefix = SIG_OBJ + profile.getProfileID() + "." + TABLE; String table_key = table_key_prefix + tableID; @@ -135,7 +137,7 @@ public class TableFactory implements IProfileConstants { if (TYPE_TABLE.equals(key)) { // add a table entry - Table table = createSigTable(profile, type, configuration); + Table table = createSigTable(profile, type, configuration, requestedSignature); if (table != null) { Entry entry = new Entry(Entry.TYPE_TABLE, table, key); @@ -160,8 +162,10 @@ public class TableFactory implements IProfileConstants { if (TYPE_VALUE.equals(type)) { // add a single value entry + ValueResolver resolver = new ValueResolver(); String value = profile.getValue(key); - Entry entry = new Entry(Entry.TYPE_VALUE, value, key); + Entry entry = new Entry(Entry.TYPE_VALUE, + resolver.resolve(key, value, profile, requestedSignature), key); if (entry != null) { entry.setColSpan(2); @@ -181,8 +185,9 @@ public class TableFactory implements IProfileConstants { Entry c_entry = new Entry(Entry.TYPE_CAPTION, caption, key); c_entry.setNoWrap(true); // dferbas fix bug #331 c_entry.setStyle(defaultCaptionStyle_); - - Entry v_entry = new Entry(Entry.TYPE_VALUE, value, key); + ValueResolver resolver = new ValueResolver(); + Entry v_entry = new Entry(Entry.TYPE_VALUE, + resolver.resolve(key, value, profile, requestedSignature), key); v_entry.setStyle(defaultValueStyle_); if (c_entry != null && v_entry != null) { @@ -198,7 +203,7 @@ public class TableFactory implements IProfileConstants { ValueResolver resolver = new ValueResolver(); Entry v_entry = new Entry(Entry.TYPE_VALUE, - resolver.resolve(key, value, profile), key); + resolver.resolve(key, value, profile, requestedSignature), key); v_entry.setStyle(defaultValueStyle_); if (c_entry != null && v_entry != null) { 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 9052a7eb..19b38f27 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 @@ -3,10 +3,13 @@ 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.lib.impl.PdfAsImpl; +import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,11 +18,13 @@ import org.slf4j.LoggerFactory; * Created with IntelliJ IDEA. User: afitzek Date: 9/11/13 Time: 11:11 AM To * change this template use File | Settings | File Templates. */ -public class ValueResolver implements IProfileConstants { +public class ValueResolver implements IProfileConstants, IResolver { private static final Logger logger = LoggerFactory .getLogger(ValueResolver.class); + public static final String PatternRegex = "\\$(\\{[^\\$]*\\})"; + private static final String defaultDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; public static final String EXP_START = "${"; @@ -31,25 +36,43 @@ public class ValueResolver implements IProfileConstants { // TODO: Use status in real implementation to get currently needed // informations... public String resolve(String key, String value, - SignatureProfileSettings settings) { + SignatureProfileSettings settings, RequestedSignature signature) { logger.debug("Resolving value for key: " + key); logger.debug("Resolving value with value: " + value); if (value != null) { - if (value.startsWith(EXP_START) && value.endsWith(EXP_END)) { - // TODO: handle OGNL expression for key and value - // TODO: Here we need the certificate - CertificateResolver certificateResolver = new CertificateResolver( - null); - String exp = value.substring(EXP_START.length(), value.length() - - EXP_END.length()); - return certificateResolver.resolve(key, exp, settings); + + Pattern pattern = Pattern.compile(PatternRegex); + Matcher matcher = pattern.matcher(value); + CertificateResolver certificateResolver = new CertificateResolver( + signature.getCertificate()); + String result = ""; + int curidx = 0; + if (matcher.find()) { + do { + int idx = matcher.start(0); + int idxe = matcher.end(0); + result += value.substring(curidx, idx); + curidx = idxe; + result += certificateResolver.resolve(key, + matcher.group(1), settings, signature); + } while (matcher.find()); + } else { + result = value; } + /* + * if (value.startsWith(EXP_START) && value.endsWith(EXP_END)) { // + * TODO: handle OGNL expression for key and value // TODO: Here we + * need the certificate + * + * String exp = value.replace('$', ' '); return } + */ + return result; } if (key.equals(SIG_DATE)) { - if(value == null) { + if (value == null) { value = defaultDateFormat; } // Value holds the date format! |