2024-09-20 13:31:55 +01:00
|
|
|
package stirling.software.SPDF.EE;
|
|
|
|
|
|
2024-10-01 13:43:08 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
2024-09-20 13:31:55 +01:00
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
2024-10-01 13:43:08 +01:00
|
|
|
import stirling.software.SPDF.utils.GeneralUtils;
|
2024-09-20 13:31:55 +01:00
|
|
|
|
|
|
|
|
@Component
|
2024-10-01 13:43:08 +01:00
|
|
|
public class LicenseKeyChecker {
|
2024-09-20 13:31:55 +01:00
|
|
|
|
|
|
|
|
private final KeygenLicenseVerifier licenseService;
|
|
|
|
|
|
|
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
|
|
2024-10-01 13:43:08 +01:00
|
|
|
private static boolean enterpriseEnbaledResult = false;
|
2024-09-20 13:31:55 +01:00
|
|
|
// Inject your license service or configuration
|
|
|
|
|
public LicenseKeyChecker(
|
|
|
|
|
KeygenLicenseVerifier licenseService, ApplicationProperties applicationProperties) {
|
|
|
|
|
this.licenseService = licenseService;
|
|
|
|
|
this.applicationProperties = new ApplicationProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(fixedRate = 604800000) // 7 days in milliseconds
|
|
|
|
|
public void checkLicensePeriodically() {
|
|
|
|
|
checkLicense();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkLicense() {
|
2024-10-01 13:43:08 +01:00
|
|
|
if(!applicationProperties.getEnterpriseEdition().isEnabled()) {
|
|
|
|
|
enterpriseEnbaledResult = false;
|
|
|
|
|
} else {
|
|
|
|
|
enterpriseEnbaledResult = licenseService.verifyLicense(applicationProperties.getEnterpriseEdition().getKey());
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 13:31:55 +01:00
|
|
|
}
|
|
|
|
|
|
2024-10-01 13:43:08 +01:00
|
|
|
public void updateLicenseKey(String newKey) throws IOException {
|
2024-09-20 13:31:55 +01:00
|
|
|
applicationProperties.getEnterpriseEdition().setKey(newKey);
|
2024-10-01 13:43:08 +01:00
|
|
|
GeneralUtils.saveKeyToConfig("EnterpriseEdition.key", newKey, false);
|
2024-09-20 13:31:55 +01:00
|
|
|
checkLicense();
|
|
|
|
|
}
|
2024-10-01 13:43:08 +01:00
|
|
|
|
|
|
|
|
public boolean getEnterpriseEnabledResult() {
|
|
|
|
|
return enterpriseEnbaledResult;
|
|
|
|
|
}
|
2024-09-20 13:31:55 +01:00
|
|
|
}
|