From c7e5987342d073d71e257fd1403d9fd4a5e7db6f Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:52:45 +0200 Subject: [PATCH] Cleanup logs (#1739) * fix * cleanups! --------- Co-authored-by: a --- build.gradle | 35 ++++++++++--------- .../software/SPDF/SPdfApplication.java | 1 + .../security/SecurityConfiguration.java | 12 +------ .../api/pipeline/ApiDocService.java | 2 +- .../model/api/converters/UrlToPdfRequest.java | 4 ++- .../model/api/filter/ContainsTextRequest.java | 2 +- .../model/api/filter/FileSizeRequest.java | 2 +- .../model/api/filter/PageRotationRequest.java | 2 +- .../model/api/filter/PageSizeRequest.java | 2 +- .../model/api/general/OverlayPdfsRequest.java | 4 +-- .../general/SplitPdfBySizeOrCountRequest.java | 4 +-- .../SPDF/model/api/misc/AddStampRequest.java | 2 +- .../model/api/misc/AutoSplitPdfRequest.java | 2 +- .../model/api/misc/ExtractHeaderRequest.java | 2 +- .../api/misc/ExtractImageScansRequest.java | 4 ++- .../SPDF/model/api/misc/PrintFileRequest.java | 4 ++- .../api/security/AddWatermarkRequest.java | 2 +- .../api/security/PDFPasswordRequest.java | 4 ++- .../model/api/security/RedactPdfRequest.java | 5 ++- .../software/SPDF/utils/GeneralUtils.java | 3 +- src/main/resources/application.properties | 10 ++++-- 21 files changed, 59 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index 2ba8a505..43c1b2e1 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { id "edu.sc.seis.launch4j" version "3.0.6" id "com.diffplug.spotless" version "6.25.0" id "com.github.jk1.dependency-license-report" version "2.9" + //id "nebula.lint" version "19.0.3" } import com.github.jk1.license.render.* @@ -100,14 +101,20 @@ spotless { } } +//gradleLint { +// rules=['unused-dependency'] +// } tasks.wrapper { gradleVersion = "8.7" } - +//tasks.withType(JavaCompile) { +// options.compilerArgs << "-Xlint:deprecation" +//} +configurations.all { + exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" +} dependencies { //security updates - implementation "ch.qos.logback:logback-classic:$logbackVersion" - implementation "ch.qos.logback:logback-core:$logbackVersion" implementation "org.springframework:spring-webmvc:6.1.9" implementation("io.github.pixee:java-security-toolkit:1.2.0") @@ -116,36 +123,33 @@ dependencies { implementation 'com.github.Carleslc.Simple-YAML:Simple-Yaml:1.8.4' // Exclude Tomcat and include Jetty - implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") { - exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" - } + implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") implementation "org.springframework.boot:spring-boot-starter-jetty:$springBootVersion" implementation "org.springframework.boot:spring-boot-starter-thymeleaf:$springBootVersion" if (System.getenv("DOCKER_ENABLE_SECURITY") != "false") { implementation "org.springframework.boot:spring-boot-starter-security:$springBootVersion" - implementation "org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.1.2.RELEASE" + runtimeOnly "org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.1.2.RELEASE" implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion" implementation "org.springframework.boot:spring-boot-starter-oauth2-client:$springBootVersion" //2.2.x requires rebuild of DB file.. need migration path - implementation "com.h2database:h2:2.1.214" + runtimeOnly "com.h2database:h2:2.1.214" // implementation "com.h2database:h2:2.2.224" } testImplementation "org.springframework.boot:spring-boot-starter-test:$springBootVersion" // Batik - implementation "org.apache.xmlgraphics:batik-all:1.17" // TwelveMonkeys - implementation "com.twelvemonkeys.imageio:imageio-batik:$imageioVersion" - implementation "com.twelvemonkeys.imageio:imageio-bmp:$imageioVersion" + runtimeOnly "com.twelvemonkeys.imageio:imageio-batik:$imageioVersion" + runtimeOnly "com.twelvemonkeys.imageio:imageio-bmp:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-hdr:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-icns:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-iff:$imageioVersion" - implementation "com.twelvemonkeys.imageio:imageio-jpeg:$imageioVersion" + runtimeOnly "com.twelvemonkeys.imageio:imageio-jpeg:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-pcx:$imageioVersion@ // implementation "com.twelvemonkeys.imageio:imageio-pict:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-pnm:$imageioVersion" @@ -153,13 +157,12 @@ dependencies { // implementation "com.twelvemonkeys.imageio:imageio-sgi:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-tga:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-thumbsdb:$imageioVersion" - implementation "com.twelvemonkeys.imageio:imageio-tiff:$imageioVersion" - implementation "com.twelvemonkeys.imageio:imageio-webp:$imageioVersion" + runtimeOnly "com.twelvemonkeys.imageio:imageio-tiff:$imageioVersion" + runtimeOnly "com.twelvemonkeys.imageio:imageio-webp:$imageioVersion" // implementation "com.twelvemonkeys.imageio:imageio-xwd:$imageioVersion" implementation "commons-io:commons-io:2.16.1" implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0" - //general PDF // https://mvnrepository.com/artifact/com.opencsv/opencsv @@ -196,7 +199,7 @@ dependencies { compileOnly "org.projectlombok:lombok:$lombokVersion" annotationProcessor "org.projectlombok:lombok:$lombokVersion" - testImplementation 'org.mockito:mockito-inline:5.2.0' + testRuntimeOnly 'org.mockito:mockito-inline:5.2.0' } tasks.withType(JavaCompile).configureEach { diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index 3410b950..6c90ee3c 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -65,6 +65,7 @@ public class SPdfApplication { public static void main(String[] args) throws IOException, InterruptedException { SpringApplication app = new SpringApplication(SPdfApplication.class); + app.setAdditionalProfiles("default"); app.addInitializers(new ConfigInitializer()); Map propertyFiles = new HashMap<>(); diff --git a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java index 1e0ff786..ed7b7921 100644 --- a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java @@ -10,7 +10,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -150,8 +149,7 @@ public class SecurityConfiguration { }) .permitAll() .anyRequest() - .authenticated()) - .authenticationProvider(authenticationProvider()); + .authenticated()); // Handle OAUTH2 Logins if (applicationProperties.getSecurity().getOAUTH2() != null @@ -379,14 +377,6 @@ public class SecurityConfiguration { return new IPRateLimitingFilter(maxRequestsPerIp, maxRequestsPerIp); } - @Bean - public DaoAuthenticationProvider authenticationProvider() { - DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); - authProvider.setUserDetailsService(userDetailsService); - authProvider.setPasswordEncoder(passwordEncoder()); - return authProvider; - } - @Bean public PersistentTokenRepository persistentTokenRepository() { return new JPATokenRepositoryImpl(); diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java index c773c976..771d7b45 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java @@ -43,7 +43,7 @@ public class ApiDocService { Map> outputToFileTypes = new HashMap<>(); - public List getExtensionTypes(boolean output, String operationName) { + public List getExtensionTypes(boolean output, String operationName) { if (outputToFileTypes.size() == 0) { outputToFileTypes.put("PDF", Arrays.asList("pdf")); outputToFileTypes.put( diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java index 3e340868..954045f0 100644 --- a/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/converters/UrlToPdfRequest.java @@ -9,6 +9,8 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode public class UrlToPdfRequest { - @Schema(description = "The input URL to be converted to a PDF file", required = true) + @Schema( + description = "The input URL to be converted to a PDF file", + requiredMode = Schema.RequiredMode.REQUIRED) private String urlInput; } diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java index 7cd2f76a..0537362d 100644 --- a/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/filter/ContainsTextRequest.java @@ -10,6 +10,6 @@ import stirling.software.SPDF.model.api.PDFWithPageNums; @EqualsAndHashCode(callSuper = true) public class ContainsTextRequest extends PDFWithPageNums { - @Schema(description = "The text to check for", required = true) + @Schema(description = "The text to check for", requiredMode = Schema.RequiredMode.REQUIRED) private String text; } diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java index 00d75139..b92d2ce2 100644 --- a/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/filter/FileSizeRequest.java @@ -10,6 +10,6 @@ import stirling.software.SPDF.model.api.PDFComparison; @EqualsAndHashCode(callSuper = true) public class FileSizeRequest extends PDFComparison { - @Schema(description = "File Size", required = true) + @Schema(description = "File Size", requiredMode = Schema.RequiredMode.REQUIRED) private String fileSize; } diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java index 949178c5..64692d45 100644 --- a/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/filter/PageRotationRequest.java @@ -10,6 +10,6 @@ import stirling.software.SPDF.model.api.PDFComparison; @EqualsAndHashCode(callSuper = true) public class PageRotationRequest extends PDFComparison { - @Schema(description = "Rotation in degrees", required = true) + @Schema(description = "Rotation in degrees", requiredMode = Schema.RequiredMode.REQUIRED) private int rotation; } diff --git a/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java b/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java index c8b46a90..d8f214f0 100644 --- a/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/filter/PageSizeRequest.java @@ -10,6 +10,6 @@ import stirling.software.SPDF.model.api.PDFComparison; @EqualsAndHashCode(callSuper = true) public class PageSizeRequest extends PDFComparison { - @Schema(description = "Standard Page Size", required = true) + @Schema(description = "Standard Page Size", requiredMode = Schema.RequiredMode.REQUIRED) private String standardPageSize; } diff --git a/src/main/java/stirling/software/SPDF/model/api/general/OverlayPdfsRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/OverlayPdfsRequest.java index 458dd699..37216201 100644 --- a/src/main/java/stirling/software/SPDF/model/api/general/OverlayPdfsRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/general/OverlayPdfsRequest.java @@ -20,13 +20,13 @@ public class OverlayPdfsRequest extends PDFFile { @Schema( description = "The mode of overlaying: 'SequentialOverlay' for sequential application, 'InterleavedOverlay' for round-robin application, 'FixedRepeatOverlay' for fixed repetition based on provided counts", - required = true) + requiredMode = Schema.RequiredMode.REQUIRED) private String overlayMode; @Schema( description = "An array of integers specifying the number of times each corresponding overlay file should be applied in the 'FixedRepeatOverlay' mode. This should match the length of the overlayFiles array.", - required = false) + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private int[] counts; @Schema(description = "Overlay position 0 is Foregound, 1 is Background") diff --git a/src/main/java/stirling/software/SPDF/model/api/general/SplitPdfBySizeOrCountRequest.java b/src/main/java/stirling/software/SPDF/model/api/general/SplitPdfBySizeOrCountRequest.java index 8b36c1c8..3bb141e7 100644 --- a/src/main/java/stirling/software/SPDF/model/api/general/SplitPdfBySizeOrCountRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/general/SplitPdfBySizeOrCountRequest.java @@ -13,14 +13,14 @@ public class SplitPdfBySizeOrCountRequest extends PDFFile { @Schema( description = "Determines the type of split: 0 for size, 1 for page count, 2 for document count", - required = false, + requiredMode = Schema.RequiredMode.NOT_REQUIRED, defaultValue = "0") private int splitType; @Schema( description = "Value for split: size in MB (e.g., '10MB') or number of pages (e.g., '5')", - required = false, + requiredMode = Schema.RequiredMode.NOT_REQUIRED, defaultValue = "10MB") private String splitValue; } diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java index f4c449b0..ebd54128 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/AddStampRequest.java @@ -15,7 +15,7 @@ public class AddStampRequest extends PDFWithPageNums { @Schema( description = "The stamp type (text or image)", allowableValues = {"text", "image"}, - required = true) + requiredMode = Schema.RequiredMode.REQUIRED) private String stampType; @Schema(description = "The stamp text") diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java index c60d50e8..1880453e 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/AutoSplitPdfRequest.java @@ -13,7 +13,7 @@ public class AutoSplitPdfRequest extends PDFFile { @Schema( description = "Flag indicating if the duplex mode is active, where the page after the divider also gets removed.", - required = false, + requiredMode = Schema.RequiredMode.NOT_REQUIRED, defaultValue = "false") private boolean duplexMode; } diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java index 33c941af..f2c9bb59 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractHeaderRequest.java @@ -13,7 +13,7 @@ public class ExtractHeaderRequest extends PDFFile { @Schema( description = "Flag indicating whether to use the first text as a fallback if no suitable title is found. Defaults to false.", - required = false, + requiredMode = Schema.RequiredMode.NOT_REQUIRED, defaultValue = "false") private boolean useFirstTextAsFallback; } diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java index 6839451e..9fda7b6f 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/ExtractImageScansRequest.java @@ -10,7 +10,9 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode public class ExtractImageScansRequest { - @Schema(description = "The input file containing image scans", required = true) + @Schema( + description = "The input file containing image scans", + requiredMode = Schema.RequiredMode.REQUIRED) private MultipartFile fileInput; @Schema( diff --git a/src/main/java/stirling/software/SPDF/model/api/misc/PrintFileRequest.java b/src/main/java/stirling/software/SPDF/model/api/misc/PrintFileRequest.java index d91c7a9e..89c33573 100644 --- a/src/main/java/stirling/software/SPDF/model/api/misc/PrintFileRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/misc/PrintFileRequest.java @@ -10,6 +10,8 @@ import stirling.software.SPDF.model.api.PDFFile; @EqualsAndHashCode(callSuper = true) public class PrintFileRequest extends PDFFile { - @Schema(description = "Name of printer to match against", required = true) + @Schema( + description = "Name of printer to match against", + requiredMode = Schema.RequiredMode.REQUIRED) private String printerName; } diff --git a/src/main/java/stirling/software/SPDF/model/api/security/AddWatermarkRequest.java b/src/main/java/stirling/software/SPDF/model/api/security/AddWatermarkRequest.java index 1f080fd2..db746fca 100644 --- a/src/main/java/stirling/software/SPDF/model/api/security/AddWatermarkRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/security/AddWatermarkRequest.java @@ -15,7 +15,7 @@ public class AddWatermarkRequest extends PDFFile { @Schema( description = "The watermark type (text or image)", allowableValues = {"text", "image"}, - required = true) + requiredMode = Schema.RequiredMode.REQUIRED) private String watermarkType; @Schema(description = "The watermark text") diff --git a/src/main/java/stirling/software/SPDF/model/api/security/PDFPasswordRequest.java b/src/main/java/stirling/software/SPDF/model/api/security/PDFPasswordRequest.java index 7f31abbb..2c320823 100644 --- a/src/main/java/stirling/software/SPDF/model/api/security/PDFPasswordRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/security/PDFPasswordRequest.java @@ -10,6 +10,8 @@ import stirling.software.SPDF.model.api.PDFFile; @EqualsAndHashCode(callSuper = true) public class PDFPasswordRequest extends PDFFile { - @Schema(description = "The password of the PDF file", required = true) + @Schema( + description = "The password of the PDF file", + requiredMode = Schema.RequiredMode.REQUIRED) private String password; } diff --git a/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java index fce57ff5..de340300 100644 --- a/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java @@ -10,7 +10,10 @@ import stirling.software.SPDF.model.api.PDFFile; @EqualsAndHashCode(callSuper = true) public class RedactPdfRequest extends PDFFile { - @Schema(description = "List of text to redact from the PDF", type = "string", required = true) + @Schema( + description = "List of text to redact from the PDF", + type = "string", + requiredMode = Schema.RequiredMode.REQUIRED) private String listOfText; @Schema(description = "Whether to use regex for the listOfText", defaultValue = "false") diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index 1efd2446..21d921c8 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -77,7 +78,7 @@ public class GeneralUtils { public static boolean isURLReachable(String urlStr) { try { - URL url = new URL(urlStr); + URL url = URI.create(urlStr).toURL(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("HEAD"); int responseCode = connection.getResponseCode(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a5f12e64..cae1dce3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,11 @@ multipart.enabled=true +logging.level.org.springframework=WARN +logging.level.org.hibernate=WARN +logging.level.org.eclipse.jetty=WARN +logging.level.com.zaxxer.hikari=WARN + +spring.jpa.open-in-view=false server.forward-headers-strategy=NATIVE @@ -24,10 +30,8 @@ spring.devtools.livereload.enabled=true spring.thymeleaf.encoding=UTF-8 -server.connection-timeout=${SYSTEM_CONNECTIONTIMEOUTMINUTES:20m} -spring.mvc.async.request-timeout=${SYSTEM_CONNECTIONTIMEOUTMILLISECONDS:1200000} -spring.resources.static-locations=file:customFiles/static/ +spring.mvc.async.request-timeout=${SYSTEM_CONNECTIONTIMEOUTMILLISECONDS:1200000} #spring.thymeleaf.prefix=file:/customFiles/templates/,classpath:/templates/ #spring.thymeleaf.cache=false