mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2024-10-04 10:10:13 +02:00
Merge branch 'main' into features/335_helm_chart
This commit is contained in:
commit
bc4640c3f0
@ -222,7 +222,7 @@ metrics:
|
|||||||
- customStaticFilePath. Customise static files such as the app logo by placing files in the /customFiles/static/ directory. An example of customising app logo is placing a /customFiles/static/favicon.svg to override current SVG. This can be used to change any images/icons/css/fonts/js etc in Stirling-PDF
|
- customStaticFilePath. Customise static files such as the app logo by placing files in the /customFiles/static/ directory. An example of customising app logo is placing a /customFiles/static/favicon.svg to override current SVG. This can be used to change any images/icons/css/fonts/js etc in Stirling-PDF
|
||||||
|
|
||||||
### Environment only parameters
|
### Environment only parameters
|
||||||
- ``SYSTEM_ROOTURIPATH`` ie set to ``pdf-app`` to Set the application's root URI tp ``localhost:8080/pdf-app``
|
- ``SYSTEM_ROOTURIPATH`` ie set to ``/pdf-app`` to Set the application's root URI to ``localhost:8080/pdf-app``
|
||||||
- ``SYSTEM_CONNECTIONTIMEOUTMINUTES`` to set custom connection timeout values
|
- ``SYSTEM_CONNECTIONTIMEOUTMINUTES`` to set custom connection timeout values
|
||||||
- ``DOCKER_ENABLE_SECURITY`` to tell docker to download security jar (required as true for auth login)
|
- ``DOCKER_ENABLE_SECURITY`` to tell docker to download security jar (required as true for auth login)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'stirling.software'
|
group = 'stirling.software'
|
||||||
version = '0.14.2'
|
version = '0.14.3'
|
||||||
sourceCompatibility = '17'
|
sourceCompatibility = '17'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -12,6 +12,8 @@ import java.nio.file.Paths;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
import org.springframework.context.ApplicationContextInitializer;
|
||||||
@ -49,7 +51,8 @@ public class ConfigInitializer implements ApplicationContextInitializer<Configur
|
|||||||
// If user file exists, we need to merge it with the template from the classpath
|
// If user file exists, we need to merge it with the template from the classpath
|
||||||
List<String> templateLines;
|
List<String> templateLines;
|
||||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
try (InputStream in = getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
||||||
templateLines = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.toList());
|
templateLines = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines()
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeYamlFiles(templateLines, destPath, destPath);
|
mergeYamlFiles(templateLines, destPath, destPath);
|
||||||
@ -58,44 +61,69 @@ public class ConfigInitializer implements ApplicationContextInitializer<Configur
|
|||||||
|
|
||||||
public void mergeYamlFiles(List<String> templateLines, Path userFilePath, Path outputPath) throws IOException {
|
public void mergeYamlFiles(List<String> templateLines, Path userFilePath, Path outputPath) throws IOException {
|
||||||
List<String> userLines = Files.readAllLines(userFilePath);
|
List<String> userLines = Files.readAllLines(userFilePath);
|
||||||
|
|
||||||
List<String> mergedLines = new ArrayList<>();
|
List<String> mergedLines = new ArrayList<>();
|
||||||
boolean insideAutoGenerated = false;
|
boolean insideAutoGenerated = false;
|
||||||
|
boolean beforeFirstKey = true;
|
||||||
|
|
||||||
|
Function<String, Boolean> isCommented = line -> line.trim().startsWith("#");
|
||||||
|
Function<String, String> extractKey = line -> {
|
||||||
|
String[] parts = line.split(":");
|
||||||
|
return parts.length > 0 ? parts[0].trim().replace("#", "").trim() : "";
|
||||||
|
};
|
||||||
|
|
||||||
|
Set<String> userKeys = userLines.stream().map(extractKey).collect(Collectors.toSet());
|
||||||
|
|
||||||
for (String line : templateLines) {
|
for (String line : templateLines) {
|
||||||
// Check if we've entered or left the AutomaticallyGenerated section
|
String key = extractKey.apply(line);
|
||||||
|
|
||||||
if (line.trim().equalsIgnoreCase("AutomaticallyGenerated:")) {
|
if (line.trim().equalsIgnoreCase("AutomaticallyGenerated:")) {
|
||||||
insideAutoGenerated = true;
|
insideAutoGenerated = true;
|
||||||
mergedLines.add(line);
|
mergedLines.add(line);
|
||||||
continue;
|
continue;
|
||||||
} else if (insideAutoGenerated && line.trim().isEmpty()) {
|
} else if (insideAutoGenerated && line.trim().isEmpty()) {
|
||||||
// We have reached the end of the AutomaticallyGenerated section
|
|
||||||
insideAutoGenerated = false;
|
insideAutoGenerated = false;
|
||||||
mergedLines.add(line);
|
mergedLines.add(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insideAutoGenerated) {
|
if (beforeFirstKey && (isCommented.apply(line) || line.trim().isEmpty())) {
|
||||||
// Add lines from user's settings if we are inside AutomaticallyGenerated
|
// Handle top comments and empty lines before the first key.
|
||||||
Optional<String> userAutoGenValue = userLines.stream().filter(l -> l.trim().startsWith(line.split(":")[0].trim())).findFirst();
|
mergedLines.add(line);
|
||||||
if (userAutoGenValue.isPresent()) {
|
|
||||||
mergedLines.add(userAutoGenValue.get());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Outside of AutomaticallyGenerated, continue as before
|
if (!key.isEmpty())
|
||||||
if (line.contains(": ")) {
|
beforeFirstKey = false;
|
||||||
String key = line.split(": ")[0].trim();
|
|
||||||
Optional<String> userValue = userLines.stream().filter(l -> l.trim().startsWith(key)).findFirst();
|
if (userKeys.contains(key)) {
|
||||||
if (userValue.isPresent()) {
|
// If user has any version (commented or uncommented) of this key, skip the
|
||||||
|
// template line
|
||||||
|
Optional<String> userValue = userLines.stream()
|
||||||
|
.filter(l -> extractKey.apply(l).equalsIgnoreCase(key) && !isCommented.apply(l)).findFirst();
|
||||||
|
if (userValue.isPresent())
|
||||||
mergedLines.add(userValue.get());
|
mergedLines.add(userValue.get());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isCommented.apply(line) || line.trim().isEmpty() || !userKeys.contains(key)) {
|
||||||
|
mergedLines.add(line); // If line is commented, empty or key not present in user's file, retain the
|
||||||
|
// template line
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
mergedLines.add(line);
|
}
|
||||||
|
|
||||||
|
// Add any additional uncommented user lines that are not present in the
|
||||||
|
// template
|
||||||
|
for (String userLine : userLines) {
|
||||||
|
String userKey = extractKey.apply(userLine);
|
||||||
|
boolean isPresentInTemplate = templateLines.stream().map(extractKey)
|
||||||
|
.anyMatch(templateKey -> templateKey.equalsIgnoreCase(userKey));
|
||||||
|
if (!isPresentInTemplate && !isCommented.apply(userLine)) {
|
||||||
|
mergedLines.add(userLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Files.write(outputPath, mergedLines, StandardCharsets.UTF_8);
|
Files.write(outputPath, mergedLines, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ import java.security.cert.CertificateFactory;
|
|||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -130,6 +131,7 @@ public class CertSignController {
|
|||||||
signature.setName(name);
|
signature.setName(name);
|
||||||
signature.setLocation(location);
|
signature.setLocation(location);
|
||||||
signature.setReason(reason);
|
signature.setReason(reason);
|
||||||
|
signature.setSignDate(Calendar.getInstance());
|
||||||
|
|
||||||
// Load the PDF
|
// Load the PDF
|
||||||
try (PDDocument document = PDDocument.load(pdf.getBytes())) {
|
try (PDDocument document = PDDocument.load(pdf.getBytes())) {
|
||||||
|
Loading…
Reference in New Issue
Block a user