Merge branch 'main' of git@github.com:Stirling-Tools/Stirling-PDF.git

into main
This commit is contained in:
Anthony Stirling
2024-10-01 13:43:08 +01:00
parent 20dc2f60cd
commit 5832147b30
41 changed files with 1129 additions and 202 deletions

View File

@@ -1,18 +1,22 @@
package stirling.software.SPDF.EE;
import java.io.IOException;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.utils.GeneralUtils;
@Component
public class LicenseKeyChecker implements CommandLineRunner {
public class LicenseKeyChecker {
private final KeygenLicenseVerifier licenseService;
private final ApplicationProperties applicationProperties;
private static boolean enterpriseEnbaledResult = false;
// Inject your license service or configuration
public LicenseKeyChecker(
KeygenLicenseVerifier licenseService, ApplicationProperties applicationProperties) {
@@ -20,39 +24,28 @@ public class LicenseKeyChecker implements CommandLineRunner {
this.applicationProperties = new ApplicationProperties();
}
// Validate on startup
@Override
public void run(String... args) throws Exception {
checkLicense();
}
// Periodic license check - runs every 7 days
@Scheduled(fixedRate = 604800000) // 7 days in milliseconds
public void checkLicensePeriodically() {
checkLicense();
}
// License validation logic
private void checkLicense() {
boolean isValid =
licenseService.verifyLicense(applicationProperties.getEnterpriseEdition().getKey());
if (!isValid) {
// Handle invalid license (shut down the app, log, etc.)
System.out.println("License key is invalid!");
// Optionally stop the application
// System.exit(1); // Uncomment if you want to stop the app
} else {
System.out.println("License key is valid.");
}
if(!applicationProperties.getEnterpriseEdition().isEnabled()) {
enterpriseEnbaledResult = false;
} else {
enterpriseEnbaledResult = licenseService.verifyLicense(applicationProperties.getEnterpriseEdition().getKey());
}
}
// Method to update the license key dynamically
public void updateLicenseKey(String newKey) {
// Update the key in ApplicationProperties
public void updateLicenseKey(String newKey) throws IOException {
applicationProperties.getEnterpriseEdition().setKey(newKey);
// Immediately validate the new key
System.out.println("License key has been updated. Checking new key...");
GeneralUtils.saveKeyToConfig("EnterpriseEdition.key", newKey, false);
checkLicense();
}
public boolean getEnterpriseEnabledResult() {
return enterpriseEnbaledResult;
}
}