From 0bc55a19b8c7b2aa53c74fee08f6bf97017ef586 Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Sat, 10 Apr 2021 15:07:10 +0200 Subject: extend valueresolver --- .../impl/stamping/RequestParameterResolver.java | 23 ++++++++++----- .../pdfas/lib/impl/stamping/ValueResolver.java | 34 +++++++++++++++------- .../pdfas/lib/impl/status/OperationStatus.java | 6 ++++ 3 files changed, 45 insertions(+), 18 deletions(-) (limited to 'pdf-as-lib') 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 index 1d8d4638..4b2a8f10 100644 --- 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 @@ -16,15 +16,22 @@ public class RequestParameterResolver implements IResolver { private OgnlContext ctx; public RequestParameterResolver(Map requestParameters) { + +// this.ctx = new OgnlContext(memberAccess, null, null, 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 boolean isAccessible(Map context, Object target, Member member, String propertyName) { + int modifiers = member.getModifiers(); + return Modifier.isPublic(modifiers); + } + }; + + this.ctx = new OgnlContext(null, null, memberAccess); + this.ctx.put("dynamic", requestParameters); +// for(String key : requestParameters.keySet()) { +// this.ctx.put(key, requestParameters.get(key)); +// } + } @Override 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 c6cddc9e..e5905c22 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 @@ -35,7 +35,6 @@ 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; @@ -61,19 +60,27 @@ public class ValueResolver implements IProfileConstants, IResolver { private static final Charset UTF_8 = Charset.forName("UTF-8"); - private IResolver internalResolver; - + private IResolver internalCertificateResolver; + private IResolver internalRequestParameterResolver; public ValueResolver(ICertificateProvider certProvider, OperationStatus operationStatus) { - internalResolver = new CertificateResolver( + internalCertificateResolver = new CertificateResolver( certProvider.getCertificate(), operationStatus); + Map test = new HashMap<>(); + test.put("schoolNameRand", RandomStringUtils.randomAlphabetic(5)); + test.put("schoolName", "EGIZ testschule"); + + test.put("subject","bbbbb"); + internalRequestParameterResolver = new RequestParameterResolver(test); } public ValueResolver(OperationStatus operationStatus) { Map test = new HashMap<>(); test.put("schoolNameRand", RandomStringUtils.randomAlphabetic(5)); - test.put("schoolName", "EGIZ testschule"); - internalResolver = new RequestParameterResolver(test); - + test.put("schoolName", "EGIZ testschule"); + + test.put("subject","bbbbb"); + internalRequestParameterResolver = new RequestParameterResolver(test); + } public String resolve(String key, String value, @@ -115,10 +122,17 @@ public class ValueResolver implements IProfileConstants, IResolver { do { int idx = matcher.start(0); int idxe = matcher.end(0); - result += value.substring(curidx, idx); + String tmp1 = value.substring(curidx, idx); + result += tmp1; curidx = idxe; - result += internalResolver.resolve(key, - matcher.group(1), settings); + String tmpValue = matcher.group(1); + if(!tmpValue.contains("dynamic")) { + String tmp = internalCertificateResolver.resolve(key, tmpValue, settings); + result += tmp; + }else { + String tmp2 = internalRequestParameterResolver.resolve(key, tmpValue, settings); + result += tmp2; + } } while (matcher.find()); } else { result = value; diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java index ecdddfa1..08dcd249 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java @@ -56,6 +56,8 @@ public class OperationStatus implements Serializable { private PDFASBackend backend; private Map metaInformations = new HashMap(); + private HashMap requestParameters = new HashMap(); + public OperationStatus(ISettings configuration, SignParameter signParameter, PDFASBackend backend) { this.configuration = configuration; this.signParamter = signParameter; @@ -174,4 +176,8 @@ public class OperationStatus implements Serializable { public Map getMetaInformations() { return metaInformations; } + + public HashMap getRequestParameters() { + return requestParameters; + } } -- cgit v1.2.3