mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 07:25:04 +00:00
moving files to common module
This commit is contained in:
parent
3831158717
commit
84a3499545
@ -421,7 +421,6 @@ dependencies {
|
|||||||
implementation 'ch.qos.logback:logback-core:1.5.18'
|
implementation 'ch.qos.logback:logback-core:1.5.18'
|
||||||
implementation 'ch.qos.logback:logback-classic:1.5.18'
|
implementation 'ch.qos.logback:logback-classic:1.5.18'
|
||||||
|
|
||||||
|
|
||||||
// Exclude vulnerable BouncyCastle version used in tableau
|
// Exclude vulnerable BouncyCastle version used in tableau
|
||||||
configurations.all {
|
configurations.all {
|
||||||
exclude group: 'org.bouncycastle', module: 'bcpkix-jdk15on'
|
exclude group: 'org.bouncycastle', module: 'bcpkix-jdk15on'
|
||||||
@ -545,7 +544,6 @@ dependencies {
|
|||||||
|
|
||||||
// Mockito (core)
|
// Mockito (core)
|
||||||
testImplementation 'org.mockito:mockito-core:5.18.0'
|
testImplementation 'org.mockito:mockito-core:5.18.0'
|
||||||
|
|
||||||
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
|
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'stirling.software'
|
group = 'stirling.software'
|
||||||
version = '0.45.6'
|
version = '0.46.2'
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
lombokVersion = "1.18.38"
|
lombokVersion = "1.18.38"
|
||||||
@ -30,17 +30,23 @@ dependencyManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.springframework.boot:spring-boot-starter-web"
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
|
implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20240325.1'
|
||||||
|
implementation 'com.fathzer:javaluator:3.0.6'
|
||||||
|
implementation 'com.posthog.java:posthog:1.2.0'
|
||||||
|
implementation 'io.github.pixee:java-security-toolkit:1.2.1'
|
||||||
|
implementation 'org.apache.commons:commons-lang3:3.17.0'
|
||||||
|
implementation 'com.drewnoakes:metadata-extractor:2.19.0' // Image metadata extractor
|
||||||
|
implementation 'com.vladsch.flexmark:flexmark-html2md-converter:0.64.8'
|
||||||
|
implementation "org.apache.pdfbox:pdfbox:$pdfboxVersion"
|
||||||
|
implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0'
|
||||||
|
implementation 'org.snakeyaml:snakeyaml-engine:2.9'
|
||||||
|
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6"
|
||||||
|
|
||||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||||
|
|
||||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
|
||||||
testImplementation "org.springframework.boot:spring-boot-starter-test"
|
testImplementation "org.springframework.boot:spring-boot-starter-test"
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,9 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
@ -21,9 +23,6 @@ import org.springframework.core.io.ClassPathResource;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.thymeleaf.spring6.SpringTemplateEngine;
|
import org.thymeleaf.spring6.SpringTemplateEngine;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@ -32,9 +31,21 @@ import stirling.software.common.model.ApplicationProperties;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
|
|
||||||
|
private final Environment env;
|
||||||
|
|
||||||
private final ApplicationProperties applicationProperties;
|
private final ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
private final Environment env;
|
@Getter
|
||||||
|
@Value("${baseUrl:http://localhost}")
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Value("${server.servlet.context-path:/}")
|
||||||
|
private String contextPath;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Value("${server.port:8080}")
|
||||||
|
private String serverPort;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(name = "system.customHTMLFiles", havingValue = "true")
|
@ConditionalOnProperty(name = "system.customHTMLFiles", havingValue = "true")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.common.configuration;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
import stirling.software.common.util.YamlHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A naive, line-based approach to merging "settings.yml" with "settings.yml.template" while
|
* A naive, line-based approach to merging "settings.yml" with "settings.yml.template" while
|
||||||
@ -78,7 +78,7 @@ public class ConfigInitializer {
|
|||||||
Path customSettingsPath = Paths.get(InstallationPathConfig.getCustomSettingsPath());
|
Path customSettingsPath = Paths.get(InstallationPathConfig.getCustomSettingsPath());
|
||||||
if (Files.notExists(customSettingsPath)) {
|
if (Files.notExists(customSettingsPath)) {
|
||||||
Files.createFile(customSettingsPath);
|
Files.createFile(customSettingsPath);
|
||||||
log.info("Created custom_settings file: {}", customSettingsPath.toString());
|
log.info("Created custom_settings file: {}", customSettingsPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,25 +48,22 @@ public class InstallationPathConfig {
|
|||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
if (os.contains("win")) {
|
if (os.contains("win")) {
|
||||||
return Paths.get(
|
return Paths.get(
|
||||||
System.getenv("APPDATA"), // parent path
|
System.getenv("APPDATA"), // parent path
|
||||||
"Stirling-PDF")
|
"Stirling-PDF")
|
||||||
.toString()
|
+ File.separator;
|
||||||
+ File.separator;
|
|
||||||
} else if (os.contains("mac")) {
|
} else if (os.contains("mac")) {
|
||||||
return Paths.get(
|
return Paths.get(
|
||||||
System.getProperty("user.home"),
|
System.getProperty("user.home"),
|
||||||
"Library",
|
"Library",
|
||||||
"Application Support",
|
"Application Support",
|
||||||
"Stirling-PDF")
|
"Stirling-PDF")
|
||||||
.toString()
|
+ File.separator;
|
||||||
+ File.separator;
|
|
||||||
} else {
|
} else {
|
||||||
return Paths.get(
|
return Paths.get(
|
||||||
System.getProperty("user.home"), // parent path
|
System.getProperty("user.home"), // parent path
|
||||||
".config",
|
".config",
|
||||||
"Stirling-PDF")
|
"Stirling-PDF")
|
||||||
.toString()
|
+ File.separator;
|
||||||
+ File.separator;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "." + File.separator;
|
return "." + File.separator;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.common.configuration;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.common.configuration;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.common.configuration;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -9,7 +9,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
import stirling.software.common.model.ApplicationProperties.CustomPaths.Operations;
|
import stirling.software.common.model.ApplicationProperties.CustomPaths.Operations;
|
||||||
import stirling.software.common.model.ApplicationProperties.CustomPaths.Pipeline;
|
import stirling.software.common.model.ApplicationProperties.CustomPaths.Pipeline;
|
@ -1,45 +0,0 @@
|
|||||||
package stirling.software.common.configuration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
|
||||||
import org.springframework.core.env.PropertySource;
|
|
||||||
import org.springframework.core.io.FileSystemResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.core.io.support.EncodedResource;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
public class YamlConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PropertySource<?> dynamicYamlPropertySource(ConfigurableEnvironment environment)
|
|
||||||
throws IOException {
|
|
||||||
String configPath = InstallationPathConfig.getSettingsPath();
|
|
||||||
log.debug("Attempting to load settings from: {}", configPath);
|
|
||||||
|
|
||||||
File file = new File(configPath);
|
|
||||||
if (!file.exists()) {
|
|
||||||
log.error("Warning: Settings file does not exist at: {}", configPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
Resource resource = new FileSystemResource(configPath);
|
|
||||||
if (!resource.exists()) {
|
|
||||||
throw new FileNotFoundException("Settings file not found at: " + configPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
EncodedResource encodedResource = new EncodedResource(resource);
|
|
||||||
PropertySource<?> propertySource =
|
|
||||||
new YamlPropertySourceFactory().createPropertySource(null, encodedResource);
|
|
||||||
environment.getPropertySources().addFirst(propertySource);
|
|
||||||
|
|
||||||
log.debug("Loaded properties: {}", propertySource.getSource());
|
|
||||||
|
|
||||||
return propertySource;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,7 @@
|
|||||||
|
package stirling.software.common.configuration.interfaces;
|
||||||
|
|
||||||
|
public interface ShowAdminInterface {
|
||||||
|
default boolean getShowUpdateOnlyAdmins() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -22,11 +22,11 @@ import org.springframework.core.io.FileSystemResource;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import stirling.software.common.model.exception.UnsupportedProviderException;
|
import stirling.software.common.model.exception.UnsupportedProviderException;
|
||||||
import stirling.software.common.model.provider.GitHubProvider;
|
import stirling.software.common.model.oauth2.GitHubProvider;
|
||||||
import stirling.software.common.model.provider.GoogleProvider;
|
import stirling.software.common.model.oauth2.GoogleProvider;
|
||||||
import stirling.software.common.model.provider.KeycloakProvider;
|
import stirling.software.common.model.oauth2.KeycloakProvider;
|
||||||
import stirling.software.common.model.provider.Provider;
|
import stirling.software.common.model.oauth2.Provider;
|
||||||
import stirling.software.common.util.Validator;
|
import stirling.software.common.util.ValidationUtil;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Component
|
@Component
|
||||||
@ -208,11 +208,11 @@ public class ApplicationProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSettingsValid() {
|
public boolean isSettingsValid() {
|
||||||
return !Validator.isStringEmpty(this.getIssuer())
|
return !ValidationUtil.isStringEmpty(this.getIssuer())
|
||||||
&& !Validator.isStringEmpty(this.getClientId())
|
&& !ValidationUtil.isStringEmpty(this.getClientId())
|
||||||
&& !Validator.isStringEmpty(this.getClientSecret())
|
&& !ValidationUtil.isStringEmpty(this.getClientSecret())
|
||||||
&& !Validator.isCollectionEmpty(this.getScopes())
|
&& !ValidationUtil.isCollectionEmpty(this.getScopes())
|
||||||
&& !Validator.isStringEmpty(this.getUseAsUsername());
|
&& !ValidationUtil.isStringEmpty(this.getUseAsUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.model;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
@ -0,0 +1,19 @@
|
|||||||
|
package stirling.software.common.model;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class PdfMetadata {
|
||||||
|
private String author;
|
||||||
|
private String producer;
|
||||||
|
private String title;
|
||||||
|
private String creator;
|
||||||
|
private String subject;
|
||||||
|
private String keywords;
|
||||||
|
private Calendar creationDate;
|
||||||
|
private Calendar modificationDate;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package stirling.software.common.model.api;
|
||||||
|
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class GeneralFile {
|
||||||
|
|
||||||
|
@Schema(
|
||||||
|
description = "The input file",
|
||||||
|
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||||
|
format = "binary")
|
||||||
|
private MultipartFile fileInput;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.model.api;
|
package stirling.software.common.model.api;
|
||||||
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -1,11 +1,10 @@
|
|||||||
package stirling.software.SPDF.model.api.converters;
|
package stirling.software.common.model.api.converters;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import stirling.software.common.model.api.PDFFile;
|
||||||
import stirling.software.SPDF.model.api.PDFFile;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.model.api.misc;
|
package stirling.software.common.model.api.misc;
|
||||||
|
|
||||||
public enum HighContrastColorCombination {
|
public enum HighContrastColorCombination {
|
||||||
WHITE_TEXT_ON_BLACK,
|
WHITE_TEXT_ON_BLACK,
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.model.api.misc;
|
package stirling.software.common.model.api.misc;
|
||||||
|
|
||||||
public enum ReplaceAndInvert {
|
public enum ReplaceAndInvert {
|
||||||
HIGH_CONTRAST_COLOR,
|
HIGH_CONTRAST_COLOR,
|
@ -0,0 +1,28 @@
|
|||||||
|
package stirling.software.common.model.api.security;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class RedactionArea {
|
||||||
|
@Schema(description = "The left edge point of the area to be redacted.")
|
||||||
|
private Double x;
|
||||||
|
|
||||||
|
@Schema(description = "The top edge point of the area to be redacted.")
|
||||||
|
private Double y;
|
||||||
|
|
||||||
|
@Schema(description = "The height of the area to be redacted.")
|
||||||
|
private Double height;
|
||||||
|
|
||||||
|
@Schema(description = "The width of the area to be redacted.")
|
||||||
|
private Double width;
|
||||||
|
|
||||||
|
@Schema(description = "The page on which the area should be redacted.")
|
||||||
|
private Integer page;
|
||||||
|
|
||||||
|
@Schema(description = "The color used to redact the specified area.")
|
||||||
|
private String color;
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package stirling.software.common.model.enumeration;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum Role {
|
||||||
|
|
||||||
|
// Unlimited access
|
||||||
|
ADMIN("ROLE_ADMIN", Integer.MAX_VALUE, Integer.MAX_VALUE, "adminUserSettings.admin"),
|
||||||
|
|
||||||
|
// Unlimited access
|
||||||
|
USER("ROLE_USER", Integer.MAX_VALUE, Integer.MAX_VALUE, "adminUserSettings.user"),
|
||||||
|
|
||||||
|
// 40 API calls Per Day, 40 web calls
|
||||||
|
LIMITED_API_USER("ROLE_LIMITED_API_USER", 40, 40, "adminUserSettings.apiUser"),
|
||||||
|
|
||||||
|
// 20 API calls Per Day, 20 web calls
|
||||||
|
EXTRA_LIMITED_API_USER("ROLE_EXTRA_LIMITED_API_USER", 20, 20, "adminUserSettings.extraApiUser"),
|
||||||
|
|
||||||
|
// 0 API calls per day and 20 web calls
|
||||||
|
WEB_ONLY_USER("ROLE_WEB_ONLY_USER", 0, 20, "adminUserSettings.webOnlyUser"),
|
||||||
|
|
||||||
|
INTERNAL_API_USER(
|
||||||
|
"STIRLING-PDF-BACKEND-API-USER",
|
||||||
|
Integer.MAX_VALUE,
|
||||||
|
Integer.MAX_VALUE,
|
||||||
|
"adminUserSettings.internalApiUser"),
|
||||||
|
|
||||||
|
DEMO_USER("ROLE_DEMO_USER", 100, 100, "adminUserSettings.demoUser");
|
||||||
|
|
||||||
|
private final String roleId;
|
||||||
|
private final int apiCallsPerDay;
|
||||||
|
private final int webCallsPerDay;
|
||||||
|
private final String roleName;
|
||||||
|
|
||||||
|
public static String getRoleNameByRoleId(String roleId) {
|
||||||
|
// Using the fromString method to get the Role enum based on the roleId
|
||||||
|
Role role = fromString(roleId);
|
||||||
|
// Return the roleName of the found Role enum
|
||||||
|
return role.getRoleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to retrieve all role IDs and role names
|
||||||
|
public static Map<String, String> getAllRoleDetails() {
|
||||||
|
// Using LinkedHashMap to preserve order
|
||||||
|
Map<String, String> roleDetails = new LinkedHashMap<>();
|
||||||
|
for (Role role : Role.values()) {
|
||||||
|
roleDetails.put(role.getRoleId(), role.getRoleName());
|
||||||
|
}
|
||||||
|
return roleDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Role fromString(String roleId) {
|
||||||
|
for (Role role : Role.values()) {
|
||||||
|
if (role.getRoleId().equalsIgnoreCase(roleId)) {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("No Role defined for id: " + roleId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package stirling.software.common.model.exception;
|
||||||
|
|
||||||
|
public class UnsupportedClaimException extends RuntimeException {
|
||||||
|
public UnsupportedClaimException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
package stirling.software.common.model.exception;
|
|
||||||
|
|
||||||
public class UnsupportedUsernameAttribute extends RuntimeException {
|
|
||||||
public UnsupportedUsernameAttribute(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.common.model.provider;
|
package stirling.software.common.model.oauth2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.common.model.provider;
|
package stirling.software.common.model.oauth2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.common.model.provider;
|
package stirling.software.common.model.oauth2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.common.model.provider;
|
package stirling.software.common.model.oauth2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -6,7 +6,7 @@ import java.util.Collection;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import stirling.software.common.model.enumeration.UsernameAttribute;
|
import stirling.software.common.model.enumeration.UsernameAttribute;
|
||||||
import stirling.software.common.model.exception.UnsupportedUsernameAttribute;
|
import stirling.software.common.model.exception.UnsupportedClaimException;
|
||||||
import static stirling.software.common.model.enumeration.UsernameAttribute.EMAIL;
|
import static stirling.software.common.model.enumeration.UsernameAttribute.EMAIL;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -80,7 +80,7 @@ public class Provider {
|
|||||||
return usernameAttribute;
|
return usernameAttribute;
|
||||||
}
|
}
|
||||||
default ->
|
default ->
|
||||||
throw new UnsupportedUsernameAttribute(
|
throw new UnsupportedClaimException(
|
||||||
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
|
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ public class Provider {
|
|||||||
return usernameAttribute;
|
return usernameAttribute;
|
||||||
}
|
}
|
||||||
default ->
|
default ->
|
||||||
throw new UnsupportedUsernameAttribute(
|
throw new UnsupportedClaimException(
|
||||||
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
|
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ public class Provider {
|
|||||||
return usernameAttribute;
|
return usernameAttribute;
|
||||||
}
|
}
|
||||||
default ->
|
default ->
|
||||||
throw new UnsupportedUsernameAttribute(
|
throw new UnsupportedClaimException(
|
||||||
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
|
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.service;
|
package stirling.software.common.service;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -22,7 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.PDFFile;
|
import stirling.software.common.model.api.PDFFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adaptive PDF document factory that optimizes memory usage based on file size and available system
|
* Adaptive PDF document factory that optimizes memory usage based on file size and available system
|
@ -0,0 +1,113 @@
|
|||||||
|
package stirling.software.common.service;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.model.PdfMetadata;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PdfMetadataService {
|
||||||
|
|
||||||
|
private final ApplicationProperties applicationProperties;
|
||||||
|
private final String stirlingPDFLabel;
|
||||||
|
private final UserServiceInterface userService;
|
||||||
|
private final boolean runningProOrHigher;
|
||||||
|
|
||||||
|
public PdfMetadataService(
|
||||||
|
ApplicationProperties applicationProperties,
|
||||||
|
@Qualifier("StirlingPDFLabel") String stirlingPDFLabel,
|
||||||
|
@Qualifier("runningProOrHigher") boolean runningProOrHigher,
|
||||||
|
@Autowired(required = false) UserServiceInterface userService) {
|
||||||
|
this.applicationProperties = applicationProperties;
|
||||||
|
this.stirlingPDFLabel = stirlingPDFLabel;
|
||||||
|
this.userService = userService;
|
||||||
|
this.runningProOrHigher = runningProOrHigher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfMetadata extractMetadataFromPdf(PDDocument pdf) {
|
||||||
|
return PdfMetadata.builder()
|
||||||
|
.author(pdf.getDocumentInformation().getAuthor())
|
||||||
|
.producer(pdf.getDocumentInformation().getProducer())
|
||||||
|
.title(pdf.getDocumentInformation().getTitle())
|
||||||
|
.creator(pdf.getDocumentInformation().getCreator())
|
||||||
|
.subject(pdf.getDocumentInformation().getSubject())
|
||||||
|
.keywords(pdf.getDocumentInformation().getKeywords())
|
||||||
|
.creationDate(pdf.getDocumentInformation().getCreationDate())
|
||||||
|
.modificationDate(pdf.getDocumentInformation().getModificationDate())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultMetadata(PDDocument pdf) {
|
||||||
|
PdfMetadata metadata = extractMetadataFromPdf(pdf);
|
||||||
|
setMetadataToPdf(pdf, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataToPdf(PDDocument pdf, PdfMetadata pdfMetadata) {
|
||||||
|
setMetadataToPdf(pdf, pdfMetadata, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataToPdf(PDDocument pdf, PdfMetadata pdfMetadata, boolean newlyCreated) {
|
||||||
|
if (newlyCreated || pdfMetadata.getCreationDate() == null) {
|
||||||
|
setNewDocumentMetadata(pdf, pdfMetadata);
|
||||||
|
}
|
||||||
|
setCommonMetadata(pdf, pdfMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNewDocumentMetadata(PDDocument pdf, PdfMetadata pdfMetadata) {
|
||||||
|
|
||||||
|
String creator = stirlingPDFLabel;
|
||||||
|
|
||||||
|
if (applicationProperties
|
||||||
|
.getPremium()
|
||||||
|
.getProFeatures()
|
||||||
|
.getCustomMetadata()
|
||||||
|
.isAutoUpdateMetadata()
|
||||||
|
&& runningProOrHigher) {
|
||||||
|
|
||||||
|
creator =
|
||||||
|
applicationProperties
|
||||||
|
.getPremium()
|
||||||
|
.getProFeatures()
|
||||||
|
.getCustomMetadata()
|
||||||
|
.getCreator();
|
||||||
|
pdf.getDocumentInformation().setProducer(stirlingPDFLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
pdf.getDocumentInformation().setCreator(creator);
|
||||||
|
pdf.getDocumentInformation().setCreationDate(Calendar.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCommonMetadata(PDDocument pdf, PdfMetadata pdfMetadata) {
|
||||||
|
String title = pdfMetadata.getTitle();
|
||||||
|
pdf.getDocumentInformation().setTitle(title);
|
||||||
|
pdf.getDocumentInformation().setProducer(stirlingPDFLabel);
|
||||||
|
pdf.getDocumentInformation().setSubject(pdfMetadata.getSubject());
|
||||||
|
pdf.getDocumentInformation().setKeywords(pdfMetadata.getKeywords());
|
||||||
|
pdf.getDocumentInformation().setModificationDate(Calendar.getInstance());
|
||||||
|
|
||||||
|
String author = pdfMetadata.getAuthor();
|
||||||
|
if (applicationProperties
|
||||||
|
.getPremium()
|
||||||
|
.getProFeatures()
|
||||||
|
.getCustomMetadata()
|
||||||
|
.isAutoUpdateMetadata()
|
||||||
|
&& runningProOrHigher) {
|
||||||
|
author =
|
||||||
|
applicationProperties
|
||||||
|
.getPremium()
|
||||||
|
.getProFeatures()
|
||||||
|
.getCustomMetadata()
|
||||||
|
.getAuthor();
|
||||||
|
|
||||||
|
if (userService != null) {
|
||||||
|
author = author.replace("username", userService.getCurrentUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pdf.getDocumentInformation().setAuthor(author);
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,21 @@
|
|||||||
package stirling.software.SPDF.service;
|
package stirling.software.common.service;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.management.*;
|
import java.lang.management.GarbageCollectorMXBean;
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.MemoryMXBean;
|
||||||
|
import java.lang.management.OperatingSystemMXBean;
|
||||||
|
import java.lang.management.RuntimeMXBean;
|
||||||
|
import java.lang.management.ThreadMXBean;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -16,7 +25,6 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import com.posthog.java.PostHog;
|
import com.posthog.java.PostHog;
|
||||||
|
|
||||||
import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -200,7 +208,7 @@ public class PostHogService {
|
|||||||
|
|
||||||
// New environment variables
|
// New environment variables
|
||||||
dockerMetrics.put("version_tag", System.getenv("VERSION_TAG"));
|
dockerMetrics.put("version_tag", System.getenv("VERSION_TAG"));
|
||||||
dockerMetrics.put("docker_enable_security", System.getenv("DOCKER_ENABLE_SECURITY"));
|
dockerMetrics.put("without_enhanced_features", System.getenv("WITHOUT_ENHANCED_FEATURES"));
|
||||||
dockerMetrics.put("fat_docker", System.getenv("FAT_DOCKER"));
|
dockerMetrics.put("fat_docker", System.getenv("FAT_DOCKER"));
|
||||||
|
|
||||||
return dockerMetrics;
|
return dockerMetrics;
|
@ -0,0 +1,9 @@
|
|||||||
|
package stirling.software.common.service;
|
||||||
|
|
||||||
|
public interface UserServiceInterface {
|
||||||
|
String getApiKeyForUser(String username);
|
||||||
|
|
||||||
|
String getCurrentUsername();
|
||||||
|
|
||||||
|
long getTotalUsersCount();
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
|
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
|
||||||
|
|
||||||
public class CheckProgramInstall {
|
public class CheckProgramInstall {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import org.owasp.html.HtmlPolicyBuilder;
|
import org.owasp.html.HtmlPolicyBuilder;
|
||||||
import org.owasp.html.PolicyFactory;
|
import org.owasp.html.PolicyFactory;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static java.nio.file.StandardWatchEventKinds.*;
|
import static java.nio.file.StandardWatchEventKinds.*;
|
||||||
|
|
||||||
@ -17,8 +17,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import stirling.software.common.configuration.RuntimePathConfig;
|
||||||
import stirling.software.SPDF.config.RuntimePathConfig;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -16,8 +16,8 @@ import java.util.zip.ZipOutputStream;
|
|||||||
|
|
||||||
import io.github.pixee.security.ZipSecurity;
|
import io.github.pixee.security.ZipSecurity;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.converters.HTMLToPdfRequest;
|
import stirling.software.common.model.api.converters.HTMLToPdfRequest;
|
||||||
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
|
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
|
||||||
|
|
||||||
public class FileToPdf {
|
public class FileToPdf {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -27,11 +27,10 @@ import io.github.pixee.security.Urls;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.config.YamlHelper;
|
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
import stirling.software.common.configuration.InstallationPathConfig;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GeneralUtils {
|
public class GeneralUtil {
|
||||||
|
|
||||||
public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
|
public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
|
||||||
File tempFile = Files.createTempFile("temp", null).toFile();
|
File tempFile = Files.createTempFile("temp", null).toFile();
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -28,7 +28,7 @@ import io.github.pixee.security.Filenames;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
|
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -34,8 +34,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import io.github.pixee.security.Filenames;
|
import io.github.pixee.security.Filenames;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
||||||
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PdfUtils {
|
public class PdfUtils {
|
||||||
@ -85,7 +84,7 @@ public class PdfUtils {
|
|||||||
public static boolean hasImages(PDDocument document, String pagesToCheck) throws IOException {
|
public static boolean hasImages(PDDocument document, String pagesToCheck) throws IOException {
|
||||||
String[] pageOrderArr = pagesToCheck.split(",");
|
String[] pageOrderArr = pagesToCheck.split(",");
|
||||||
List<Integer> pageList =
|
List<Integer> pageList =
|
||||||
GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages());
|
GeneralUtil.parsePageList(pageOrderArr, document.getNumberOfPages());
|
||||||
|
|
||||||
for (int pageNumber : pageList) {
|
for (int pageNumber : pageList) {
|
||||||
PDPage page = document.getPage(pageNumber);
|
PDPage page = document.getPage(pageNumber);
|
||||||
@ -101,7 +100,7 @@ public class PdfUtils {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
String[] pageOrderArr = pageNumbersToCheck.split(",");
|
String[] pageOrderArr = pageNumbersToCheck.split(",");
|
||||||
List<Integer> pageList =
|
List<Integer> pageList =
|
||||||
GeneralUtils.parsePageList(pageOrderArr, document.getNumberOfPages());
|
GeneralUtil.parsePageList(pageOrderArr, document.getNumberOfPages());
|
||||||
|
|
||||||
for (int pageNumber : pageList) {
|
for (int pageNumber : pageList) {
|
||||||
PDPage page = document.getPage(pageNumber);
|
PDPage page = document.getPage(pageNumber);
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,9 +1,10 @@
|
|||||||
package stirling.software.common.util;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.util.Collection;
|
import stirling.software.common.model.oauth2.Provider;
|
||||||
import stirling.software.common.model.provider.Provider;
|
import static stirling.software.common.util.ValidationUtil.isCollectionEmpty;
|
||||||
|
import static stirling.software.common.util.ValidationUtil.isStringEmpty;
|
||||||
|
|
||||||
public class Validator {
|
public class ProviderUtil {
|
||||||
|
|
||||||
public static boolean validateProvider(Provider provider) {
|
public static boolean validateProvider(Provider provider) {
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
@ -24,12 +25,4 @@ public class Validator {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStringEmpty(String input) {
|
|
||||||
return input == null || input.isBlank();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCollectionEmpty(Collection<String> input) {
|
|
||||||
return input == null || input.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,14 +1,12 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
public class RequestUriUtils {
|
public class RequestUriUtil {
|
||||||
|
|
||||||
public static boolean isStaticResource(String requestURI) {
|
public static boolean isStaticResource(String requestURI) {
|
||||||
|
|
||||||
return isStaticResource("", requestURI);
|
return isStaticResource("", requestURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStaticResource(String contextPath, String requestURI) {
|
public static boolean isStaticResource(String contextPath, String requestURI) {
|
||||||
|
|
||||||
return requestURI.startsWith(contextPath + "/css/")
|
return requestURI.startsWith(contextPath + "/css/")
|
||||||
|| requestURI.startsWith(contextPath + "/fonts/")
|
|| requestURI.startsWith(contextPath + "/fonts/")
|
||||||
|| requestURI.startsWith(contextPath + "/js/")
|
|| requestURI.startsWith(contextPath + "/js/")
|
@ -1,9 +1,7 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class UIScaling {
|
public class UIScaling {
|
||||||
private static final double BASE_RESOLUTION_WIDTH = 1920.0;
|
private static final double BASE_RESOLUTION_WIDTH = 1920.0;
|
||||||
private static final double BASE_RESOLUTION_HEIGHT = 1080.0;
|
private static final double BASE_RESOLUTION_HEIGHT = 1080.0;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
@ -0,0 +1,14 @@
|
|||||||
|
package stirling.software.common.util;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class ValidationUtil {
|
||||||
|
|
||||||
|
public static boolean isStringEmpty(String input) {
|
||||||
|
return input == null || input.isBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCollectionEmpty(Collection<String> input) {
|
||||||
|
return input == null || input.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -23,9 +23,8 @@ import org.springframework.core.io.InputStreamResource;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import stirling.software.common.model.api.misc.HighContrastColorCombination;
|
||||||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination;
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CustomColorReplaceStrategy extends ReplaceAndInvertColorStrategy {
|
public class CustomColorReplaceStrategy extends ReplaceAndInvertColorStrategy {
|
@ -1,7 +1,7 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination;
|
import stirling.software.common.model.api.misc.HighContrastColorCombination;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
|
|
||||||
public class HighContrastColorReplaceDecider {
|
public class HighContrastColorReplaceDecider {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -18,8 +18,7 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
|||||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
|
||||||
|
|
||||||
public class InvertFullColorStrategy extends ReplaceAndInvertColorStrategy {
|
public class InvertFullColorStrategy extends ReplaceAndInvertColorStrategy {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -8,8 +8,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.PDFFile;
|
import stirling.software.common.model.api.PDFFile;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.propertyeditor;
|
package stirling.software.common.util.propertyeditor;
|
||||||
|
|
||||||
import java.beans.PropertyEditorSupport;
|
import java.beans.PropertyEditorSupport;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -9,8 +9,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import stirling.software.common.model.api.security.RedactionArea;
|
||||||
import stirling.software.SPDF.model.api.security.RedactionArea;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class StringToArrayListPropertyEditor extends PropertyEditorSupport {
|
public class StringToArrayListPropertyEditor extends PropertyEditorSupport {
|
||||||
@ -26,7 +25,8 @@ public class StringToArrayListPropertyEditor extends PropertyEditorSupport {
|
|||||||
try {
|
try {
|
||||||
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||||
TypeReference<ArrayList<RedactionArea>> typeRef =
|
TypeReference<ArrayList<RedactionArea>> typeRef =
|
||||||
new TypeReference<ArrayList<RedactionArea>>() {};
|
new TypeReference<>() {
|
||||||
|
};
|
||||||
List<RedactionArea> list = objectMapper.readValue(text, typeRef);
|
List<RedactionArea> list = objectMapper.readValue(text, typeRef);
|
||||||
setValue(list);
|
setValue(list);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.propertyeditor;
|
package stirling.software.common.util.propertyeditor;
|
||||||
|
|
||||||
import java.beans.PropertyEditorSupport;
|
import java.beans.PropertyEditorSupport;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -15,7 +15,7 @@ public class StringToMapPropertyEditor extends PropertyEditorSupport {
|
|||||||
public void setAsText(String text) throws IllegalArgumentException {
|
public void setAsText(String text) throws IllegalArgumentException {
|
||||||
try {
|
try {
|
||||||
TypeReference<HashMap<String, String>> typeRef =
|
TypeReference<HashMap<String, String>> typeRef =
|
||||||
new TypeReference<HashMap<String, String>>() {};
|
new TypeReference<>() {};
|
||||||
Map<String, String> map = objectMapper.readValue(text, typeRef);
|
Map<String, String> map = objectMapper.readValue(text, typeRef);
|
||||||
setValue(map);
|
setValue(map);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
@ -1,7 +1,8 @@
|
|||||||
package stirling.software.SPDF.service;
|
package stirling.software.common.service;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
import static stirling.software.common.service.SpyPDFDocumentFactory.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
@ -19,8 +20,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||||||
import org.junit.jupiter.params.provider.CsvSource;
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.PDFFile;
|
import stirling.software.common.model.api.PDFFile;
|
||||||
import stirling.software.SPDF.service.SpyPDFDocumentFactory.StrategyType;
|
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
@ -46,7 +46,7 @@ class CustomPDFDocumentFactoryTest {
|
|||||||
void testStrategy_FileInput(int sizeMB, StrategyType expected) throws IOException {
|
void testStrategy_FileInput(int sizeMB, StrategyType expected) throws IOException {
|
||||||
File file = writeTempFile(inflatePdf(basePdfBytes, sizeMB));
|
File file = writeTempFile(inflatePdf(basePdfBytes, sizeMB));
|
||||||
try (PDDocument doc = factory.load(file)) {
|
try (PDDocument doc = factory.load(file)) {
|
||||||
assertEquals(expected, factory.lastStrategyUsed);
|
Assertions.assertEquals(expected, factory.lastStrategyUsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class CustomPDFDocumentFactoryTest {
|
|||||||
void testStrategy_ByteArray(int sizeMB, StrategyType expected) throws IOException {
|
void testStrategy_ByteArray(int sizeMB, StrategyType expected) throws IOException {
|
||||||
byte[] inflated = inflatePdf(basePdfBytes, sizeMB);
|
byte[] inflated = inflatePdf(basePdfBytes, sizeMB);
|
||||||
try (PDDocument doc = factory.load(inflated)) {
|
try (PDDocument doc = factory.load(inflated)) {
|
||||||
assertEquals(expected, factory.lastStrategyUsed);
|
Assertions.assertEquals(expected, factory.lastStrategyUsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class CustomPDFDocumentFactoryTest {
|
|||||||
void testStrategy_InputStream(int sizeMB, StrategyType expected) throws IOException {
|
void testStrategy_InputStream(int sizeMB, StrategyType expected) throws IOException {
|
||||||
byte[] inflated = inflatePdf(basePdfBytes, sizeMB);
|
byte[] inflated = inflatePdf(basePdfBytes, sizeMB);
|
||||||
try (PDDocument doc = factory.load(new ByteArrayInputStream(inflated))) {
|
try (PDDocument doc = factory.load(new ByteArrayInputStream(inflated))) {
|
||||||
assertEquals(expected, factory.lastStrategyUsed);
|
Assertions.assertEquals(expected, factory.lastStrategyUsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class CustomPDFDocumentFactoryTest {
|
|||||||
MockMultipartFile multipart =
|
MockMultipartFile multipart =
|
||||||
new MockMultipartFile("file", "doc.pdf", "application/pdf", inflated);
|
new MockMultipartFile("file", "doc.pdf", "application/pdf", inflated);
|
||||||
try (PDDocument doc = factory.load(multipart)) {
|
try (PDDocument doc = factory.load(multipart)) {
|
||||||
assertEquals(expected, factory.lastStrategyUsed);
|
Assertions.assertEquals(expected, factory.lastStrategyUsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ class CustomPDFDocumentFactoryTest {
|
|||||||
PDFFile pdfFile = new PDFFile();
|
PDFFile pdfFile = new PDFFile();
|
||||||
pdfFile.setFileInput(multipart);
|
pdfFile.setFileInput(multipart);
|
||||||
try (PDDocument doc = factory.load(pdfFile)) {
|
try (PDDocument doc = factory.load(pdfFile)) {
|
||||||
assertEquals(expected, factory.lastStrategyUsed);
|
Assertions.assertEquals(expected, factory.lastStrategyUsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.service;
|
package stirling.software.common.service;
|
||||||
|
|
||||||
import org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction;
|
import org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction;
|
||||||
|
|
@ -1,5 +1,15 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
@ -10,19 +20,6 @@ import static org.mockito.Mockito.times;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.MockedStatic;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
|
|
||||||
|
|
||||||
class CheckProgramInstallTest {
|
class CheckProgramInstallTest {
|
||||||
|
|
||||||
private MockedStatic<ProcessExecutor> mockProcessExecutor;
|
private MockedStatic<ProcessExecutor> mockProcessExecutor;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ -7,6 +7,8 @@ import java.time.LocalDateTime;
|
|||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.CsvSource;
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
|
|
||||||
|
import stirling.software.common.model.FileInfo;
|
||||||
|
|
||||||
public class FileInfoTest {
|
public class FileInfoTest {
|
||||||
|
|
||||||
@ParameterizedTest(name = "{index}: fileSize={0}")
|
@ParameterizedTest(name = "{index}: fileSize={0}")
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
@ -19,8 +19,7 @@ import org.junit.jupiter.api.io.TempDir;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import stirling.software.common.configuration.RuntimePathConfig;
|
||||||
import stirling.software.SPDF.config.RuntimePathConfig;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class FileMonitorTest {
|
class FileMonitorTest {
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
@ -8,7 +8,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.converters.HTMLToPdfRequest;
|
import stirling.software.common.model.api.converters.HTMLToPdfRequest;
|
||||||
|
|
||||||
public class FileToPdfTest {
|
public class FileToPdfTest {
|
||||||
|
|
@ -0,0 +1,41 @@
|
|||||||
|
package stirling.software.common.util;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class GeneralUtilAdditionalTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testConvertSizeToBytes() {
|
||||||
|
assertEquals(1024L, GeneralUtil.convertSizeToBytes("1KB"));
|
||||||
|
assertEquals(1024L * 1024, GeneralUtil.convertSizeToBytes("1MB"));
|
||||||
|
assertEquals(1024L * 1024 * 1024, GeneralUtil.convertSizeToBytes("1GB"));
|
||||||
|
assertEquals(100L * 1024 * 1024, GeneralUtil.convertSizeToBytes("100"));
|
||||||
|
assertNull(GeneralUtil.convertSizeToBytes("invalid"));
|
||||||
|
assertNull(GeneralUtil.convertSizeToBytes(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testFormatBytes() {
|
||||||
|
assertEquals("512 B", GeneralUtil.formatBytes(512));
|
||||||
|
assertEquals("1.00 KB", GeneralUtil.formatBytes(1024));
|
||||||
|
assertEquals("1.00 MB", GeneralUtil.formatBytes(1024L * 1024));
|
||||||
|
assertEquals("1.00 GB", GeneralUtil.formatBytes(1024L * 1024 * 1024));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testURLHelpersAndUUID() {
|
||||||
|
assertTrue(GeneralUtil.isValidURL("https://example.com"));
|
||||||
|
assertFalse(GeneralUtil.isValidURL("htp:/bad"));
|
||||||
|
assertFalse(GeneralUtil.isURLReachable("http://localhost"));
|
||||||
|
assertFalse(GeneralUtil.isURLReachable("ftp://example.com"));
|
||||||
|
|
||||||
|
assertTrue(GeneralUtil.isValidUUID("123e4567-e89b-12d3-a456-426614174000"));
|
||||||
|
assertFalse(GeneralUtil.isValidUUID("not-a-uuid"));
|
||||||
|
|
||||||
|
assertFalse(GeneralUtil.isVersionHigher(null, "1.0"));
|
||||||
|
assertTrue(GeneralUtil.isVersionHigher("2.0", "1.9"));
|
||||||
|
assertFalse(GeneralUtil.isVersionHigher("1.0", "1.0.1"));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ -6,152 +6,152 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class GeneralUtilsTest {
|
public class GeneralUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithAll() {
|
void testParsePageListWithAll() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"all"}, 5, false);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"all"}, 5, false);
|
||||||
assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithAllOneBased() {
|
void testParsePageListWithAllOneBased() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"all"}, 5, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"all"}, 5, true);
|
||||||
assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc() {
|
void nFunc() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"n"}, 5, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"n"}, 5, true);
|
||||||
assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages.");
|
assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced() {
|
void nFuncAdvanced() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n"}, 9, true);
|
||||||
// skip 0 as not valid
|
// skip 0 as not valid
|
||||||
assertEquals(List.of(4, 8), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(4, 8), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvancedZero() {
|
void nFuncAdvancedZero() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n"}, 9, false);
|
||||||
// skip 0 as not valid
|
// skip 0 as not valid
|
||||||
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced2() {
|
void nFuncAdvanced2() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n-1"}, 9, true);
|
||||||
// skip -1 as not valid
|
// skip -1 as not valid
|
||||||
assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)");
|
assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced3() {
|
void nFuncAdvanced3() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n+1"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n+1"}, 9, true);
|
||||||
assertEquals(List.of(5, 9), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(5, 9), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_spaces() {
|
void nFunc_spaces() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"n + 1"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"n + 1"}, 9, true);
|
||||||
assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result);
|
assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_consecutive_Ns_nnn() {
|
void nFunc_consecutive_Ns_nnn() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"nnn"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"nnn"}, 9, true);
|
||||||
assertEquals(List.of(1, 8), result);
|
assertEquals(List.of(1, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_consecutive_Ns_nn() {
|
void nFunc_consecutive_Ns_nn() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"nn"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"nn"}, 9, true);
|
||||||
assertEquals(List.of(1, 4, 9), result);
|
assertEquals(List.of(1, 4, 9), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_opening_closing_round_brackets() {
|
void nFunc_opening_closing_round_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)(n-2)"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)(n-2)"}, 9, true);
|
||||||
assertEquals(List.of(2, 6), result);
|
assertEquals(List.of(2, 6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_opening_round_brackets() {
|
void nFunc_opening_round_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"2(n-1)"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"2(n-1)"}, 9, true);
|
||||||
assertEquals(List.of(2, 4, 6, 8), result);
|
assertEquals(List.of(2, 4, 6, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_opening_round_brackets_n() {
|
void nFunc_opening_round_brackets_n() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"n(n-1)"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"n(n-1)"}, 9, true);
|
||||||
assertEquals(List.of(2, 6), result);
|
assertEquals(List.of(2, 6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_closing_round_brackets() {
|
void nFunc_closing_round_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)2"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)2"}, 9, true);
|
||||||
assertEquals(List.of(2, 4, 6, 8), result);
|
assertEquals(List.of(2, 4, 6, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_closing_round_brackets_n() {
|
void nFunc_closing_round_brackets_n() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)n"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)n"}, 9, true);
|
||||||
assertEquals(List.of(2, 6), result);
|
assertEquals(List.of(2, 6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFunc_function_surrounded_with_brackets() {
|
void nFunc_function_surrounded_with_brackets() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"(n-1)"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"(n-1)"}, 9, true);
|
||||||
assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result);
|
assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced4() {
|
void nFuncAdvanced4() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"3+2n"}, 9, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"3+2n"}, 9, true);
|
||||||
assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvancedZerobased() {
|
void nFuncAdvancedZerobased() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n"}, 9, false);
|
||||||
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(3, 7), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nFuncAdvanced2Zerobased() {
|
void nFuncAdvanced2Zerobased() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, false);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"4n-1"}, 9, false);
|
||||||
assertEquals(List.of(2, 6), result, "'All' keyword should return all pages.");
|
assertEquals(List.of(2, 6), result, "'All' keyword should return all pages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeOneBasedOutput() {
|
void testParsePageListWithRangeOneBasedOutput() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1-3"}, 5, true);
|
||||||
assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly.");
|
assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeZeroBaseOutput() {
|
void testParsePageListWithRangeZeroBaseOutput() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, false);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1-3"}, 5, false);
|
||||||
assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly.");
|
assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeOneBasedOutputFull() {
|
void testParsePageListWithRangeOneBasedOutputFull() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1,3,7-8"}, 8, true);
|
||||||
assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly.");
|
assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeOneBasedOutputFullOutOfRange() {
|
void testParsePageListWithRangeOneBasedOutputFullOutOfRange() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 5, true);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1,3,7-8"}, 5, true);
|
||||||
assertEquals(List.of(1, 3), result, "Range should be parsed correctly.");
|
assertEquals(List.of(1, 3), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParsePageListWithRangeZeroBaseOutputFull() {
|
void testParsePageListWithRangeZeroBaseOutputFull() {
|
||||||
List<Integer> result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, false);
|
List<Integer> result = GeneralUtil.parsePageList(new String[] {"1,3,7-8"}, 8, false);
|
||||||
assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly.");
|
assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly.");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
@ -30,7 +30,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import io.github.pixee.security.ZipSecurity;
|
import io.github.pixee.security.ZipSecurity;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
|
import stirling.software.common.util.ProcessExecutor.ProcessExecutorResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for PDFToFile utility class. This includes both invalid content type cases and positive
|
* Tests for PDFToFile utility class. This includes both invalid content type cases and positive
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
@ -23,9 +23,9 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
|
||||||
import stirling.software.SPDF.service.PdfMetadataService;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
||||||
|
import stirling.software.common.service.PdfMetadataService;
|
||||||
|
|
||||||
public class PdfUtilsTest {
|
public class PdfUtilsTest {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
@ -2,23 +2,21 @@ package stirling.software.common.util;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import stirling.software.common.model.enumeration.UsernameAttribute;
|
import stirling.software.common.model.enumeration.UsernameAttribute;
|
||||||
import stirling.software.common.model.provider.GitHubProvider;
|
import stirling.software.common.model.oauth2.GitHubProvider;
|
||||||
import stirling.software.common.model.provider.GoogleProvider;
|
import stirling.software.common.model.oauth2.GoogleProvider;
|
||||||
import stirling.software.common.model.provider.Provider;
|
import stirling.software.common.model.oauth2.Provider;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class ValidatorTest {
|
class ProviderUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSuccessfulValidation() {
|
void testSuccessfulValidation() {
|
||||||
@ -28,13 +26,13 @@ class ValidatorTest {
|
|||||||
when(provider.getClientSecret()).thenReturn("clientSecret");
|
when(provider.getClientSecret()).thenReturn("clientSecret");
|
||||||
when(provider.getScopes()).thenReturn(List.of("read:user"));
|
when(provider.getScopes()).thenReturn(List.of("read:user"));
|
||||||
|
|
||||||
assertTrue(Validator.validateProvider(provider));
|
Assertions.assertTrue(ProviderUtil.validateProvider(provider));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("providerParams")
|
@MethodSource("providerParams")
|
||||||
void testUnsuccessfulValidation(Provider provider) {
|
void testUnsuccessfulValidation(Provider provider) {
|
||||||
assertFalse(Validator.validateProvider(provider));
|
Assertions.assertFalse(ProviderUtil.validateProvider(provider));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stream<Arguments> providerParams() {
|
public static Stream<Arguments> providerParams() {
|
@ -0,0 +1,311 @@
|
|||||||
|
package stirling.software.common.util;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
|
public class RequestUriUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIsStaticResource() {
|
||||||
|
// Test static resources without context path
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/css/styles.css"), "CSS files should be static");
|
||||||
|
assertTrue(RequestUriUtil.isStaticResource("/js/script.js"), "JS files should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/images/logo.png"),
|
||||||
|
"Image files should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/public/index.html"),
|
||||||
|
"Public files should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/pdfjs/pdf.worker.js"),
|
||||||
|
"PDF.js files should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/api/v1/info/status"),
|
||||||
|
"API status should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/some-path/icon.svg"),
|
||||||
|
"SVG files should be static");
|
||||||
|
assertTrue(RequestUriUtil.isStaticResource("/login"), "Login page should be static");
|
||||||
|
assertTrue(RequestUriUtil.isStaticResource("/error"), "Error page should be static");
|
||||||
|
|
||||||
|
// Test non-static resources
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource("/api/v1/users"),
|
||||||
|
"API users should not be static");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource("/api/v1/orders"),
|
||||||
|
"API orders should not be static");
|
||||||
|
assertFalse(RequestUriUtil.isStaticResource("/"), "Root path should not be static");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource("/register"),
|
||||||
|
"Register page should not be static");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource("/api/v1/products"),
|
||||||
|
"API products should not be static");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIsStaticResourceWithContextPath() {
|
||||||
|
String contextPath = "/myapp";
|
||||||
|
|
||||||
|
// Test static resources with context path
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource(contextPath, contextPath + "/css/styles.css"),
|
||||||
|
"CSS with context path should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource(contextPath, contextPath + "/js/script.js"),
|
||||||
|
"JS with context path should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource(contextPath, contextPath + "/images/logo.png"),
|
||||||
|
"Images with context path should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource(contextPath, contextPath + "/login"),
|
||||||
|
"Login with context path should be static");
|
||||||
|
|
||||||
|
// Test non-static resources with context path
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource(contextPath, contextPath + "/api/v1/users"),
|
||||||
|
"API users with context path should not be static");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource(contextPath, "/"),
|
||||||
|
"Root path with context path should not be static");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(
|
||||||
|
strings = {
|
||||||
|
"robots.txt",
|
||||||
|
"/favicon.ico",
|
||||||
|
"/icon.svg",
|
||||||
|
"/image.png",
|
||||||
|
"/site.webmanifest",
|
||||||
|
"/app/logo.svg",
|
||||||
|
"/downloads/document.png",
|
||||||
|
"/assets/brand.ico",
|
||||||
|
"/any/path/with/image.svg",
|
||||||
|
"/deep/nested/folder/icon.png"
|
||||||
|
})
|
||||||
|
void testIsStaticResourceWithFileExtensions(String path) {
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource(path),
|
||||||
|
"Files with specific extensions should be static regardless of path");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIsTrackableResource() {
|
||||||
|
// Test non-trackable resources (returns false)
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/js/script.js"),
|
||||||
|
"JS files should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/v1/api-docs"),
|
||||||
|
"API docs should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("robots.txt"),
|
||||||
|
"robots.txt should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/images/logo.png"),
|
||||||
|
"Images should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/styles.css"),
|
||||||
|
"CSS files should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/script.js.map"),
|
||||||
|
"Map files should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/icon.svg"),
|
||||||
|
"SVG files should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/popularity.txt"),
|
||||||
|
"Popularity file should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/script.js"),
|
||||||
|
"JS files should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/swagger/index.html"),
|
||||||
|
"Swagger files should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/api/v1/info/status"),
|
||||||
|
"API info should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/site.webmanifest"),
|
||||||
|
"Webmanifest should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/fonts/font.woff"),
|
||||||
|
"Fonts should not be trackable");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/pdfjs/viewer.js"),
|
||||||
|
"PDF.js files should not be trackable");
|
||||||
|
|
||||||
|
// Test trackable resources (returns true)
|
||||||
|
assertTrue(RequestUriUtil.isTrackableResource("/login"), "Login page should be trackable");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource("/register"),
|
||||||
|
"Register page should be trackable");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource("/api/v1/users"),
|
||||||
|
"API users should be trackable");
|
||||||
|
assertTrue(RequestUriUtil.isTrackableResource("/"), "Root path should be trackable");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource("/some-other-path"),
|
||||||
|
"Other paths should be trackable");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIsTrackableResourceWithContextPath() {
|
||||||
|
String contextPath = "/myapp";
|
||||||
|
|
||||||
|
// Test with context path
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/js/script.js"),
|
||||||
|
"JS files should not be trackable with context path");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/login"),
|
||||||
|
"Login page should be trackable with context path");
|
||||||
|
|
||||||
|
// Additional tests with context path
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/fonts/custom.woff"),
|
||||||
|
"Font files should not be trackable with context path");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/images/header.png"),
|
||||||
|
"Images should not be trackable with context path");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/swagger/ui.html"),
|
||||||
|
"Swagger UI should not be trackable with context path");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/account/profile"),
|
||||||
|
"Account page should be trackable with context path");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource(contextPath, "/pdf/view"),
|
||||||
|
"PDF view page should be trackable with context path");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(
|
||||||
|
strings = {
|
||||||
|
"/js/util.js",
|
||||||
|
"/v1/api-docs/swagger.json",
|
||||||
|
"/robots.txt",
|
||||||
|
"/images/header/logo.png",
|
||||||
|
"/styles/theme.css",
|
||||||
|
"/build/app.js.map",
|
||||||
|
"/assets/icon.svg",
|
||||||
|
"/data/popularity.txt",
|
||||||
|
"/bundle.js",
|
||||||
|
"/api/swagger-ui.html",
|
||||||
|
"/api/v1/info/health",
|
||||||
|
"/site.webmanifest",
|
||||||
|
"/fonts/roboto.woff",
|
||||||
|
"/pdfjs/viewer.js"
|
||||||
|
})
|
||||||
|
void testNonTrackableResources(String path) {
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource(path),
|
||||||
|
"Resources matching patterns should not be trackable: " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(
|
||||||
|
strings = {
|
||||||
|
"/",
|
||||||
|
"/home",
|
||||||
|
"/login",
|
||||||
|
"/register",
|
||||||
|
"/pdf/merge",
|
||||||
|
"/pdf/split",
|
||||||
|
"/api/v1/users/1",
|
||||||
|
"/api/v1/documents/process",
|
||||||
|
"/settings",
|
||||||
|
"/account/profile",
|
||||||
|
"/dashboard",
|
||||||
|
"/help",
|
||||||
|
"/about"
|
||||||
|
})
|
||||||
|
void testTrackableResources(String path) {
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isTrackableResource(path),
|
||||||
|
"App routes should be trackable: " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEdgeCases() {
|
||||||
|
// Test with empty strings
|
||||||
|
assertFalse(RequestUriUtil.isStaticResource("", ""), "Empty path should not be static");
|
||||||
|
assertTrue(RequestUriUtil.isTrackableResource("", ""), "Empty path should be trackable");
|
||||||
|
|
||||||
|
// Test with null-like behavior (would actually throw NPE in real code)
|
||||||
|
// These are not actual null tests but shows handling of odd cases
|
||||||
|
assertFalse(RequestUriUtil.isStaticResource("null"), "String 'null' should not be static");
|
||||||
|
|
||||||
|
// Test String "null" as a path
|
||||||
|
boolean isTrackable = RequestUriUtil.isTrackableResource("null");
|
||||||
|
assertTrue(isTrackable, "String 'null' should be trackable");
|
||||||
|
|
||||||
|
// Mixed case extensions test - note that Java's endsWith() is case-sensitive
|
||||||
|
// We'll check actual behavior and document it rather than asserting
|
||||||
|
|
||||||
|
// Always test the lowercase versions which should definitely work
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/logo.png"), "PNG (lowercase) should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/icon.svg"), "SVG (lowercase) should be static");
|
||||||
|
|
||||||
|
// Path with query parameters
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isStaticResource("/api/users?page=1"),
|
||||||
|
"Path with query params should respect base path");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/images/logo.png?v=123"),
|
||||||
|
"Static resource with query params should still be static");
|
||||||
|
|
||||||
|
// Paths with fragments
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/css/styles.css#section1"),
|
||||||
|
"CSS with fragment should be static");
|
||||||
|
|
||||||
|
// Multiple dots in filename
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/js/jquery.min.js"),
|
||||||
|
"JS with multiple dots should be static");
|
||||||
|
|
||||||
|
// Special characters in path
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/images/user's-photo.png"),
|
||||||
|
"Path with special chars should be handled correctly");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testComplexPaths() {
|
||||||
|
// Test complex static resource paths
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/css/theme/dark/styles.css"),
|
||||||
|
"Nested CSS should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/fonts/open-sans/bold/font.woff"),
|
||||||
|
"Nested font should be static");
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource("/js/vendor/jquery/3.5.1/jquery.min.js"),
|
||||||
|
"Versioned JS should be static");
|
||||||
|
|
||||||
|
// Test complex paths with context
|
||||||
|
String contextPath = "/app";
|
||||||
|
assertTrue(
|
||||||
|
RequestUriUtil.isStaticResource(
|
||||||
|
contextPath, contextPath + "/css/theme/dark/styles.css"),
|
||||||
|
"Nested CSS with context should be static");
|
||||||
|
|
||||||
|
// Test boundary cases for isTrackableResource
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/js-framework/components"),
|
||||||
|
"Path starting with js- should not be treated as JS resource");
|
||||||
|
assertFalse(
|
||||||
|
RequestUriUtil.isTrackableResource("/fonts-selection"),
|
||||||
|
"Path starting with fonts- should not be treated as font resource");
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils;
|
package stirling.software.common.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
@ -11,8 +11,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination;
|
import stirling.software.common.model.api.misc.HighContrastColorCombination;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
|
|
||||||
class CustomColorReplaceStrategyTest {
|
class CustomColorReplaceStrategyTest {
|
||||||
|
|
@ -1,12 +1,10 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import stirling.software.common.model.api.misc.HighContrastColorCombination;
|
||||||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination;
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
class HighContrastColorReplaceDeciderTest {
|
class HighContrastColorReplaceDeciderTest {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
@ -26,8 +26,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
|
||||||
|
|
||||||
class InvertFullColorStrategyTest {
|
class InvertFullColorStrategyTest {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.misc;
|
package stirling.software.common.util.misc;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
@ -9,8 +9,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
|
||||||
|
|
||||||
class ReplaceAndInvertColorStrategyTest {
|
class ReplaceAndInvertColorStrategyTest {
|
||||||
|
|
@ -1,17 +1,14 @@
|
|||||||
package stirling.software.SPDF.utils.propertyeditor;
|
package stirling.software.common.util.propertyeditor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import stirling.software.common.model.api.security.RedactionArea;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.security.RedactionArea;
|
|
||||||
|
|
||||||
class StringToArrayListPropertyEditorTest {
|
class StringToArrayListPropertyEditorTest {
|
||||||
|
|
||||||
private StringToArrayListPropertyEditor editor;
|
private StringToArrayListPropertyEditor editor;
|
@ -1,4 +1,4 @@
|
|||||||
package stirling.software.SPDF.utils.propertyeditor;
|
package stirling.software.common.util.propertyeditor;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
@ -19,8 +19,8 @@ import com.posthog.java.shaded.org.json.JSONObject;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.GeneralUtils;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.util.GeneralUtil;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -765,7 +765,7 @@ public class KeygenLicenseVerifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String generateMachineFingerprint() {
|
private String generateMachineFingerprint() {
|
||||||
return GeneralUtils.generateMachineFingerprint();
|
return GeneralUtil.generateMachineFingerprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,8 +11,8 @@ import org.springframework.stereotype.Component;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
|
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
|
||||||
import stirling.software.SPDF.utils.GeneralUtils;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.util.GeneralUtil;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -88,7 +88,7 @@ public class LicenseKeyChecker {
|
|||||||
|
|
||||||
public void updateLicenseKey(String newKey) throws IOException {
|
public void updateLicenseKey(String newKey) throws IOException {
|
||||||
applicationProperties.getPremium().setKey(newKey);
|
applicationProperties.getPremium().setKey(newKey);
|
||||||
GeneralUtils.saveKeyToSettings("EnterpriseEdition.key", newKey);
|
GeneralUtil.saveKeyToSettings("EnterpriseEdition.key", newKey);
|
||||||
checkLicense();
|
checkLicense();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,11 @@ package stirling.software.SPDF.Factories;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.api.misc.HighContrastColorCombination;
|
import stirling.software.common.model.api.misc.HighContrastColorCombination;
|
||||||
import stirling.software.SPDF.model.api.misc.ReplaceAndInvert;
|
import stirling.software.common.model.api.misc.ReplaceAndInvert;
|
||||||
import stirling.software.SPDF.utils.misc.CustomColorReplaceStrategy;
|
import stirling.software.common.util.misc.CustomColorReplaceStrategy;
|
||||||
import stirling.software.SPDF.utils.misc.InvertFullColorStrategy;
|
import stirling.software.common.util.misc.InvertFullColorStrategy;
|
||||||
import stirling.software.SPDF.utils.misc.ReplaceAndInvertColorStrategy;
|
import stirling.software.common.util.misc.ReplaceAndInvertColorStrategy;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ReplaceAndInvertColorFactory {
|
public class ReplaceAndInvertColorFactory {
|
||||||
|
@ -27,10 +27,10 @@ import jakarta.annotation.PreDestroy;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.UI.WebBrowser;
|
import stirling.software.SPDF.UI.WebBrowser;
|
||||||
import stirling.software.SPDF.config.ConfigInitializer;
|
import stirling.software.common.configuration.ConfigInitializer;
|
||||||
import stirling.software.SPDF.utils.UrlUtils;
|
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
import stirling.software.common.configuration.InstallationPathConfig;
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.util.UrlUtils;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
|
@ -43,8 +43,8 @@ import me.friwi.jcefmaven.MavenCefAppHandlerAdapter;
|
|||||||
import me.friwi.jcefmaven.impl.progress.ConsoleProgressHandler;
|
import me.friwi.jcefmaven.impl.progress.ConsoleProgressHandler;
|
||||||
|
|
||||||
import stirling.software.SPDF.UI.WebBrowser;
|
import stirling.software.SPDF.UI.WebBrowser;
|
||||||
import stirling.software.SPDF.utils.UIScaling;
|
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
import stirling.software.common.configuration.InstallationPathConfig;
|
||||||
|
import stirling.software.common.util.UIScaling;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -15,7 +15,7 @@ import io.github.pixee.security.BoundedLineReader;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.UIScaling;
|
import stirling.software.common.util.UIScaling;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LoadingWindow extends JDialog {
|
public class LoadingWindow extends JDialog {
|
||||||
|
@ -12,6 +12,8 @@ import jakarta.annotation.PostConstruct;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import stirling.software.common.configuration.RuntimePathConfig;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ExternalAppDepConfig {
|
public class ExternalAppDepConfig {
|
||||||
|
@ -17,8 +17,8 @@ import jakarta.annotation.PostConstruct;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.GeneralUtils;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.util.GeneralUtil;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -39,31 +39,31 @@ public class InitialSetup {
|
|||||||
|
|
||||||
public void initUUIDKey() throws IOException {
|
public void initUUIDKey() throws IOException {
|
||||||
String uuid = applicationProperties.getAutomaticallyGenerated().getUUID();
|
String uuid = applicationProperties.getAutomaticallyGenerated().getUUID();
|
||||||
if (!GeneralUtils.isValidUUID(uuid)) {
|
if (!GeneralUtil.isValidUUID(uuid)) {
|
||||||
// Generating a random UUID as the secret key
|
// Generating a random UUID as the secret key
|
||||||
uuid = UUID.randomUUID().toString();
|
uuid = UUID.randomUUID().toString();
|
||||||
GeneralUtils.saveKeyToSettings("AutomaticallyGenerated.UUID", uuid);
|
GeneralUtil.saveKeyToSettings("AutomaticallyGenerated.UUID", uuid);
|
||||||
applicationProperties.getAutomaticallyGenerated().setUUID(uuid);
|
applicationProperties.getAutomaticallyGenerated().setUUID(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initSecretKey() throws IOException {
|
public void initSecretKey() throws IOException {
|
||||||
String secretKey = applicationProperties.getAutomaticallyGenerated().getKey();
|
String secretKey = applicationProperties.getAutomaticallyGenerated().getKey();
|
||||||
if (!GeneralUtils.isValidUUID(secretKey)) {
|
if (!GeneralUtil.isValidUUID(secretKey)) {
|
||||||
// Generating a random UUID as the secret key
|
// Generating a random UUID as the secret key
|
||||||
secretKey = UUID.randomUUID().toString();
|
secretKey = UUID.randomUUID().toString();
|
||||||
GeneralUtils.saveKeyToSettings("AutomaticallyGenerated.key", secretKey);
|
GeneralUtil.saveKeyToSettings("AutomaticallyGenerated.key", secretKey);
|
||||||
applicationProperties.getAutomaticallyGenerated().setKey(secretKey);
|
applicationProperties.getAutomaticallyGenerated().setKey(secretKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initEnableCSRFSecurity() throws IOException {
|
public void initEnableCSRFSecurity() throws IOException {
|
||||||
if (GeneralUtils.isVersionHigher(
|
if (GeneralUtil.isVersionHigher(
|
||||||
"0.36.0", applicationProperties.getAutomaticallyGenerated().getAppVersion())) {
|
"0.36.0", applicationProperties.getAutomaticallyGenerated().getAppVersion())) {
|
||||||
Boolean csrf = applicationProperties.getSecurity().getCsrfDisabled();
|
Boolean csrf = applicationProperties.getSecurity().getCsrfDisabled();
|
||||||
if (!csrf) {
|
if (!csrf) {
|
||||||
GeneralUtils.saveKeyToSettings("security.csrfDisabled", false);
|
GeneralUtil.saveKeyToSettings("security.csrfDisabled", false);
|
||||||
GeneralUtils.saveKeyToSettings("system.enableAnalytics", true);
|
GeneralUtil.saveKeyToSettings("system.enableAnalytics", true);
|
||||||
applicationProperties.getSecurity().setCsrfDisabled(false);
|
applicationProperties.getSecurity().setCsrfDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,14 +74,14 @@ public class InitialSetup {
|
|||||||
String termsUrl = applicationProperties.getLegal().getTermsAndConditions();
|
String termsUrl = applicationProperties.getLegal().getTermsAndConditions();
|
||||||
if (StringUtils.isEmpty(termsUrl)) {
|
if (StringUtils.isEmpty(termsUrl)) {
|
||||||
String defaultTermsUrl = "https://www.stirlingpdf.com/terms";
|
String defaultTermsUrl = "https://www.stirlingpdf.com/terms";
|
||||||
GeneralUtils.saveKeyToSettings("legal.termsAndConditions", defaultTermsUrl);
|
GeneralUtil.saveKeyToSettings("legal.termsAndConditions", defaultTermsUrl);
|
||||||
applicationProperties.getLegal().setTermsAndConditions(defaultTermsUrl);
|
applicationProperties.getLegal().setTermsAndConditions(defaultTermsUrl);
|
||||||
}
|
}
|
||||||
// Initialize Privacy Policy
|
// Initialize Privacy Policy
|
||||||
String privacyUrl = applicationProperties.getLegal().getPrivacyPolicy();
|
String privacyUrl = applicationProperties.getLegal().getPrivacyPolicy();
|
||||||
if (StringUtils.isEmpty(privacyUrl)) {
|
if (StringUtils.isEmpty(privacyUrl)) {
|
||||||
String defaultPrivacyUrl = "https://www.stirlingpdf.com/privacy-policy";
|
String defaultPrivacyUrl = "https://www.stirlingpdf.com/privacy-policy";
|
||||||
GeneralUtils.saveKeyToSettings("legal.privacyPolicy", defaultPrivacyUrl);
|
GeneralUtil.saveKeyToSettings("legal.privacyPolicy", defaultPrivacyUrl);
|
||||||
applicationProperties.getLegal().setPrivacyPolicy(defaultPrivacyUrl);
|
applicationProperties.getLegal().setPrivacyPolicy(defaultPrivacyUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ public class InitialSetup {
|
|||||||
appVersion = props.getProperty("version");
|
appVersion = props.getProperty("version");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
GeneralUtils.saveKeyToSettings("AutomaticallyGenerated.appVersion", appVersion);
|
GeneralUtil.saveKeyToSettings("AutomaticallyGenerated.appVersion", appVersion);
|
||||||
applicationProperties.getAutomaticallyGenerated().setAppVersion(appVersion);
|
applicationProperties.getAutomaticallyGenerated().setAppVersion(appVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import jakarta.servlet.http.HttpSession;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.RequestUriUtils;
|
import stirling.software.common.util.RequestUriUtil;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -30,7 +30,7 @@ public class MetricsFilter extends OncePerRequestFilter {
|
|||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
String uri = request.getRequestURI();
|
String uri = request.getRequestURI();
|
||||||
|
|
||||||
if (RequestUriUtils.isTrackableResource(request.getContextPath(), uri)) {
|
if (RequestUriUtil.isTrackableResource(request.getContextPath(), uri)) {
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
String sessionId = (session != null) ? session.getId() : "no-session";
|
String sessionId = (session != null) ? session.getId() : "no-session";
|
||||||
Counter counter =
|
Counter counter =
|
||||||
|
@ -3,7 +3,7 @@ package stirling.software.SPDF.config.interfaces;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.FileInfo;
|
import stirling.software.common.model.FileInfo;
|
||||||
import stirling.software.common.model.exception.UnsupportedProviderException;
|
import stirling.software.common.model.exception.UnsupportedProviderException;
|
||||||
|
|
||||||
public interface DatabaseInterface {
|
public interface DatabaseInterface {
|
||||||
|
@ -13,7 +13,7 @@ import jakarta.servlet.http.HttpSession;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.RequestUriUtils;
|
import stirling.software.common.util.RequestUriUtil;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CustomAuthenticationSuccessHandler
|
public class CustomAuthenticationSuccessHandler
|
||||||
@ -48,7 +48,7 @@ public class CustomAuthenticationSuccessHandler
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (savedRequest != null
|
if (savedRequest != null
|
||||||
&& !RequestUriUtils.isStaticResource(
|
&& !RequestUriUtil.isStaticResource(
|
||||||
request.getContextPath(), savedRequest.getRedirectUrl())) {
|
request.getContextPath(), savedRequest.getRedirectUrl())) {
|
||||||
// Redirect to the original destination
|
// Redirect to the original destination
|
||||||
super.onAuthenticationSuccess(request, response, authentication);
|
super.onAuthenticationSuccess(request, response, authentication);
|
||||||
|
@ -25,11 +25,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import stirling.software.SPDF.SPDFApplication;
|
import stirling.software.SPDF.SPDFApplication;
|
||||||
import stirling.software.SPDF.config.security.saml2.CertificateUtils;
|
import stirling.software.SPDF.config.security.saml2.CertificateUtils;
|
||||||
import stirling.software.SPDF.config.security.saml2.CustomSaml2AuthenticatedPrincipal;
|
import stirling.software.SPDF.config.security.saml2.CustomSaml2AuthenticatedPrincipal;
|
||||||
import stirling.software.SPDF.utils.UrlUtils;
|
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
import stirling.software.common.model.ApplicationProperties.Security.OAUTH2;
|
import stirling.software.common.model.ApplicationProperties.Security.OAUTH2;
|
||||||
import stirling.software.common.model.ApplicationProperties.Security.SAML2;
|
import stirling.software.common.model.ApplicationProperties.Security.SAML2;
|
||||||
import stirling.software.common.model.provider.KeycloakProvider;
|
import stirling.software.common.model.oauth2.KeycloakProvider;
|
||||||
|
import stirling.software.common.util.UrlUtils;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -20,7 +20,7 @@ import jakarta.servlet.http.HttpSession;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.User;
|
import stirling.software.SPDF.model.User;
|
||||||
import stirling.software.SPDF.utils.RequestUriUtils;
|
import stirling.software.common.util.RequestUriUtil;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@ -40,7 +40,7 @@ public class FirstLoginFilter extends OncePerRequestFilter {
|
|||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
String contextPath = request.getContextPath();
|
String contextPath = request.getContextPath();
|
||||||
// Check if the request is for static resources
|
// Check if the request is for static resources
|
||||||
boolean isStaticResource = RequestUriUtils.isStaticResource(contextPath, requestURI);
|
boolean isStaticResource = RequestUriUtil.isStaticResource(contextPath, requestURI);
|
||||||
// If it's a static resource, just continue the filter chain and skip the logic below
|
// If it's a static resource, just continue the filter chain and skip the logic below
|
||||||
if (isStaticResource) {
|
if (isStaticResource) {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
|
@ -9,7 +9,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import stirling.software.SPDF.utils.RequestUriUtils;
|
import stirling.software.common.util.RequestUriUtil;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class IPRateLimitingFilter implements Filter {
|
public class IPRateLimitingFilter implements Filter {
|
||||||
@ -29,7 +29,7 @@ public class IPRateLimitingFilter implements Filter {
|
|||||||
String requestURI = httpRequest.getRequestURI();
|
String requestURI = httpRequest.getRequestURI();
|
||||||
// Check if the request is for static resources
|
// Check if the request is for static resources
|
||||||
boolean isStaticResource =
|
boolean isStaticResource =
|
||||||
RequestUriUtils.isStaticResource(httpRequest.getContextPath(), requestURI);
|
RequestUriUtil.isStaticResource(httpRequest.getContextPath(), requestURI);
|
||||||
|
|
||||||
// If it's a static resource, just continue the filter chain and skip the logic below
|
// If it's a static resource, just continue the filter chain and skip the logic below
|
||||||
if (isStaticResource) {
|
if (isStaticResource) {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package stirling.software.common.configuration;
|
package stirling.software.SPDF.config.security.database;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import stirling.software.common.configuration.InstallationPathConfig;
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
import stirling.software.common.model.exception.UnsupportedProviderException;
|
import stirling.software.common.model.exception.UnsupportedProviderException;
|
||||||
|
|
@ -29,9 +29,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
import stirling.software.SPDF.config.interfaces.DatabaseInterface;
|
import stirling.software.SPDF.config.interfaces.DatabaseInterface;
|
||||||
import stirling.software.SPDF.model.exception.BackupNotFoundException;
|
import stirling.software.SPDF.model.exception.BackupNotFoundException;
|
||||||
import stirling.software.SPDF.utils.FileInfo;
|
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
import stirling.software.common.configuration.InstallationPathConfig;
|
||||||
import stirling.software.common.model.ApplicationProperties;
|
import stirling.software.common.model.ApplicationProperties;
|
||||||
|
import stirling.software.common.model.FileInfo;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user