diff options
| author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2026-06-08 15:20:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-08 15:20:40 +0200 |
| commit | 9b452b7f5abf799a31f751859ca3103f053adebf (patch) | |
| tree | cd0f2db53ac75926f2c2e308d9b496bb73fc58cf /pdf-as-web/src/main/java/at | |
| parent | c8abbd8bef5349ab892a2853a4e5e3d5ed16b670 (diff) | |
| download | pdf-as-4-9b452b7f5abf799a31f751859ca3103f053adebf.tar.gz pdf-as-4-9b452b7f5abf799a31f751859ca3103f053adebf.tar.bz2 pdf-as-4-9b452b7f5abf799a31f751859ca3103f053adebf.zip | |
Further follow-up fixes (#87)
* remove remaining references to pdf-as 4
* fix tomcat coop
- properly initialize spring boot not just for bootRun but also for tomcat
- fail-fast if properties fails to load
- also deps bumps
* major version bumps
spring boot 3 -> 4
tomcat 10 -> tomcat 11
junit 4 -> 6
Diffstat (limited to 'pdf-as-web/src/main/java/at')
5 files changed, 74 insertions, 74 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/PdfAsWeb.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/PdfAsWeb.java index 9d1cd7fe..e9ba88be 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/PdfAsWeb.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/PdfAsWeb.java @@ -2,9 +2,16 @@ package at.gv.egiz.pdfas.web; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication -public class PdfAsWeb { +public class PdfAsWeb extends SpringBootServletInitializer { + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(PdfAsWeb.class); + } + public static void main(String[] args) { SpringApplication.run(PdfAsWeb.class, args); } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java index 85e1b75d..f781b258 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java @@ -136,9 +136,14 @@ public class WebConfiguration implements IConfigurationConstants { public static void configure(String configFile) { try (InputStream is = new FileInputStream(configFile)) { + logger.info("Loading PDF-AS Web configuration from '{}'...", configFile); configure(is); } catch (Exception e) { logger.error("Failed to load configuration {}", configFile, e); + if (e instanceof RuntimeException ex) + throw ex; + else + throw new RuntimeException(e); } } @@ -152,14 +157,30 @@ public class WebConfiguration implements IConfigurationConstants { try { properties.load(config); } catch (Exception e) { - logger.error("Failed to load configuration: " + e.getMessage()); + logger.error("Failed to load configuration.", e); throw new RuntimeException(e); } + { // validate + if (properties.isEmpty()) { + logger.error("No properties were loaded from web configuration. You likely did not specify `pdf-as-web.conf` correctly."); + throw new RuntimeException("No properties were loaded from the web configuration. Check if you specified `pdf-as-web.conf` correctly."); + } + String pdfASDir = getPdfASDir(); + if (pdfASDir == null) { + logger.error("Please configure the PDF-AS working directory in the web configuration"); + throw new RuntimeException( + "Please configure PDF-AS working directory in the web configuration"); + } + File f = new File(pdfASDir); + if (!f.exists() || !f.isDirectory()) { + logger.error("PDF-AS working directory does not exist or is not a directory!: {}", pdfASDir); + throw new RuntimeException("PDF-AS working directory does not exists or is not a directory!"); + } + } + if (isWhiteListEnabled()) { - Iterator<Object> keyIt = properties.keySet().iterator(); - while (keyIt.hasNext()) { - Object keyObj = keyIt.next(); + for (Object keyObj : properties.keySet()) { if (keyObj != null) { String key = keyObj.toString(); if (key.startsWith(WHITELIST_VALUE_PRE)) { @@ -174,9 +195,7 @@ public class WebConfiguration implements IConfigurationConstants { } if (isAllowExtOverwrite()) { - Iterator<Object> keyIt = properties.keySet().iterator(); - while (keyIt.hasNext()) { - Object keyObj = keyIt.next(); + for (Object keyObj : properties.keySet()) { if (keyObj != null) { String key = keyObj.toString(); if (key.startsWith(ALLOW_EXT_WHITELIST_VALUE_PRE)) { @@ -190,9 +209,7 @@ public class WebConfiguration implements IConfigurationConstants { } } - Iterator<Object> keyIt = properties.keySet().iterator(); - while (keyIt.hasNext()) { - Object keyObj = keyIt.next(); + for (Object keyObj : properties.keySet()) { if (keyObj != null) { String key = keyObj.toString(); if (key.startsWith(HIBERNATE_PREFIX)) { @@ -207,9 +224,7 @@ public class WebConfiguration implements IConfigurationConstants { if (hibernateProps.size() != 0) { logger.debug("DB Properties: "); - Iterator<Object> hibkeyIt = hibernateProps.keySet().iterator(); - while (hibkeyIt.hasNext()) { - Object keyObj = hibkeyIt.next(); + for (Object keyObj : hibernateProps.keySet()) { if (keyObj != null) { String key = keyObj.toString(); String value = hibernateProps.getProperty(key); @@ -217,22 +232,6 @@ public class WebConfiguration implements IConfigurationConstants { } } } - - String pdfASDir = getPdfASDir(); - if (pdfASDir == null) { - logger.error("Please configure pdf as working directory in the web configuration"); - throw new RuntimeException( - "Please configure pdf as working directory in the web configuration"); - } - - File f = new File(pdfASDir); - - if (!f.exists() || !f.isDirectory()) { - logger.error("Pdf As working directory does not exists or is not a directory!: " - + pdfASDir); - throw new RuntimeException( - "Pdf As working directory does not exists or is not a directory!"); - } } public static String getPublicURL() { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index 4a4d15b2..5e7e3bd0 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -50,6 +50,7 @@ import jakarta.servlet.http.HttpSession; import jakarta.xml.bind.JAXBElement; import jakarta.xml.ws.WebServiceException; +import lombok.Getter; import lombok.val; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; @@ -157,7 +158,8 @@ public class PdfAsHelper { private static PdfAs pdfAs; private static ObjectFactory of = new ObjectFactory(); - private static Configuration pdfAsConfig; + @Getter + private static Configuration pdfAsConfig; static { reloadConfig(); @@ -171,17 +173,17 @@ public class PdfAsHelper { public static synchronized void reloadConfig() { log.info("Creating PDF-AS"); - pdfAs = PdfAsFactory.createPdfAs(new File(WebConfiguration - .getPdfASDir())); + val workdir = WebConfiguration.getPdfASDir(); + if (workdir == null) { + throw new IllegalStateException( + "WebConfiguration is not yet initialized. This is an application start-up order bug."); + } + pdfAs = PdfAsFactory.createPdfAs(new File(workdir)); pdfAsConfig = pdfAs.getConfiguration(); log.info("Creating PDF-AS done"); } - public static Configuration getPdfAsConfig() { - return pdfAsConfig; - } - - public static String buildPosString(HttpServletRequest request, + public static String buildPosString(HttpServletRequest request, HttpServletResponse response) throws PdfAsWebException { String posP = PdfAsParameterExtractor.getSigPosP(request); String posX = PdfAsParameterExtractor.getSigPosX(request); @@ -258,7 +260,7 @@ public class PdfAsHelper { + " has invalid value! (auto | new | last)"); } } - sb.append("p:" + posP.trim() + ";"); + sb.append("p:").append(posP.trim()).append(";"); } else { sb.append("p:auto;"); } @@ -273,7 +275,7 @@ public class PdfAsHelper { + " has invalid value!", e); } } - sb.append("r:" + posR.trim() + ";"); + sb.append("r:").append(posR.trim()).append(";"); } else { sb.append("r:0;"); } @@ -290,7 +292,7 @@ public class PdfAsHelper { sb.append("f:0;"); } } - sb.append("f:" + posF.trim() + ";"); + sb.append("f:").append(posF.trim()).append(";"); } else { sb.append("f:0;"); } @@ -324,9 +326,7 @@ public class PdfAsHelper { verifyParameter.setConfiguration(config); verifyParameter.setWhichSignature(signIdx); - List<VerifyResult> results = pdfAs.verify(verifyParameter); - - return results; + return pdfAs.verify(verifyParameter); } public static List<VerifyResult> synchronousVerify(byte[] pdfData, @@ -347,9 +347,7 @@ public class PdfAsHelper { verifyParameter.setConfiguration(config); verifyParameter.setWhichSignature(signIdx); - List<VerifyResult> results = pdfAs.verify(verifyParameter); - - return results; + return pdfAs.verify(verifyParameter); } public static PdfasSignResponse synchronousServerSignature(PdfasSignRequest internalReq) throws Exception { @@ -359,10 +357,9 @@ public class PdfAsHelper { respBuilder.transactionId(internalReq.getCoreParams().getTransactionId()); // sign each document - Iterator<DocumentToSign> docsToSign = internalReq.getInput().iterator(); - while(docsToSign.hasNext()) { - respBuilder.signedPdf(synchronousServerSignature(docsToSign.next(), internalReq.getCoreParams())); - + for (DocumentToSign documentToSign : internalReq.getInput()) { + respBuilder.signedPdf(synchronousServerSignature(documentToSign, internalReq.getCoreParams())); + } log.debug("Signing process finished."); @@ -529,19 +526,17 @@ public class PdfAsHelper { SignResult signResult = pdfAs.sign(signParameter); - PDFASVerificationResponse verResponse = new PDFASVerificationResponse(); - verResponse.setSignerCertificate(signResult.getSignerCertificate().getEncoded()); + PDFASVerificationResponse verResponse = new PDFASVerificationResponse(); + verResponse.setSignerCertificate(signResult.getSignerCertificate().getEncoded()); - - SignedDocument signPdfDoc = SignedDocument.builder() - .signingTimestamp(Long.valueOf(System.currentTimeMillis())) - .outputData(baos.toByteArray()) - .fileName(documentToSign.getFileName()) - .verificationResponse(verResponse) - .signerCertificate(Base64.encodeBase64String(signResult.getSignerCertificate().getEncoded())) - .build(); - - return signPdfDoc; + + return SignedDocument.builder() + .signingTimestamp(System.currentTimeMillis()) + .outputData(baos.toByteArray()) + .fileName(documentToSign.getFileName()) + .verificationResponse(verResponse) + .signerCertificate(Base64.encodeBase64String(signResult.getSignerCertificate().getEncoded())) + .build(); } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/json_api/JacksonConfig.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/json_api/JacksonConfig.java index ffb02c5f..9d316f74 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/json_api/JacksonConfig.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/json_api/JacksonConfig.java @@ -1,9 +1,8 @@ package at.gv.egiz.pdfas.web.json_api; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer; +import tools.jackson.databind.cfg.EnumFeature; +import tools.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,16 +10,16 @@ import org.springframework.context.annotation.Configuration; @Configuration public class JacksonConfig { @Bean - public Jackson2ObjectMapperBuilderCustomizer enumsShouldUseToStringToMatchXML() { - return b -> b.featuresToEnable( - SerializationFeature.WRITE_ENUMS_USING_TO_STRING, - DeserializationFeature.READ_ENUMS_USING_TO_STRING + public JsonMapperBuilderCustomizer enumsShouldUseToStringToMatchXML() { + return b -> b.enable( + EnumFeature.WRITE_ENUMS_USING_TO_STRING, + EnumFeature.READ_ENUMS_USING_TO_STRING ); } @Bean - public Jackson2ObjectMapperBuilderCustomizer useJaxbJsonNames() { - return b -> b.modulesToInstall( + public JsonMapperBuilderCustomizer useJaxbJsonNames() { + return b -> b.addModule( new JakartaXmlBindAnnotationModule() ); } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/web_xml_bridges/ContextXmlBridge.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/web_xml_bridges/ContextXmlBridge.java index 17e86c94..c9e06fb1 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/web_xml_bridges/ContextXmlBridge.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/web_xml_bridges/ContextXmlBridge.java @@ -2,7 +2,7 @@ package at.gv.egiz.pdfas.web.web_xml_bridges; import lombok.val; import org.apache.tomcat.util.http.Rfc6265CookieProcessor; -import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; +import org.springframework.boot.tomcat.TomcatContextCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; |
