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 | |
| 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
38 files changed, 177 insertions, 208 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c6addc3..e91f3b1e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,9 +22,9 @@ env: LC_ALL: "en_US.UTF-8" LANG: "en_US.UTF-8" LANGUAGE: "en_US" - LIB_NAME: "PDF-AS 4" + LIB_NAME: "PDF-AS 5" PROJECT_PATH: '.' - PROJECT_NAME: 'pdf-as-4' + PROJECT_NAME: 'pdf-as' jobs: security-checks: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e946a44..a4fa72a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,9 +7,9 @@ env: LC_ALL: "en_US.UTF-8" LANG: "en_US.UTF-8" LANGUAGE: "en_US" - LIB_NAME: "PDF-AS 4" + LIB_NAME: "PDF-AS 5" PROJECT_PATH: '.' - PROJECT_NAME: 'pdf-as-4' + PROJECT_NAME: 'pdf-as-5' jobs: release: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6b431215..b9ac20cf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ variables: LC_ALL: "en_US.UTF-8" LANG: "en_US.UTF-8" LANGUAGE: "en_US" - LIB_NAME: "PDF-AS 4" + LIB_NAME: "PDF-AS 5" GIT_DEPTH: "2" SECURE_LOG_LEVEL: "debug" @@ -32,7 +32,7 @@ https://joinup.ec.europa.eu/collection/e-government-innovation-center-egiz/solut #### 2. Push source code to public git -Run git push with tag also to https://git.egiz.gv.at/pdf-as-4/ (this is the public EGIZ GIT REPO) +Run git push with tag also to https://git.egiz.gv.at/pdf-as/ (this is the public EGIZ GIT REPO) #### 3. Add release notes to EGIZ or ASIT website! @@ -64,8 +64,8 @@ arguments: #### 4. Intellij Config for testing: * Main class: at.gv.egiz.pdfas.cli.Main -* Classpath: pdf-as-4-pdf-as-cli.pdfbox2 -* Parameters: -p SIGNATURBLOCK_DE_NOTE_DYNAMIC -c bku -m sign /Users/user/Documents/pdf-as-4/unsigned.pdf +* Classpath: pdf-as-5-pdf-as-cli.pdfbox3 +* Parameters: -p SIGNATURBLOCK_DE_NOTE_DYNAMIC -c bku -m sign /Users/user/Documents/pdf-as-5/unsigned.pdf * Needs local BKU (e.g. Mocca) * Uses configuration from /Users/user/.pdfas/ diff --git a/build.gradle b/build.gradle index 54621112..c970c082 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import com.github.spotbugs.snom.SpotBugsTask + plugins { id "com.github.ben-manes.versions" version "0.51.0" apply false id "com.github.spotbugs" version "6.0.0" @@ -32,9 +34,10 @@ allprojects { //tomcatVersion = '7.0.54'; //tomcatVersion = '8.0.36'; //tomcatVersion = '9.0.115'; - tomcatVersion = '10.1.54'; + //tomcatVersion = '10.1.54'; + tomcatVersion = '11.0.22' slf4jVersion = '2.0.16' - cxfVersion = '4.2.0' + cxfVersion = '4.2.1' bouncyCastleVersion = '1.82' commonsCollectionsVersion = '4.5.0' commonsLang3Version = '3.20.0' @@ -49,8 +52,9 @@ allprojects { ognlVersion = '3.3.5' jsonVersion = '20250517' micrometerVersion = '1.15.4' - springBootVersion = '3.5.13' - junitVersion = '4.13.2' + springBootVersion = '4.0.6' + junit4Version = '4.13.2' + junitVersion = '6.1.0' jakartaActivationVersion = '2.1.4' jakartaJwsVersion = '3.0.0' jakartaXmlWsVersion = '4.0.3' @@ -101,7 +105,7 @@ subprojects { reportLevel = "medium" } - tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { task -> + tasks.withType(SpotBugsTask).configureEach { task -> task.ignoreFailures = (System.getenv("CI") == "true") task.reports { xml.required = true @@ -114,6 +118,7 @@ subprojects { } tasks.withType(Test).configureEach { + useJUnitPlatform() finalizedBy jacocoTestReport } @@ -165,7 +170,11 @@ subprojects { implementation group: 'org.projectlombok', name: 'lombok', version: lombokVersion annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion - testImplementation group: 'junit', name: 'junit', version: junitVersion + testImplementation group: 'junit', name: 'junit', version: junit4Version + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion + testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher', version: junitVersion + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion + testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion } task sourcesJar(type: Jar, dependsOn: classes) { diff --git a/pdf-as-cli/build.gradle b/pdf-as-cli/build.gradle index 2eb4a01f..7f8d91fd 100644 --- a/pdf-as-cli/build.gradle +++ b/pdf-as-cli/build.gradle @@ -38,7 +38,6 @@ dependencies { implementation group: 'commons-cli', name: 'commons-cli', version: commonsCliVersion implementation group: 'jakarta.activation', name: 'jakarta.activation-api', version: jakartaActivationVersion implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion - testImplementation group: 'junit', name: 'junit', version: junitVersion } diff --git a/pdf-as-common/build.gradle b/pdf-as-common/build.gradle index 394280ee..8ff542b2 100644 --- a/pdf-as-common/build.gradle +++ b/pdf-as-common/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'eclipse' jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Commons' + attributes 'Implementation-Title': 'PDF-AS-5 Commons' } } @@ -28,7 +28,6 @@ dependencies { api group: 'commons-codec', name: 'commons-codec', version: commonsCodecVersion api group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: jaxbRuntimeVersion api group: 'jakarta.jws', name: 'jakarta.jws-api', version: jakartaJwsVersion - testImplementation group: 'junit', name: 'junit', version: junitVersion } test { diff --git a/pdf-as-lib/build.gradle b/pdf-as-lib/build.gradle index 204539d5..0688b2ef 100644 --- a/pdf-as-lib/build.gradle +++ b/pdf-as-lib/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'java-library-distribution' jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Library', 'JARMANIFEST': 'PDF-AS-LIB' + attributes 'Implementation-Title': 'PDF-AS-5 Library', 'JARMANIFEST': 'PDF-AS-LIB' } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/package-info.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/package-info.java index a1bd53c7..d39034e4 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/package-info.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/package-info.java @@ -22,6 +22,6 @@ * that you distribute must include a readable copy of the "NOTICE" text file. ******************************************************************************/ /** - * PDF-AS 4.0 Main package name + * PDF-AS 5.0 Main package name */ package at.gv.egiz.pdfas.lib; diff --git a/pdf-as-moa/build.gradle b/pdf-as-moa/build.gradle index 7885f697..8a5d211d 100644 --- a/pdf-as-moa/build.gradle +++ b/pdf-as-moa/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'java-library-distribution' jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 MOA Library', 'JARMANIFEST': 'PDF-AS-LIB' + attributes 'Implementation-Title': 'PDF-AS-5 MOA Library', 'JARMANIFEST': 'PDF-AS-LIB' } } @@ -61,8 +61,6 @@ dependencies { implementation group: 'org.apache.commons', name: 'commons-lang3', version: commonsLang3Version api group: 'org.apache.commons', name: 'commons-text', version: commonsTextVersion - testImplementation group: 'junit', name: 'junit', version: junitVersion - // Apache CXF tools for WSDL processing - updated to Jakarta EE compatible version ws group: 'org.apache.cxf', name: 'cxf-tools', version: cxfVersion ws group: 'org.apache.cxf', name: 'cxf-tools-wsdlto-databinding-jaxb', version: cxfVersion diff --git a/pdf-as-moa/src/generated/java/org/w3/_2000/_09/xmldsig_/PGPDataType.java b/pdf-as-moa/src/generated/java/org/w3/_2000/_09/xmldsig_/PGPDataType.java index 12c4d7db..0ba7227f 100644 --- a/pdf-as-moa/src/generated/java/org/w3/_2000/_09/xmldsig_/PGPDataType.java +++ b/pdf-as-moa/src/generated/java/org/w3/_2000/_09/xmldsig_/PGPDataType.java @@ -52,8 +52,8 @@ public class PGPDataType { * <p> * You are getting this "catch-all" property because of the following reason: * The field name "PGPKeyPacket" is used by two different parts of a schema. See: - * line 184 of file:/home/gpalfinger/Documents/pdf-as-4-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd - * line 180 of file:/home/gpalfinger/Documents/pdf-as-4-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd + * line 184 of file:/home/gpalfinger/Documents/pdf-as-5-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd + * line 180 of file:/home/gpalfinger/Documents/pdf-as-5-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd * <p> * To get rid of this property, apply a property customization to one * of both of the following declarations to change their names: @@ -72,8 +72,8 @@ public class PGPDataType { * <p> * You are getting this "catch-all" property because of the following reason: * The field name "PGPKeyPacket" is used by two different parts of a schema. See: - * line 184 of file:/home/gpalfinger/Documents/pdf-as-4-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd - * line 180 of file:/home/gpalfinger/Documents/pdf-as-4-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd + * line 184 of file:/home/gpalfinger/Documents/pdf-as-5-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd + * line 180 of file:/home/gpalfinger/Documents/pdf-as-5-kiro/pdf-as-moa/src/main/resources/wsdl/W3C-XMLDSig.xsd * <p> * To get rid of this property, apply a property customization to one * of both of the following declarations to change their names: diff --git a/pdf-as-pdfbox-2/build.gradle b/pdf-as-pdfbox-2/build.gradle index 67bb265d..43dba994 100644 --- a/pdf-as-pdfbox-2/build.gradle +++ b/pdf-as-pdfbox-2/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'eclipse' jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 PDFBOX 2 Backend' + attributes 'Implementation-Title': 'PDF-AS-5 PDFBOX 2 Backend' } // from { diff --git a/pdf-as-pdfbox-3/build.gradle.kts b/pdf-as-pdfbox-3/build.gradle.kts index c1888ac9..093fc795 100644 --- a/pdf-as-pdfbox-3/build.gradle.kts +++ b/pdf-as-pdfbox-3/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { implementation("org.apache.pdfbox", "pdfbox-tools", pdfboxVersion) implementation("org.apache.pdfbox", "xmpbox", pdfboxVersion) implementation("org.apache.pdfbox", "preflight", pdfboxVersion) + implementation("org.apache.pdfbox", "jbig2-imageio", "3.0.5") testImplementation("ch.qos.logback", "logback-classic", project.ext["logbackVersion"] as String) testImplementation(project(":signature-standards:sigs-pades")) @@ -31,9 +32,6 @@ tasks.register("releases", Copy::class) { into(rootDir.resolve("releases/$version")) } -tasks.test { - useJUnit() -} kotlin { jvmToolchain(17) }
\ No newline at end of file diff --git a/pdf-as-tests/build.gradle b/pdf-as-tests/build.gradle index 1cc793f7..aad47bb2 100644 --- a/pdf-as-tests/build.gradle +++ b/pdf-as-tests/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'eclipse' jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Test Library', 'JARMANIFEST': 'PDF-AS-LIB' + attributes 'Implementation-Title': 'PDF-AS-5 Test Library', 'JARMANIFEST': 'PDF-AS-LIB' } } diff --git a/pdf-as-web-client/build.gradle b/pdf-as-web-client/build.gradle index 8d9628ad..1618b41d 100644 --- a/pdf-as-web-client/build.gradle +++ b/pdf-as-web-client/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'eclipse' jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 WEB CLIENT', 'JARMANIFEST': 'PDF-AS-WEB-CLIENT' + attributes 'Implementation-Title': 'PDF-AS-5 WEB CLIENT', 'JARMANIFEST': 'PDF-AS-WEB-CLIENT' } } diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java index 3c0223fd..b993e5de 100644 --- a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java @@ -46,7 +46,7 @@ public class SimpleTestSOAP { public static void main(String[] args) { try { - String file = "/Users/amarsalek/Documents/pdf-as-4/unsigned.pdf"; + String file = "/Users/amarsalek/Documents/pdf-as-5/unsigned.pdf"; // String file = "/Users/amarsalek/Downloads/qr2.pdf"; FileInputStream fis = new FileInputStream(file); byte[] inputData = IOUtils.toByteArray(fis); diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java index 17278303..0a33a260 100644 --- a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java @@ -39,7 +39,7 @@ public class SimpleTestSOAPInvalidParameter { public static void main(String[] args) { try { - String file = "/Users/amarsalek/Documents/pdf-as-4/unsigned.pdf"; + String file = "/Users/amarsalek/Documents/pdf-as-5/unsigned.pdf"; FileInputStream fis = new FileInputStream(file); byte[] inputData = IOUtils.toByteArray(fis); diff --git a/pdf-as-web-db/build.gradle b/pdf-as-web-db/build.gradle index 78611668..d1633c7a 100644 --- a/pdf-as-web-db/build.gradle +++ b/pdf-as-web-db/build.gradle @@ -6,7 +6,7 @@ plugins { jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Web Extension Library', 'JARMANIFEST': 'PDF-AS-LIB' + attributes 'Implementation-Title': 'PDF-AS-5 Web Extension Library', 'JARMANIFEST': 'PDF-AS-LIB' } } diff --git a/pdf-as-web-statistic-api/build.gradle b/pdf-as-web-statistic-api/build.gradle index 82216460..75a38b79 100644 --- a/pdf-as-web-statistic-api/build.gradle +++ b/pdf-as-web-statistic-api/build.gradle @@ -7,7 +7,7 @@ plugins { jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Web Statistic Library', 'JARMANIFEST': 'PDF-AS-LIB' + attributes 'Implementation-Title': 'PDF-AS-5 Web Statistic Library', 'JARMANIFEST': 'PDF-AS-LIB' } } @@ -25,7 +25,6 @@ sourceSets.test.runtimeClasspath += configurations.providedCompile dependencies { implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion implementation group: 'org.apache.commons', name: 'commons-lang3', version: commonsLang3Version - testImplementation group: 'junit', name: 'junit', version: junitVersion } task releases(type: Copy) { diff --git a/pdf-as-web-status/build.gradle b/pdf-as-web-status/build.gradle index ca227397..e6977da8 100644 --- a/pdf-as-web-status/build.gradle +++ b/pdf-as-web-status/build.gradle @@ -7,7 +7,7 @@ plugins { jar { manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Web Status Library', 'JARMANIFEST': 'PDF-AS-LIB' + attributes 'Implementation-Title': 'PDF-AS-5 Web Status Library', 'JARMANIFEST': 'PDF-AS-LIB' } } diff --git a/pdf-as-web/build.gradle b/pdf-as-web/build.gradle index 4537e047..a5a56450 100644 --- a/pdf-as-web/build.gradle +++ b/pdf-as-web/build.gradle @@ -76,17 +76,16 @@ dependencies { api group: 'org.json', name: 'json', version: jsonVersion api group: 'jakarta.jws', name: 'jakarta.jws-api', version: jakartaJwsVersion compileOnly group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: jakartaServletVersion - implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion - implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webmvc', version: springBootVersion + providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: springBootVersion implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.16' - implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: tomcatVersion + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.3' + providedRuntime group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: tomcatVersion implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.2' implementation 'org.glassfish.web:jakarta.servlet.jsp.jstl:3.0.1' - implementation 'com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations' + implementation 'tools.jackson.module:jackson-module-jakarta-xmlbind-annotations' testImplementation group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: jakartaServletVersion - testImplementation 'org.springframework:spring-test' - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-webmvc-test', version: springBootVersion testImplementation group: 'org.apache.cxf', name: 'cxf-rt-transports-http-jetty', version: cxfVersion } diff --git a/pdf-as-web/src/main/assembly/tomcat/catalina.env b/pdf-as-web/src/main/assembly/tomcat/catalina.env index 61e37593..5892da05 100644 --- a/pdf-as-web/src/main/assembly/tomcat/catalina.env +++ b/pdf-as-web/src/main/assembly/tomcat/catalina.env @@ -7,5 +7,4 @@ export CATALINA_OPTS="\ -Xss1024K \ -Xms128M \ -Xmx2048M \ - -XX:MaxPermSize=256m \ " diff --git a/pdf-as-web/src/main/assembly/tomcat/setVariables.bat b/pdf-as-web/src/main/assembly/tomcat/setVariables.bat index 57bd2f9a..e6a8ba03 100644 --- a/pdf-as-web/src/main/assembly/tomcat/setVariables.bat +++ b/pdf-as-web/src/main/assembly/tomcat/setVariables.bat @@ -55,14 +55,11 @@ set JVM_XMS=128 rem Maximum memory pool size in MB
set JVM_XMX=2048
-rem Maximum PermGenSize in M
-set JVM_MAXPERMSIZE=256
-
rem COMMAND LINE OPTIONS
-set JAVA_OPTS=-server -Xss%JVM_XSS%k -Xms%JVM_XMS%m -Xmx%JVM_XMX%m -XX:MaxPermSize=%JVM_MAXPERMSIZE%m -Dfile.encoding=UTF8
+set JAVA_OPTS=-server -Xss%JVM_XSS%k -Xms%JVM_XMS%m -Xmx%JVM_XMX%m -Dfile.encoding=UTF8
set CATALINA_OPTS=%PDFAS_WORK_DIR_PARAM%
rem SERVICE OPTIONS
-set SERVICE_OPTS=%PDFAS_WORK_DIR_PARAM%;-XX:MaxPermSize=%JVM_MAXPERMSIZE%m -Dfile.encoding=UTF8
+set SERVICE_OPTS=%PDFAS_WORK_DIR_PARAM%;-Dfile.encoding=UTF8
:END
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; diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleSignServletTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleSignServletTest.java index a311429d..a99e79a7 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleSignServletTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleSignServletTest.java @@ -8,10 +8,9 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.SneakyThrows; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockHttpServletRequest; @@ -23,15 +22,13 @@ import at.gv.egiz.pdfas.web.stats.StatisticEvent.Operation; import at.gv.egiz.pdfas.web.stats.StatisticEvent.Source; import org.springframework.mock.web.MockServletConfig; import org.springframework.mock.web.MockServletContext; -import org.springframework.test.context.junit4.SpringRunner; //@Ignore -@RunWith(SpringRunner.class) @SpringBootTest -public class SimpleSignServletTest { +class SimpleSignServletTest { - @BeforeClass + @BeforeAll public static void classInitializer() throws IOException { final String current = new java.io.File(".").getCanonicalPath(); System.setProperty("pdf-as-web.conf", @@ -39,7 +36,7 @@ public class SimpleSignServletTest { } - @Before + @BeforeEach @SneakyThrows public void setup() { servlet.init( diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java index b9d7c152..64ab9153 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java @@ -5,9 +5,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Enumeration; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -15,10 +13,7 @@ import jakarta.servlet.http.HttpServletResponse; import lombok.val; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockHttpServletRequest; @@ -31,21 +26,19 @@ import at.gv.egiz.pdfas.web.stats.StatisticEvent.Source; import lombok.SneakyThrows; import org.springframework.mock.web.MockServletConfig; import org.springframework.mock.web.MockServletContext; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest -public class SimpleVerifyServletTest { +class SimpleVerifyServletTest { - @BeforeClass + @BeforeAll public static void classInitializer() throws IOException { final String current = new java.io.File(".").getCanonicalPath(); System.setProperty("pdf-as-web.conf", current + "/src/test/resources/config/pdfas/pdf-as-web.properties"); } - @Before + @BeforeEach @SneakyThrows public void setup() { servlet.init( @@ -92,10 +85,10 @@ public class SimpleVerifyServletTest { performTest(httpReq, httpResp, pdf); //validate state - assertNotNull("httpResp", httpResp); - assertEquals("httpStatus", 200, httpResp.getStatus()); + Assertions.assertNotNull(httpResp, "httpResp"); + Assertions.assertEquals(200, httpResp.getStatus(), "httpStatus"); String body = httpResp.getContentAsString(); - assertFalse("Empty body", StringUtils.isEmpty(body)); + Assertions.assertFalse(StringUtils.isEmpty(body), "Empty body"); return httpResp; diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonApiTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonApiTest.java index cfb0a375..18eff611 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonApiTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonApiTest.java @@ -2,22 +2,20 @@ package at.gv.egiz.pdfas.web.test; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.junit.Assert.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Assertions; +import tools.jackson.databind.json.JsonMapper; import com.jayway.jsonpath.JsonPath; import lombok.Lombok; import lombok.SneakyThrows; import lombok.val; import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import java.io.File; @@ -26,7 +24,6 @@ import java.util.Base64; import java.util.Map; import java.util.UUID; -@RunWith(SpringRunner.class) @SpringBootTest(properties = { "management.endpoint.metrics.enabled=true", "management.endpoints.web.exposure.include=metrics" @@ -34,7 +31,7 @@ import java.util.UUID; @AutoConfigureMockMvc public class JsonApiTest extends TestUtils.CanWatchOperationCount { @Autowired MockMvc mvc; - @Autowired ObjectMapper om; + @Autowired JsonMapper om; static { try { @@ -78,8 +75,9 @@ public class JsonApiTest extends TestUtils.CanWatchOperationCount { .andReturn().getResponse().getContentAsString(); final byte[] signedPDF = Base64.getDecoder().decode(JsonPath.<String>read(signResponse, "$.signedPDF")); - assertArrayEquals("Signed data looks PDF-ish (%PDF- header)", - new byte[]{'%', 'P', 'D', 'F', '-'}, Arrays.copyOfRange(signedPDF, 0, 5)); + Assertions.assertArrayEquals( + new byte[]{'%', 'P', 'D', 'F', '-'}, Arrays.copyOfRange(signedPDF, 0, 5), + "Signed data looks PDF-ish (%PDF- header)"); } } diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonSoapParameterNamingTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonSoapParameterNamingTest.java index cd775eda..36aa85c3 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonSoapParameterNamingTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/JsonSoapParameterNamingTest.java @@ -13,18 +13,16 @@ import at.gv.egiz.pdfas.api.ws.PdfasSignMultipleRequest; import at.gv.egiz.pdfas.api.ws.PdfasSignMultipleResponse; import at.gv.egiz.pdfas.api.ws.PdfasSignedDocument; import at.gv.egiz.pdfas.api.ws.VerificationLevel; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.JsonNode; +import tools.jackson.databind.json.JsonMapper; import java.io.File; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; import lombok.Lombok; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * Verifies that the JSON API wire names match the SOAP/JAXB wire names. @@ -34,16 +32,15 @@ import org.springframework.test.context.junit4.SpringRunner; * {@code invoke-url}, {@code preprocessorArguments}, {@code configurationOverrides}, and {@code documents}. * * <p>Expected current-state behavior: this test fails until the SOAP DTOs either carry explicit Jackson - * annotations or the web ObjectMapper is configured to honor JAXB annotations for JSON naming. Keep old JSON + * annotations or the web JsonMapper is configured to honor JAXB annotations for JSON naming. Keep old JSON * names as aliases when implementing the fix so existing clients remain compatible. */ -@RunWith(SpringRunner.class) @SpringBootTest(properties = { "management.endpoint.metrics.enabled=true", "management.endpoints.web.exposure.include=metrics" }) public class JsonSoapParameterNamingTest { - @Autowired ObjectMapper om; + @Autowired JsonMapper om; static { try { diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java index 46b0e405..e6bfa4c6 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java @@ -7,7 +7,8 @@ import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; import at.gv.egiz.pdfas.web.config.PdfAsWebSpringConfiguration; import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeAll; +import tools.jackson.databind.json.JsonMapper; import com.jayway.jsonpath.JsonPath; import iaik.x509.X509Certificate; import jakarta.jws.WebService; @@ -16,15 +17,12 @@ import lombok.Lombok; import lombok.SneakyThrows; import lombok.val; import org.apache.commons.io.IOUtils; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import java.io.*; @@ -33,11 +31,9 @@ import java.security.KeyStore; import java.security.PrivateKey; import java.util.*; -import static org.junit.Assert.assertArrayEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -@RunWith(SpringRunner.class) @SpringBootTest(properties = { "management.endpoint.metrics.enabled=true", "management.endpoints.web.exposure.include=metrics" @@ -45,7 +41,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @AutoConfigureMockMvc public class MockMoaSigningTest extends TestUtils.CanWatchOperationCount { @Autowired MockMvc mvc; - @Autowired ObjectMapper om; + @Autowired JsonMapper om; @Autowired PdfAsWebSpringConfiguration config; static { @@ -57,7 +53,7 @@ public class MockMoaSigningTest extends TestUtils.CanWatchOperationCount { } } - @BeforeClass + @BeforeAll public static void jceWorkaround() { System.setProperty("javax.net.ssl.trustStoreType", "JKS"); } @@ -207,8 +203,9 @@ public class MockMoaSigningTest extends TestUtils.CanWatchOperationCount { .andReturn().getResponse().getContentAsString(); final byte[] signedPDF = Base64.getDecoder().decode(JsonPath.<String>read(signResponse, "$.signedPDF")); - assertArrayEquals("Signed data looks PDF-ish (%PDF- header)", - new byte[]{'%', 'P', 'D', 'F', '-'}, Arrays.copyOfRange(signedPDF, 0, 5)); + Assertions.assertArrayEquals( + new byte[]{'%', 'P', 'D', 'F', '-'}, Arrays.copyOfRange(signedPDF, 0, 5), + "Signed data looks PDF-ish (%PDF- header)"); } } diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java index 9c65fe0d..9319f8cf 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java @@ -8,13 +8,11 @@ import java.net.URL; import java.util.UUID; import at.gv.egiz.pdfas.api.ws.PDFASSigning; -import at.gv.egiz.pdfas.web.servlets.SimpleVerifyServletTest; import jakarta.xml.ws.Service; import lombok.val; import org.apache.commons.io.IOUtils; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; @@ -23,22 +21,20 @@ import at.gv.egiz.pdfas.api.ws.PDFASSignResponse; import lombok.SneakyThrows; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.test.context.junit4.SpringRunner; import javax.xml.namespace.QName; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class SimpleWebServiceTest { +class SimpleWebServiceTest { - @BeforeClass + @BeforeAll public static void classInitializer() throws IOException { final String current = new java.io.File(".").getCanonicalPath(); System.setProperty("pdf-as-web.conf", current + "/src/test/resources/config/pdfas/pdf-as-web.properties"); } - @BeforeClass + @BeforeAll public static void jceWorkaround() { System.setProperty("javax.net.ssl.trustStoreType", "JKS"); } @@ -49,7 +45,7 @@ public class SimpleWebServiceTest { @Test @SneakyThrows public void sign() { - byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf")); + byte[] pdf = IOUtils.toByteArray(SimpleWebServiceTest.class.getResourceAsStream("/data/enc_own.pdf")); PDFASSignResponse resp = executeTest(pdf); assertNotNull("signed doc", resp.getSignedPDF()); assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode()); @@ -60,7 +56,7 @@ public class SimpleWebServiceTest { @Test @SneakyThrows public void withSignatureFields() { - byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf")); + byte[] pdf = IOUtils.toByteArray(SimpleWebServiceTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf")); PDFASSignResponse resp = executeTest(pdf); assertNotNull("signed doc", resp.getSignedPDF()); assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode()); diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java index cd2ba077..0fb3f3af 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java @@ -8,13 +8,11 @@ import java.net.URL; import java.util.UUID; import at.gv.egiz.pdfas.api.ws.PDFASSigning; -import at.gv.egiz.pdfas.web.servlets.SimpleVerifyServletTest; import jakarta.xml.ws.Service; import lombok.val; import org.apache.commons.io.IOUtils; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; @@ -23,22 +21,20 @@ import at.gv.egiz.pdfas.api.ws.PDFASSignResponse; import lombok.SneakyThrows; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.test.context.junit4.SpringRunner; import javax.xml.namespace.QName; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class SimpleWebServiceWithoutVerificationTest { +class SimpleWebServiceWithoutVerificationTest { - @BeforeClass + @BeforeAll public static void classInitializer() throws IOException { final String current = new java.io.File(".").getCanonicalPath(); System.setProperty("pdf-as-web.conf", current + "/src/test/resources/config/pdfas/pdf-as-web-verify-disabled.properties"); } - @BeforeClass + @BeforeAll public static void jceWorkaround() { System.setProperty("javax.net.ssl.trustStoreType", "JKS"); } @@ -49,7 +45,7 @@ public class SimpleWebServiceWithoutVerificationTest { @Test @SneakyThrows public void sign() { - byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf")); + byte[] pdf = IOUtils.toByteArray(SimpleWebServiceWithoutVerificationTest.class.getResourceAsStream("/data/enc_own.pdf")); PDFASSignResponse resp = executeTest(pdf); assertNotNull("signed doc", resp.getSignedPDF()); assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode()); @@ -60,7 +56,7 @@ public class SimpleWebServiceWithoutVerificationTest { @Test @SneakyThrows public void withSignatureFields() { - byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf")); + byte[] pdf = IOUtils.toByteArray(SimpleWebServiceWithoutVerificationTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf")); PDFASSignResponse resp = executeTest(pdf); assertNotNull("signed doc", resp.getSignedPDF()); assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode()); diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/TestUtils.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/TestUtils.java index f6196ca9..900b1f82 100644 --- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/TestUtils.java +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/TestUtils.java @@ -4,11 +4,11 @@ import at.gv.egiz.pdfas.web.stats.impl.StatisticMicrometerBackend; import com.jayway.jsonpath.JsonPath; import io.micrometer.core.instrument.MeterRegistry; import lombok.val; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -22,7 +22,7 @@ public class TestUtils { val result = mvc.perform(builder).andReturn().getResponse(); if (result.getStatus() == 404) return 0.0; - Assert.assertEquals(200, result.getStatus()); + Assertions.assertEquals(200, result.getStatus()); return JsonPath.<List<Double>>read( result.getContentAsString(), "$.measurements[?(@.statistic == 'COUNT')].value") @@ -34,13 +34,13 @@ public class TestUtils { public static abstract class CanWatchOperationCount { @Autowired MockMvc mvc; @Autowired private MeterRegistry meterRegistry; - @Before + @BeforeEach public void rebindStatisticsBackend() { StatisticMicrometerBackend.SpringContextProxy.meterRegistry = meterRegistry; } protected AutoCloseable OperationCountWatcher(String... tags) throws Exception { val initialCount = TestUtils.getOperationCount(mvc, tags); - return () -> Assert.assertEquals(initialCount+1.0, TestUtils.getOperationCount(mvc, tags), 0.0001); + return () -> Assertions.assertEquals(initialCount+1.0, TestUtils.getOperationCount(mvc, tags), 0.0001); } } } diff --git a/signature-standards/sigs-pades/build.gradle b/signature-standards/sigs-pades/build.gradle index 9bef553c..9531330a 100644 --- a/signature-standards/sigs-pades/build.gradle +++ b/signature-standards/sigs-pades/build.gradle @@ -27,7 +27,6 @@ dependencies { implementation project(':pdf-as-common') implementation group: 'org.apache.commons', name: 'commons-collections4', version: commonsCollectionsVersion implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion - testImplementation group: 'junit', name: 'junit', version: junitVersion } test { diff --git a/signature-standards/sigs-pkcs7detached/build.gradle b/signature-standards/sigs-pkcs7detached/build.gradle index d60397a4..ac29931d 100644 --- a/signature-standards/sigs-pkcs7detached/build.gradle +++ b/signature-standards/sigs-pkcs7detached/build.gradle @@ -27,7 +27,6 @@ dependencies { implementation project(':pdf-as-common') implementation group: 'org.apache.commons', name: 'commons-collections4', version: commonsCollectionsVersion implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion - testImplementation group: 'junit', name: 'junit', version: junitVersion } test { |
