diff options
author | Thomas <> | 2021-03-26 15:42:00 +0100 |
---|---|---|
committer | Thomas <> | 2021-03-26 15:42:00 +0100 |
commit | 935a42e0c046282d1dda8aaf418822e25677c81a (patch) | |
tree | 05d0997caade3a271b6e15bd25190c58b99b346a /pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl | |
parent | 8a8d467d6415c5b12262ad18ff7f21f6b07cdcd4 (diff) | |
download | pdf-as-4-935a42e0c046282d1dda8aaf418822e25677c81a.tar.gz pdf-as-4-935a42e0c046282d1dda8aaf418822e25677c81a.tar.bz2 pdf-as-4-935a42e0c046282d1dda8aaf418822e25677c81a.zip |
simple PoC for this task
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl')
3 files changed, 60 insertions, 9 deletions
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..1d8d4638 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java @@ -0,0 +1,35 @@ +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.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(memberAccess, null, null, 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..9f015594 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,24 @@ 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 = "req".equals(type) + ? new ValueResolver(operationStatus) + : 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 +253,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..c6cddc9e 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 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.Collections; +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,21 @@ 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( + internalResolver = new CertificateResolver( certProvider.getCertificate(), operationStatus); } + public ValueResolver(OperationStatus operationStatus) { + Map<String, String> test = new HashMap<>(); + test.put("schoolNameRand", RandomStringUtils.randomAlphabetic(5)); + test.put("schoolName", "EGIZ testschule"); + internalResolver = new RequestParameterResolver(test); + + } + public String resolve(String key, String value, SignatureProfileSettings settings) { @@ -104,7 +117,7 @@ public class ValueResolver implements IProfileConstants, IResolver { int idxe = matcher.end(0); result += value.substring(curidx, idx); curidx = idxe; - result += certificateResolver.resolve(key, + result += internalResolver.resolve(key, matcher.group(1), settings); } while (matcher.find()); } else { |